IDEA-386630 Java Highlighting: Check bounds of type parameters of constructors like methods#3453
IDEA-386630 Java Highlighting: Check bounds of type parameters of constructors like methods#3453O7410 wants to merge 2 commits intoJetBrains:masterfrom
Conversation
|
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> {}
} |
|
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();
}
} |
|
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? |
|
The compiler only complains about the type arguments, so that's what I'll do |
|
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 |
…rent, now checks inferred type arguments too
|
Made a few changes and updated the test, let me know if I missed anything |
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
PsiNewExpressionand the type arguments be not applicable, and have a problem that would be caught bycheckReferenceTypeArgumentList?I'm also not sure if the
elseon line 1313 should remain there.It might make more sense to first
checkReferenceTypeArgumentListand if that didn't have any errors, thencheckIncompatibleCall?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