Skip to content

Comments

ECJ fails to complain about static member being selected from a parameterized class#4837

Open
srikanth-sankaran wants to merge 2 commits intoeclipse-jdt:masterfrom
srikanth-sankaran:static-accessed-with-parameterized
Open

ECJ fails to complain about static member being selected from a parameterized class#4837
srikanth-sankaran wants to merge 2 commits intoeclipse-jdt:masterfrom
srikanth-sankaran:static-accessed-with-parameterized

Conversation

@srikanth-sankaran
Copy link
Contributor

@srikanth-sankaran
Copy link
Contributor Author

@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.

@stephan-herrmann
Copy link
Contributor

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.

@srikanth-sankaran
Copy link
Contributor Author

I'll complete my review tomorrow.

Thanks.

Fix is two fold:

  • To be a parameterized type, a type in and off itself need not have type arguments, if its enclosing instance is parameterized it becomes parameterized.
  • Additionally, in QTR we fail to recognize a qualifying class as being a parameterized type under similar circumstances.

@stephan-herrmann
Copy link
Contributor

To be a parameterized type, a type in and off itself need not have type arguments, if its enclosing instance is parameterized it becomes parameterized.

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. ✔️

Copy link
Contributor

@stephan-herrmann stephan-herrmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment on lines +2083 to +2086
"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" +
Copy link
Contributor

@stephan-herrmann stephan-herrmann Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@srikanth-sankaran
Copy link
Contributor Author

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.

@srikanth-sankaran srikanth-sankaran force-pushed the static-accessed-with-parameterized branch from 34796d1 to 79f6973 Compare February 19, 2026 04:48
@srikanth-sankaran
Copy link
Contributor Author

Again, how to you remove an absent <E>?

By saying new Demo.Outer.StaticNested<String>(); ??

@srikanth-sankaran
Copy link
Contributor Author

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?

Given it is RC1, I tried to minimize the delta - so didn't look into it ...

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ecj ignores error "cannot select a static class from a parameterized type"

2 participants