8334488: Improve error for illegal early access from nested class
Reviewed-by: mcimadamore
This commit is contained in:
parent
07ebda54f2
commit
7b3a96d570
@ -950,7 +950,6 @@ public class Attr extends JCTree.Visitor {
|
|||||||
Optional.ofNullable(env.info.attributionMode.isSpeculative ?
|
Optional.ofNullable(env.info.attributionMode.isSpeculative ?
|
||||||
argumentAttr.withLocalCacheContext() : null);
|
argumentAttr.withLocalCacheContext() : null);
|
||||||
boolean ctorProloguePrev = env.info.ctorPrologue;
|
boolean ctorProloguePrev = env.info.ctorPrologue;
|
||||||
env.info.ctorPrologue = false;
|
|
||||||
try {
|
try {
|
||||||
// Local and anonymous classes have not been entered yet, so we need to
|
// Local and anonymous classes have not been entered yet, so we need to
|
||||||
// do it now.
|
// do it now.
|
||||||
@ -995,7 +994,7 @@ public class Attr extends JCTree.Visitor {
|
|||||||
Lint lint = env.info.lint.augment(m);
|
Lint lint = env.info.lint.augment(m);
|
||||||
Lint prevLint = chk.setLint(lint);
|
Lint prevLint = chk.setLint(lint);
|
||||||
boolean ctorProloguePrev = env.info.ctorPrologue;
|
boolean ctorProloguePrev = env.info.ctorPrologue;
|
||||||
env.info.ctorPrologue = false;
|
Assert.check(!env.info.ctorPrologue);
|
||||||
MethodSymbol prevMethod = chk.setMethod(m);
|
MethodSymbol prevMethod = chk.setMethod(m);
|
||||||
try {
|
try {
|
||||||
deferredLintHandler.flush(tree.pos(), lint);
|
deferredLintHandler.flush(tree.pos(), lint);
|
||||||
|
@ -209,6 +209,7 @@ public class Enter extends JCTree.Visitor {
|
|||||||
localEnv.info.lint = null; // leave this to be filled in by Attr,
|
localEnv.info.lint = null; // leave this to be filled in by Attr,
|
||||||
// when annotations have been processed
|
// when annotations have been processed
|
||||||
localEnv.info.isAnonymousDiamond = TreeInfo.isDiamond(env.tree);
|
localEnv.info.isAnonymousDiamond = TreeInfo.isDiamond(env.tree);
|
||||||
|
localEnv.info.ctorPrologue = false;
|
||||||
return localEnv;
|
return localEnv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
AnonymousInSuperCallNegTest.java:23:49: compiler.err.no.encl.instance.of.type.in.scope: AnonymousInSuperCallNegTest.JavacBug
|
AnonymousInSuperCallNegTest.java:23:49: compiler.err.cant.ref.before.ctor.called: x
|
||||||
1 error
|
1 error
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
LocalClassCtorPrologue.java:16:17: compiler.err.no.encl.instance.of.type.in.scope: LocalClassCtorPrologue
|
LocalClassCtorPrologue.java:16:17: compiler.err.cant.ref.before.ctor.called: x
|
||||||
- compiler.note.preview.filename: LocalClassCtorPrologue.java, DEFAULT
|
- compiler.note.preview.filename: LocalClassCtorPrologue.java, DEFAULT
|
||||||
- compiler.note.preview.recompile
|
- compiler.note.preview.recompile
|
||||||
1 error
|
1 error
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* @test /nodynamiccopyright/
|
||||||
|
* @bug 8334488
|
||||||
|
* @summary Verify the error message generated for early access from inner class
|
||||||
|
* @compile/fail/ref=EarlyInnerAccessErrorMessageTest.out -XDrawDiagnostics EarlyInnerAccessErrorMessageTest.java
|
||||||
|
* @enablePreview
|
||||||
|
*/
|
||||||
|
public class EarlyInnerAccessErrorMessageTest {
|
||||||
|
int x;
|
||||||
|
EarlyInnerAccessErrorMessageTest() {
|
||||||
|
class Inner {
|
||||||
|
{ System.out.println(x); }
|
||||||
|
}
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
EarlyInnerAccessErrorMessageTest.java:12:34: compiler.err.cant.ref.before.ctor.called: x
|
||||||
|
- compiler.note.preview.filename: EarlyInnerAccessErrorMessageTest.java, DEFAULT
|
||||||
|
- compiler.note.preview.recompile
|
||||||
|
1 error
|
@ -1,4 +1,4 @@
|
|||||||
EarlyLocalClass.java:12:32: compiler.err.no.encl.instance.of.type.in.scope: EarlyLocalClass
|
EarlyLocalClass.java:12:32: compiler.err.cant.ref.before.ctor.called: this
|
||||||
- compiler.note.preview.filename: EarlyLocalClass.java, DEFAULT
|
- compiler.note.preview.filename: EarlyLocalClass.java, DEFAULT
|
||||||
- compiler.note.preview.recompile
|
- compiler.note.preview.recompile
|
||||||
1 error
|
1 error
|
||||||
|
Loading…
x
Reference in New Issue
Block a user