[lworld] RFR: 8369062: [lworld] Do not allow references to instance fields before a this() invocation
Chen Liang
liach at openjdk.org
Sat Oct 4 04:14:23 UTC 2025
On Sat, 4 Oct 2025 02:40:02 GMT, Vicente Romero <vromero at openjdk.org> wrote:
> implementation of [1] in valhalla. This means that code like:
>
> class Inner7 {
> private int x;
>
> public Inner7(byte y) {
> x = y; // error can't refer to an instance field before a this() invocation
> this((int)y);
> }
> public Inner7(int x) {
> this.x = x;
> super();
> }
> }
>
>
> won't be accepted by javac
> [1] https://bugs.openjdk.org/browse/JDK-8368719
Looks good. Now we are consistently rejecting this field access before this constructor delegation.
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java line 1490:
> 1488: if (mode != PrologueVisitorMode.WARNINGS_ONLY) {
> 1489: if (mode == PrologueVisitorMode.THIS_CONSTRUCTOR) {
> 1490: reportPrologueError(tree, sym);
Can merge this with the `else` in the `allowValueClasses` check above for simplicity.
-------------
Marked as reviewed by liach (Committer).
PR Review: https://git.openjdk.org/valhalla/pull/1659#pullrequestreview-3301528522
PR Review Comment: https://git.openjdk.org/valhalla/pull/1659#discussion_r2403727779
More information about the valhalla-dev
mailing list