RFR: 8334248: Invalid error for early construction local class constructor method reference [v3]
Maurizio Cimadamore
mcimadamore at openjdk.org
Mon Jun 17 20:46:10 UTC 2024
On Mon, 17 Jun 2024 18:28:17 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:
> > But, interestingly, the error is issued very late (in Lower rather than in Attr). This has to do with the logic that sets AttrContext::ctorPrologue: this field is set to false as soon as we encounter a local class.
>
> Any ugliness is surely due to my incomplete understanding of compiler internals. The assumption is that a new `Env` is created when we encounter a new class declaration, and so the `ctorPrologue` flag is only valid for the current class. So that would make sense that it is reset inside the local class (new `Env` there). Consistent with that, the `Resolve.findVar()` method recurses up through each enclosing `Env`'s and checks the corresponding `ctorPrologue` flag, which corresponds to the scope in which the variable is ultimately found, for being in an early construction context But this may be incomplete or skipped in the `EarlyLocalClass.this` example... ?
The problem is that I don't think there's a new env creation in `visitClassDef`. This calls `Attr::attribClass` which is where the new env is fetched/created. So I think maybe you need to move the place where you set the flag to false?
-------------
PR Comment: https://git.openjdk.org/jdk/pull/19705#issuecomment-2174389150
More information about the compiler-dev
mailing list