Fwd: Re: RFR: JEP 359-Records: compiler code

Alex Buckley alex.buckley at oracle.com
Fri Nov 1 17:38:55 UTC 2019


On 11/1/2019 5:06 AM, Maurizio Cimadamore wrote:
> "first statement of this constructor must invoke another constructor"
> 
> This has two problems, I think:
> 
> 1) "statement .... must invoke" - a statement does not invoke; maybe 
> rephrase as "first statement ... must be a constructor invocation"
> 
> 2) we don't have a blessed term to name a non-canonical constructor. Can 
> we just say non-canonical in the diagnostic? E.g.
> 
> "the first statement in a non-canonical constructor must be an 
> invocation of another constructor"
> 
> Seems a mouthful.
> 
> I noted that we have this diagnostic around:
> 
> # 0: name
>   230 compiler.err.call.must.be.first.stmt.in.ctor=\
>   231     call to {0} must be first statement in constructor
> 
> Perhaps, inspired by this, we can turn this around and do this:
> 
> "First statement in non-canonical constructor must be a call to 'this'" ?
> 
> This seems more compact.

This weird corner of the language (JLS 8.8.7.1, which should be 
cross-ref'd from the penultimate bullet of 8.10.4) DOES have statements 
that invoke:

-----
Explicit constructor invocation statements are divided into two kinds:

- Alternate constructor invocations begin with the keyword `this` ... 
used to invoke an alternate constructor of the same class.
-----

These "invocation statements" are weird: despite the s-word, they are 
not capital-S "Statements" as defined in chapter 14, and despite the 
i-word, they are not method invocation expressions as defined in chapter 15.

They are so weird that even their most colloquial, snappy description -- 
"a call to 'this'`" -- is weird. It makes sense if you SAY it to 
yourself when writing a program, but I think it's hard to READ -- "A 
call to this what? This constructor? This class?"

I therefore recommend the following message, which tiptoes around the 
ugly term "non-canonical":

"error: constructor is not canonical, so its first statement must invoke 
another constructor"

Alex


More information about the compiler-dev mailing list