diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java index 533541bd108..08c37fc5aa4 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java @@ -950,7 +950,6 @@ public class Attr extends JCTree.Visitor { Optional.ofNullable(env.info.attributionMode.isSpeculative ? argumentAttr.withLocalCacheContext() : null); boolean ctorProloguePrev = env.info.ctorPrologue; - env.info.ctorPrologue = false; try { // Local and anonymous classes have not been entered yet, so we need to // do it now. @@ -995,7 +994,7 @@ public class Attr extends JCTree.Visitor { Lint lint = env.info.lint.augment(m); Lint prevLint = chk.setLint(lint); boolean ctorProloguePrev = env.info.ctorPrologue; - env.info.ctorPrologue = false; + Assert.check(!env.info.ctorPrologue); MethodSymbol prevMethod = chk.setMethod(m); try { deferredLintHandler.flush(tree.pos(), lint); diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java index 7478ef1c907..926be3b6e26 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java @@ -209,6 +209,7 @@ public class Enter extends JCTree.Visitor { localEnv.info.lint = null; // leave this to be filled in by Attr, // when annotations have been processed localEnv.info.isAnonymousDiamond = TreeInfo.isDiamond(env.tree); + localEnv.info.ctorPrologue = false; return localEnv; } diff --git a/test/langtools/tools/javac/AnonymousClass/AnonymousInSuperCallNegTest.out b/test/langtools/tools/javac/AnonymousClass/AnonymousInSuperCallNegTest.out index 140521689a0..c04b45bce1e 100644 --- a/test/langtools/tools/javac/AnonymousClass/AnonymousInSuperCallNegTest.out +++ b/test/langtools/tools/javac/AnonymousClass/AnonymousInSuperCallNegTest.out @@ -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 diff --git a/test/langtools/tools/javac/LocalClassCtorPrologue.out b/test/langtools/tools/javac/LocalClassCtorPrologue.out index f1a999af491..65f3418825d 100644 --- a/test/langtools/tools/javac/LocalClassCtorPrologue.out +++ b/test/langtools/tools/javac/LocalClassCtorPrologue.out @@ -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.recompile 1 error diff --git a/test/langtools/tools/javac/SuperInit/EarlyInnerAccessErrorMessageTest.java b/test/langtools/tools/javac/SuperInit/EarlyInnerAccessErrorMessageTest.java new file mode 100644 index 00000000000..a8ee3a2aea5 --- /dev/null +++ b/test/langtools/tools/javac/SuperInit/EarlyInnerAccessErrorMessageTest.java @@ -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(); + } +} diff --git a/test/langtools/tools/javac/SuperInit/EarlyInnerAccessErrorMessageTest.out b/test/langtools/tools/javac/SuperInit/EarlyInnerAccessErrorMessageTest.out new file mode 100644 index 00000000000..a8d690a4c23 --- /dev/null +++ b/test/langtools/tools/javac/SuperInit/EarlyInnerAccessErrorMessageTest.out @@ -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 diff --git a/test/langtools/tools/javac/SuperInit/EarlyLocalClass.out b/test/langtools/tools/javac/SuperInit/EarlyLocalClass.out index 390b68ea2c9..ee01f9c403d 100644 --- a/test/langtools/tools/javac/SuperInit/EarlyLocalClass.out +++ b/test/langtools/tools/javac/SuperInit/EarlyLocalClass.out @@ -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.recompile 1 error