Skip to content

Commit

Permalink
8334043: VerifyError when inner class is accessed in prologue
Browse files Browse the repository at this point in the history
Reviewed-by: jpai
Backport-of: d4c13737171b7ab7a8a29a69fa9965f8363c5aee
  • Loading branch information
Vicente Romero committed Jun 19, 2024
1 parent d9dd2d1 commit 12a61bc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3863,7 +3863,20 @@ private boolean isAllowedEarlyReference(DiagnosticPosition pos, Env<AttrContext>

// Get the symbol's qualifier, if any
JCExpression lhs = TreeInfo.skipParens(assign.lhs);
JCExpression base = lhs instanceof JCFieldAccess select ? select.selected : null;
JCExpression base;
switch (lhs.getTag()) {
case IDENT:
base = null;
break;
case SELECT:
JCFieldAccess select = (JCFieldAccess)lhs;
base = select.selected;
if (!TreeInfo.isExplicitThisReference(types, (ClassType)env.enclClass.type, base))
return false;
break;
default:
return false;
}

// If an early reference, the field must not be declared in a superclass
if (isEarlyReference(env, base, v) && v.owner != env.enclClass.sym)
Expand Down
11 changes: 11 additions & 0 deletions test/langtools/tools/javac/SuperInit/EarlyAssignments.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,15 @@ public Inner7() {
super();
}
}

public static class Inner8 {
class Inner8a {
int x;
}

public Inner8() {
this.new Inner8a().x = 1; // FAIL - illegal early access
super();
}
}
}
3 changes: 2 additions & 1 deletion test/langtools/tools/javac/SuperInit/EarlyAssignments.out
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ EarlyAssignments.java:134:17: compiler.err.cant.ref.before.ctor.called: super
EarlyAssignments.java:139:23: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:148:13: compiler.err.cant.assign.initialized.before.ctor.called: x
EarlyAssignments.java:157:13: compiler.err.cant.assign.val.to.var: final, x
EarlyAssignments.java:168:13: compiler.err.cant.ref.before.ctor.called: this
- compiler.note.preview.filename: EarlyAssignments.java, DEFAULT
- compiler.note.preview.recompile
25 errors
26 errors

0 comments on commit 12a61bc

Please sign in to comment.