Different handing of "this" vs. "MyClass.this" in definite assignment

Brian Goetz brian.goetz at oracle.com
Fri Dec 2 17:13:50 UTC 2022


Re-reading Ch16, you're right, this seems simpler than I was making it.  
There are several sentences of the form

> Such an assignment is defined to occur if and only if either the 
> simple name of the
> variable (or, for a field, its simple name qualified by this)

I think these can be refined to say something like

(or for a field, its simple named qualified by `this` (both qualified 
and unqualified))

This language is already present in 16.1.10, but missing in other uses 
of "qualified by this" in Ch16.  We're not talking about `this` and 
`X.this`, but about different ways to name the same field.


On 12/1/2022 4:29 PM, Archie Cobbs wrote:
> On Thu, Dec 1, 2022 at 1:03 PM Brian Goetz <brian.goetz at oracle.com> wrote:
>
>     To come up with a sensible meaning of option (2), I think we have
>     to assess the spec impact of threading the equivalence of
>     `[implicit C].this` and `C.this` through the spec?
>
>
> I think it depends on how ambitious you want to be.
>
> At its narrowest, this issue is not about the equivalence of 
> "MyClass.this" and "this", it's about the equivalence of 
> "MyClass.this.foo" and "this.foo", and only as that relates to 
> definite assignment, i.e., it's about the definition of the phrase 
> "access to its value" in the first two sentences of JLS §16. And of 
> course this definition is a lexical one, not a semantic one.
>
> I agree it would be nicer if the entire JLS were refactored to make 
> "MyClass.this" and "this" always mean the same thing (only when "this" 
> has type MyClass of course), but that's a bigger change than is 
> strictly necessary here. And I'm fuzzier on what that would even 
> mean... what other sections are there besides §16 that talk about 
> "this" and/or "MyClass.this" in lexical terms instead of in terms of 
> the object reference that they represent? I'm not familiar enough to 
> know if there even are any, or which sections they are, off the top of 
> my head.
>
> -Archie
>
> -- 
> Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20221202/441e8e52/attachment.htm>


More information about the amber-dev mailing list