Parenthesized "this" and final fields

Alex Buckley alex.buckley at oracle.com
Thu Jun 7 21:45:39 UTC 2018


On 6/7/2018 1:54 PM, Maurizio Cimadamore wrote:

>>>  > Throughout the rest of this chapter, we will, unless explicitly
>>> stated otherwise, write V to represent a local variable or blank |final|
>>> field which is in scope (ยง6.3
>>> <https://docs.oracle.com/javase/specs/jls/se10/html/jls-6.html#jls-6.3>).
>>> Likewise,
>>> we will use |a|, |b|, |c|, and |e| to represent expressions, and S and T
>>> to represent statements. We will use the phrase "|a| is V" to mean that
>>> |a| is either the simple name of the variable V, or V's simple name
>>> qualified by |this| (ignoring parentheses). We will use the phrase "|a|
>>> is not V" to mean the negation of "|a| is V".
>>>
>>> What does this mean? I see many different ways to add parenthesis to a
>>> qualified this reference:
>>>
>>> (this).x = value //as in your example
>>> (this.x) = value
>>>
>>> I trust that the spec here means that every parenthesis should be
>>> dropped; which would suggest we have a bug here.
>>
>> Right. The "ignoring parentheses" clause ought to appear in 16.0 too.
> I mean, I think the spec is fine here, but javac only deals with the
> second kind of parenthesis, not the former - should javac be changed to
> drop both kind of parenthesis?

Yes. The 16.0 text "Throughout the rest of this chapter ..." surely 
intends to look through parentheses as much as possible -- V should be 
`this.x` in

   ( (( (((this))).x )) ++ )

Alex


More information about the compiler-dev mailing list