Skip to content
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

[23] ECJ rejects local instantiation in early construction context #3165

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ public void manageEnclosingInstanceAccessIfNecessary(BlockScope currentScope, Fl
Scope outerScope = currentScope.parent;
if (!methodScope.isConstructorCall) {
nestedType.addSyntheticArgumentAndField(nestedType.enclosingType());
outerScope = outerScope.enclosingClassScope();
outerScope = outerScope.enclosingInstanceScope();
earlySeen = methodScope.isInsideEarlyConstructionContext(nestedType.enclosingType(), false);
}
if (JavaFeature.FLEXIBLE_CONSTRUCTOR_BODIES.isSupported(currentScope.compilerOptions())) {
Expand All @@ -1087,6 +1087,8 @@ public void manageEnclosingInstanceAccessIfNecessary(BlockScope currentScope, Fl
earlySeen = cs.insideEarlyConstructionContext;
}
outerScope = outerScope.parent;
if (outerScope instanceof MethodScope ms && ms.isStatic)
break;
}
}
}
Expand Down Expand Up @@ -1124,6 +1126,7 @@ public void manageEnclosingInstanceAccessIfNecessary(BlockScope currentScope, Fl
}
}


/**
* Access emulation for a local member type
* force to emulation of access to direct enclosing instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,18 @@ public final ClassScope enclosingClassScope() {
return null; // may answer null if no type around
}

public ClassScope enclosingInstanceScope() {
Scope scope = this;
while (true) {
scope = scope.parent;
if (scope == null || scope instanceof MethodScope ms && ms.isStatic) {
return null;
} else if (scope instanceof ClassScope cs) {
return cs;
}
}
}

public final ClassScope enclosingTopMostClassScope() {
Scope scope = this;
while (scope != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2330,4 +2330,25 @@ public static void main(String... args) {
};
runner.runConformTest();
}

public void testGH3153() {
runConformTest(new String[] {
"X.java",
"""
public class X {
public static void main(String[] argv) {
class Inner {
Inner() {
class Local {}
new Local() {}; // Error: No enclosing instance of the type X is accessible in scope
super();
}
}
new Inner();
}
}
""" },
"");
}

}
Loading