ECJ fails to complain about static member being selected from a parameterized class#4837
Conversation
srikanth-sankaran
commented
Feb 13, 2026
- Fixes ecj ignores error "cannot select a static class from a parameterized type" #4702
|
@stephan-herrmann - Can you please review this for 4.39 RC1 ? TIA I have organized it as two commits, the first one is merely a rename refactoring. |
|
Pondering about this issue teleported me back into https://bugs.eclipse.org/bugs/show_bug.cgi?id=460491 - refreshing memory of that old story took a bit longer than expected ... I'll complete my review tomorrow. |
Thanks. Fix is two fold:
|
This part looks good. I see this area as dual to https://bugs.eclipse.org/460491 : while the old bug ensured that implicit references to static members of parameterized types do not resolve as parameterized (since no type variables are in scope), this current fix makes sure you cannot explicitly request such an illegal type via a PQTR. ✔️ |
stephan-herrmann
left a comment
There was a problem hiding this comment.
After doubts regarding testIssue4702_1() I was about to suggest to only merge the changes in PQTR, but then I tried this:
public class Demo<E> {
class Outer {
static class StaticNested<X> {}
}
void qualifiedNew() {
new Outer.StaticNested<String>();
}
}accepted in 4.38, rejected with the change under review:
----------
1. ERROR in /tmp/Demo.java (at line 6)
new Outer.StaticNested<String>();
^^^^^^^^^^^^^^^^^^
The member type Demo.Outer.StaticNested<X> cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type Demo<E>.Outer
----------
1 problem (1 error)
Again, how to you remove an absent <E>?
I do like the move to make code blocks look more similar between PQTR and QTR. If we'd invert the enclosing if in PQTR to align as if (qualifyingType == null) then we'd see even more clearly, that then-blocks are still different between both types. Is that difference intended? How motivated?
| "1. ERROR in OuterStaticNestedDemo.java (at line 7)\n" + | ||
| " new Outer.StaticNested();\n" + | ||
| " ^^^^^^^^^^^^^^^^^^\n" + | ||
| "The member type OuterStaticNestedDemo.Outer.StaticNested cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type OuterStaticNestedDemo<E>.Outer\n" + |
There was a problem hiding this comment.
Here I don't understand what's going on. The programmer did not specify any type arguments, yet the compiler requires arguments to be removed? How could that code be corrected?
I realize that javac raises a similar error, but if there is any chance that this code is legal per JLS then rejecting this now sounds like a change too disruptive for RC1.
@srikanth-sankaran have you checked this against JLS?
There was a problem hiding this comment.
For the general discussion I moved back to the issue, see
- ecj ignores error "cannot select a static class from a parameterized type" #4702 (comment)
- ecj ignores error "cannot select a static class from a parameterized type" #4702 (comment)
:)
There was a problem hiding this comment.
The programmer did not specify any type arguments, yet the compiler requires arguments to be removed? How could that code be corrected?
I realize that javac raises a similar error
By saying new OuterStaticNestedDemo.Outer.StaticNested(); ?
Javac as well as the patched ECJ accept this.
|
To address the questions raised during review I'll defer to this to 4.40 M1. Since this is not a case of valid code being rejected but of invalid code not being rejected it need not be rushed. |
34796d1 to
79f6973
Compare
By saying |
Given it is RC1, I tried to minimize the delta - so didn't look into it ... |