RFR: 8349754: Invalid "early reference" error when class extends an outer class [v2]

Maurizio Cimadamore mcimadamore at openjdk.org
Fri Feb 14 10:14:16 UTC 2025


On Thu, 13 Feb 2025 18:43:27 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>>> From what I can tell we still need to make an exception for the `Foo.this.x`
>> 
>> Sure - I was referring to the "simple name" part of the affair :-)
>
>> Trying to explain this to myself: The current class here is `Foo`, and `Foo.this.x` does indeed refer to a member of class `Foo`. But it refers to a different _instance_ of class `Foo` from the one under construction.
> 
> I will also re-read the JLS carefully, to make sure this is covered

So... N.this is always used to denote an enclosing instance. So, if N is in early construction context, there are two cases:
* this is a "simple assignment", in which case the spec says it's ok
* it's not an assignment (but a field read), in which case it's an error.

In your example above, `Early` is not in early construction context when we are in the `Sub` constructor, so none of the above applies? I guess in terms of code, what this means is that I'm surprised that we're handling the implicit and explicit cases in the same test. E.g. when using a qualified `X.this`, the membership check seems irrelevant (the only thing that matters is whether `X` is in early construction context).

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23545#discussion_r1955892604


More information about the compiler-dev mailing list