RFR: 8334248: Invalid error for early construction local class constructor method reference

Archie Cobbs acobbs at openjdk.org
Thu Jun 13 21:13:14 UTC 2024


On Thu, 13 Jun 2024 16:54:04 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:

> The new "flexible constructors" JEP 482 specifies that a local class declared in an early construction context does not have an immediate outer instance, i.e., it has the same behavior as an anonymous class would in that situation.
> 
> However, the compiler still (incorrectly) tries to verify that an outer instance exists in the case of a method reference to the local class' constructor.
> 
> Example:
> 
> 
> 
> import java.util.function.Supplier;
> 
> class EarlyLocalCtorRef {
> 
>     EarlyLocalCtorRef() {
>         class InnerLocal { }
>         this(InnerLocal::new);
>     }
> 
>     EarlyLocalCtorRef(Supplier<Object> s) {
>     }
> }
> 
> 
> Expected output: Successful compilation.
> 
> Actual output:
> 
> 
> EarlyLocalCtorRef.java:5: error: cannot reference this before supertype constructor has been called
>         this(InnerLocal::new);
>              ^ 
> 
> 
> The fix is to not look for an implicit outer instance for classes that don't have one when encountering a constructor method reference.
> 
> **NOTE:** The test added here will fail until [JDK-8333313](https://bugs.openjdk.org/browse/JDK-8333313) is fixed.

FYI, I said `/integrate` already but we should probably wait for `/sponsor` until [JDK-8333313](https://bugs.openjdk.org/browse/JDK-8333313) is fixed so we don't break the build.

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

PR Comment: https://git.openjdk.org/jdk/pull/19705#issuecomment-2166801631


More information about the compiler-dev mailing list