File tree Expand file tree Collapse file tree 5 files changed +47
-1
lines changed
src/jdk.compiler/share/classes/com/sun/tools/javac
test/langtools/tools/javac/SuperInit Expand file tree Collapse file tree 5 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -1381,6 +1381,17 @@ public void visitSelect(JCFieldAccess tree) {
13811381 SelectScanner ss = new SelectScanner ();
13821382 ss .scan (tree );
13831383 if (ss .scanLater == null ) {
1384+ Symbol sym = TreeInfo .symbolFor (tree );
1385+ // if this is a field access
1386+ if (sym .kind == VAR && sym .owner .kind == TYP ) {
1387+ // Type.super.field or super.field expressions are forbidden in early construction contexts
1388+ for (JCTree subtree : ss .selectorTrees ) {
1389+ if (TreeInfo .isSuperOrSelectorDotSuper (subtree )) {
1390+ reportPrologueError (tree , sym );
1391+ return ;
1392+ }
1393+ }
1394+ }
13841395 analyzeSymbol (tree );
13851396 } else {
13861397 boolean prevLhs = isInLHS ;
Original file line number Diff line number Diff line change @@ -179,6 +179,21 @@ public static boolean isIdentOrThisDotIdent(JCTree tree) {
179179 }
180180 }
181181
182+ /** Is this tree `super`, or `Ident.super`?
183+ */
184+ public static boolean isSuperOrSelectorDotSuper (JCTree tree ) {
185+ switch (tree .getTag ()) {
186+ case PARENS :
187+ return isSuperOrSelectorDotSuper (skipParens (tree ));
188+ case IDENT :
189+ return ((JCIdent )tree ).name == ((JCIdent )tree ).name .table .names ._super ;
190+ case SELECT :
191+ return ((JCFieldAccess )tree ).name == ((JCFieldAccess )tree ).name .table .names ._super ;
192+ default :
193+ return false ;
194+ }
195+ }
196+
182197 /** Check if the given tree is an explicit reference to the 'this' instance of the
183198 * class currently being compiled. This is true if tree is:
184199 * - An unqualified 'this' identifier
Original file line number Diff line number Diff line change @@ -269,4 +269,20 @@ static class Inner8 {
269269 x = 4 ;
270270 }
271271 }
272+
273+ static class Inner9 {
274+ interface Parent {
275+ boolean check = true ;
276+ }
277+
278+ class Medium implements Parent {}
279+
280+ class Inner9Test extends Medium {
281+ Inner9Test () {
282+ boolean check1 = Inner9Test .super .check ;
283+ boolean check2 = super .check ;
284+ super ();
285+ }
286+ }
287+ }
272288}
Original file line number Diff line number Diff line change @@ -26,6 +26,8 @@ SuperInitFails.java:232:16: compiler.err.cant.ref.before.ctor.called: x
2626SuperInitFails.java:241:35: compiler.err.cant.ref.before.ctor.called: this
2727SuperInitFails.java:253:13: compiler.err.cant.ref.before.ctor.called: x
2828SuperInitFails.java:266:18: compiler.err.cant.ref.before.ctor.called: x
29+ SuperInitFails.java:282:50: compiler.err.cant.ref.before.ctor.called: check
30+ SuperInitFails.java:283:39: compiler.err.cant.ref.before.ctor.called: check
2931SuperInitFails.java:35:13: compiler.err.call.must.only.appear.in.ctor
3032SuperInitFails.java:39:14: compiler.err.call.must.only.appear.in.ctor
3133SuperInitFails.java:43:14: compiler.err.call.must.only.appear.in.ctor
@@ -35,4 +37,4 @@ SuperInitFails.java:55:32: compiler.err.call.must.only.appear.in.ctor
3537SuperInitFails.java:85:18: compiler.err.ctor.calls.not.allowed.here
3638SuperInitFails.java:91:13: compiler.err.return.before.superclass.initialized
3739SuperInitFails.java:152:18: compiler.err.call.must.only.appear.in.ctor
38- 37 errors
40+ 39 errors
Original file line number Diff line number Diff line change @@ -32,3 +32,5 @@ SuperInitFails.java:188:32: compiler.warn.would.not.be.allowed.in.prologue: x
3232SuperInitFails.java:231:41: compiler.warn.would.not.be.allowed.in.prologue: x
3333SuperInitFails.java:232:16: compiler.warn.would.not.be.allowed.in.prologue: x
3434SuperInitFails.java:241:35: compiler.warn.would.not.be.allowed.in.prologue: this
35+ SuperInitFails.java:282:50: compiler.warn.would.not.be.allowed.in.prologue: check
36+ SuperInitFails.java:283:39: compiler.warn.would.not.be.allowed.in.prologue: check
You can’t perform that action at this time.
0 commit comments