On Mon, 1 Sep 2025 12:17:45 GMT, Maurizio Cimadamore <[email protected]>
wrote:
> > Do we still need the changes in `Attr.checkAssignable` -- e.g. flexible
> > constructor bodies used to check some extra properties in there. Now that
> > we have an LHS variable in the prologue scanner, I wonder if we can unify
> > the checks?
>
> I did an experiment, and adding this:
>
> ```
> if (isInLHS && !insideLambdaOrClassDef) {
> // Check instance field assignments that appear in
> constructor prologues
> if (isEarlyReference(localEnv, tree.hasTag(SELECT) ?
> ((JCFieldAccess)tree).selected : null, sym)) {
> // Field may not be inherited from a superclass
> if (sym.owner != localEnv.enclClass.sym) {
> log.error(tree, Errors.CantRefBeforeCtorCalled(sym));
> return;
> }
>
> // Field may not have an initializer
> if ((sym.flags() & HASINIT) != 0) {
> log.error(tree,
> Errors.CantAssignInitializedBeforeCtorCalled(sym));
> return;
> }
> }
> return;
> };
> ```
>
> At the start of `analyzeSymbol` seems to work fine. Maybe we want to break
> `analyzeSymbol` in different parts, one for reads and one for writes.
>
> But one nice consequence of this is that now `isEarlyReference` is only
> called inside this visitor -- this means we can probably avoid having to pass
> `isPrologue = true` and, we can also avoid this dance:
>
> ```
> tree.hasTag(SELECT) ? ((JCFieldAccess)tree).selected : null
> ```
>
> Which is required at every callsite.
addressed in last commit, thanks!
-------------
PR Comment: https://git.openjdk.org/valhalla/pull/1523#issuecomment-3243287853