-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[24] Local instantiation in static context allowed by ECJ #3687
Comments
Here's another related testcase where we are rejecting but Javac is accepting:
|
Thanks, @jarthana I'll go back to studying the papers 😄 |
Regarding the first example I see two violations, actually: Allocation
|
While fixing this I get into a conflict with tests like org.eclipse.jdt.core.tests.compiler.regression.LocalEnumTest.test077(): public class X {
public static void main(String[] args) {
enum E {
A {
void bar() {
new M();
}
};
abstract void bar();
class M {
M() {
System.out.println("SUCCESS");
}
}
}
E.A.bar();
}
} Hitherto a conforming test, we now start to report
javac >= 16 complains similarly ("no enclosing instance"). (before 16 enums were not allowed to be local). I think the error is correct, because the body of A is an implicit anonymous class inside the initializer of the implicit static field A. So we are in a static context indeed, where the member class M cannot be instantiated without qualification. |
+ allocation must compare "nearest enclosing static scope + search for enclosing static should not go beyond the target enclosing + LocalEnumTest: corrected some expected outcomes + extracted subset from one test for specific comparison with javac Fixes eclipse-jdt#3687
+ allocation must compare "nearest enclosing static scope" + search for enclosing static should not go beyond the target enclosing + LocalEnumTest: corrected some expected outcomes + extracted subset from one test for specific comparison with javac Fixes #3687
Fixed by #3699 |
The following code that contains an instantiation of a local in a static context is allowed by the compiler. This was allowed by earlier JDK24s, but as of ea34, is rejected).
@stephan-herrmann I haven't yet looked at the spec, but it appears that we should be rejecting this code?
I also did some investigation and found this code to be involved (AllocationExpression, line 371:
MethodScope enclosingMethodScope = local.scope.enclosingMethodScope();
First of all, I don't think I understand the !enclosingMethodScope.isStatic in the check in line 372. The second part I don't understand is why we are ignoring the scope of the AllocationExpression itself.
The text was updated successfully, but these errors were encountered: