"With" for records

Brian Goetz brian.goetz at oracle.com
Sat Jun 11 18:16:26 UTC 2022


We also probably want a rule to _prevent_ assignment to any locals 
*other than* the synthetic component locals.  Assigning to uplevel 
locals from within a `with` block seems like asking for trouble; the 
with block is like a transform on the component locals.

However, we may need a story (hope not) for _accessing_ uplevel shadowed 
locals.  For example:

     record R(A contents) { }
     record A(B contents) { }
     record B(int contents) { }

     R r = ...
     R rr = r with { contents = contents with { contents = 3 }}

it is possible that the inner block might want additional information 
from one of the enclosing `contents` variables.



On 6/10/2022 11:25 AM, Brian Goetz wrote:
>> About the declaration of local variables, in Java, there is no 
>> hiding/shadowing between local variables, so a code like this is 
>> rejected ? Or do we introduce a special rule for the hiding of 
>> implicit variables ?
>
> Yes, we probably do need a special rule for this.  The component names 
> are fixed, and collisions are likely, so these synthetic variables 
> will probably have to be allowed to shadow other locals. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20220611/ca018551/attachment-0001.htm>


More information about the amber-spec-experts mailing list