Skip to content

IDEA-386630 Java Highlighting: Check bounds of type parameters of constructors like methods#3453

Open
O7410 wants to merge 2 commits intoJetBrains:masterfrom
O7410:IDEA-386630
Open

IDEA-386630 Java Highlighting: Check bounds of type parameters of constructors like methods#3453
O7410 wants to merge 2 commits intoJetBrains:masterfrom
O7410:IDEA-386630

Conversation

@O7410
Copy link
Contributor

@O7410 O7410 commented Mar 9, 2026

There might be edge cases, where because of the additional condition, no error is raised at all, that is to say: Can the constructor call be something other than PsiNewExpression and the type arguments be not applicable, and have a problem that would be caught by checkReferenceTypeArgumentList?
I'm also not sure if the else on line 1313 should remain there.
It might make more sense to first checkReferenceTypeArgumentList and if that didn't have any errors, then checkIncompatibleCall?
I tested this and read the code of the methods as much as I could, but I'm not sure
I would like for this to be fixed before 2026.1

@BartvHelvert BartvHelvert added the Java Pull requests that update Java plugin code label Mar 13, 2026
@O7410
Copy link
Contributor Author

O7410 commented Mar 13, 2026

I'm currently looking into it again, looks like with the current changes there are still some differences, specifically when the argument counts are different. Notably, I found a case where my changes cause IntelliJ to not highlight an error when there is an error and it previously did highlight it.

import java.util.function.Function;

class Test {
    public static void main(String[] args) {
        main(new Builder<>());
    }

    public static void main(Builder<Beta> gammaBuilder) {

        new Test(Test::c, name -> gammaBuilder); // compiler error on this line
//        Test.method(Test::c, name -> gammaBuilder);
        Test.<Beta, Builder<Beta>>method(Test::c, name -> gammaBuilder);
        new <Beta, Builder<Beta>> Test(Test::c, name -> gammaBuilder);
    }


    private static <T extends Alfa, B extends Builder<T>> void method(final Function<B, String> f1,
                                                        final Function<String, B> f2) {
    }

    private <T extends Alfa, B extends Builder<T>> Test(final Function<B, String> f1,
                                                        final Function<String, B> f2) {

    }

    private static String c(final Builder<? extends Beta> builder) {
        return "";
    }

    static class Alfa {}
    private static class Beta extends Alfa {}

    static class Builder<T> {}
}

@O7410
Copy link
Contributor Author

O7410 commented Mar 13, 2026

Here is another case where the constructor and the method call are different:

public class C {
    private <T extends String> C(T t) {
    }

    private static <T extends String> void method(T t) {
    }

    static {
        C.<String, Number>method();
        new <String, Number>C();
    }
}

@O7410
Copy link
Contributor Author

O7410 commented Mar 13, 2026

In the last case, both with my changes and in 2025.3.3, the method call highlights just the type parameters and the constructor call highlights just the missing argument. Should both of the calls highlight both the type parameters and the missing argument?

@O7410
Copy link
Contributor Author

O7410 commented Mar 13, 2026

The compiler only complains about the type arguments, so that's what I'll do

@O7410
Copy link
Contributor Author

O7410 commented Mar 14, 2026

I found this too

public class TestClass {
    public static void main(String[] args) {
        // spaces for clarity
        C. < String , Number > method ();
        new < String , Number > C ();
    }
}
public class C {
    private <T extends String> C() {
    }

    private static <T extends String> void method() {
    }
}

In 2025.3.3, on the method, IntelliJ highlights both the type parameters and the method because of the access modifier, but only the C for the constructor

…rent, now checks inferred type arguments too
@O7410
Copy link
Contributor Author

O7410 commented Mar 14, 2026

Made a few changes and updated the test, let me know if I missed anything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Java Pull requests that update Java plugin code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants