RFR: 8356551: Javac rejects receiver parameter in constructor of local class in early construction context
Archie Cobbs
acobbs at openjdk.org
Fri May 9 17:19:06 UTC 2025
Consider a class like this:
class Outer {
Outer() {
class Local {
Local(Outer Outer.this) { // "receiver parameter"
}
}
super();
}
}
Normally, a reference to `Outer.this` appearing anywhere in `Local` would generate an error because `Local` is defined in an early construction context of `Outer`. But in the above example, `Outer.this` is a "receiver parameter", which is the relatively obscure mechanism by which type annotations can be added to the outer instance (JLS §8.4).
This is allowed, even though the outer instance is otherwise inaccessible here. However, the compiler was reporting an error. This PR adds an exception for receiver parameters to the illegal early access check. It also adds a missing bug ID to the regression test.
-------------
Commit messages:
- Update copyrights.
- Allow prologue references to "Foo.this" when appearing as a receiver parameter.
Changes: https://git.openjdk.org/jdk/pull/25153/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=25153&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8356551
Stats: 31 lines in 3 files changed: 22 ins; 0 del; 9 mod
Patch: https://git.openjdk.org/jdk/pull/25153.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/25153/head:pull/25153
PR: https://git.openjdk.org/jdk/pull/25153
More information about the compiler-dev
mailing list