RFR: JDK14-8236005: local records shouldn't capture any non-static state from any enclosing type

Vicente Romero vicente.romero at oracle.com
Fri Jan 10 22:53:47 UTC 2020



On 1/10/20 2:06 PM, Maurizio Cimadamore wrote:
> Not 100% sure - shouldn't the "staticOnly" variable be set to true 
> when we are inside a local record, so that the existing check will 
> issue an error?
>
> I see that "staticOnly" is set in this routine:
>
>     /** An environment is "static" if its static level is greater than
>      *  the one of its outer environment
>      */
>     protected static boolean isStatic(Env<AttrContext> env) {
>         return env.outer != null && env.info.staticLevel > 
> env.outer.info.staticLevel;
>     }

staticOnly is true, it is because of the rest of the conditions that the 
static error is not generated. So with the current conditions this code 
fails correctly:

class R {
     int z = 0;
     void m() {
         record RR(int x) { public int x() { return z; }};
     }
}

here we have:

if (staticOnly &&                          // true
     sym.kind ==VAR &&
     sym.owner.kind ==TYP &&               // true it is a field
     (sym.flags() &STATIC) ==0)           // true is is not static, then error
     return new StaticError(sym);

but this code is accepted:

class R {
     void m() {
         int z = 0;
         record RR(int x) { public int x() { return z; }};
     }
}


if (staticOnly &&                          // true
     sym.kind ==VAR &&
     sym.owner.kind ==TYP &&               // false it is a local variable
     (sym.flags() &STATIC) ==0)           // true is is not static but it won't be evaluated anyway, then NO error
     return new StaticError(sym);

that's why I added the additional conditions

>
> Which makes me think that, maybe the staticLevel of the local record 
> has not increased its value as expected?
>
> Maurizio

Vicente

>
> On 10/01/2020 03:54, Vicente Romero wrote:
>> Hi,
>>
>> Please review the fix for [1] at [2]. This fix is for the compiler to 
>> emit an error if a local record accesses non-static state from the 
>> enclosing environment
>>
>> Thanks,
>> Vicente
>>
>> [1] https://bugs.openjdk.java.net/browse/JDK-8236005
>> [2] http://cr.openjdk.java.net/~vromero/8236005/webrev.00/
>>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20200110/cc2a3913/attachment.htm>


More information about the compiler-dev mailing list