On Sat, 30 May 2026 00:33:30 GMT, Maurizio Cimadamore <[email protected]> 
wrote:

> * In principle this works but (a) we need to find some way so that an early 
> access in a field initializer is an early access _in all constructors_ at 
> once (but we already have something like that in `Attr`/`Resolve`)

Spoke too fast -- early access from field initializer is NOT proxied correctly. 
This compiles, but then fails with verifier error (this is not a regression, 
apparently this never worked):


class EarlyFieldInitRead {
      static int seed() { return 42; }

      static value class V {
          int x = seed();
          int y = x;
          V() { super(); }
      }

      public static void main(String[] args) {
          new V();
      }
  }


The issue is that when we record early reads in `Attr`/`Resolve` we use 
`env.enclMethod` -- which if we're in a field is not something meaningful. As a 
result, `LocalProxyVarsGen` doesn't pick that up, and doesn't proxy the access.

A simple solution could be to associate early reads from field initializers to 
the enclosing class.

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

PR Comment: https://git.openjdk.org/valhalla/pull/2488#issuecomment-4580987089

Reply via email to