On Fri, 29 Aug 2025 10:47:27 GMT, Maurizio Cimadamore <[email protected]>
wrote:
>> Vicente Romero has updated the pull request incrementally with one
>> additional commit since the last revision:
>>
>> removing unnecessary imports
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java line 1449:
>
>> 1447: * not allowed in the prologue
>> 1448: */
>> 1449: if (insideLambdaOrClassDef ||
>
> I'm not entirely convinced about these checks. They seem to lead to very
> strange asymmetries:
>
>
> import java.util.function.*;
>
> class Test3 {
>
> int x = 4;
> int y;
>
> Test3() {
> System.out.println(x); //error
> Supplier<Integer> s1 = () -> x; // error
> y = 2;
> System.out.println(y); // ok
> Supplier<Integer> s2 = () -> y; // error
> super();
> }
> }
>
>
> I understand that references to `x` are invalid here -- `x` is not a strict
> field, so it will be initialized _after_ the prologue. So the first couple of
> references are errors, fine.
>
> But in the last couple, we have that `print(x)` is good, but the reference
> from the lambda is flagged as an error. I'm not sure what's the rationale
> here? After all the lambda is defined _after_ `y` has been assigned, so what
> are we trying to protect against?
I think that the idea of restricting the access from lambdas and local classes
is that they will capture `this` in order to access the field(s)
> src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java line
> 1010:
>
>> 1008: return node.type.tsym;
>> 1009: return null;
>> 1010: case TYPECAST:
>
> Is this still needed?
yes no for this patch, but I was wondering if it could be useful for future
use. But I will remove it
-------------
PR Review Comment:
https://git.openjdk.org/valhalla/pull/1523#discussion_r2309862398
PR Review Comment:
https://git.openjdk.org/valhalla/pull/1523#discussion_r2309865193