Integrated: 8356551: Javac rejects receiver parameter in constructor of local class in early construction context

Archie Cobbs acobbs at openjdk.org
Tue May 13 14:33:57 UTC 2025


On Fri, 9 May 2025 17:13:08 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:

> 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.

This pull request has now been integrated.

Changeset: b8c69dfb
Author:    Archie Cobbs <acobbs at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/b8c69dfb2adb0eb8cce6b5e81a7388a6430eb8fb
Stats:     30 lines in 3 files changed: 22 ins; 0 del; 8 mod

8356551: Javac rejects receiver parameter in constructor of local class in early construction context

Reviewed-by: mcimadamore

-------------

PR: https://git.openjdk.org/jdk/pull/25153


More information about the compiler-dev mailing list