javac compiler message when class extends record

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Thu Dec 19 09:32:13 UTC 2019


I agree that the message should align with that we have for enums (so, 
the message should speak about "classes" not "records").

As for records with 'extends' clause not being parseable, I observe the 
same with enums:

jshell> enum E extends Foo { }
|  Error:
|  '{' expected
|  enum E extends Foo { }
|        ^
|  Error:
|  enum constant expected here
|  enum E extends Foo { }
|         ^
|  Error:
|  reached end of file while parsing
|  enum E extends Foo { }
|                        ^

So I think we're at least consistent there (we might want, one day, to 
improve this on both fronts).

Maurizio

On 19/12/2019 04:48, Tagir Valeev wrote:
> Btw note that "record Test() extends Record {}" is not parseable at
> all. The compiler message here is the following:
>
> Test.java:1: error: '{' expected
> record Test() extends Record {}
>               ^
>
> So "records cannot directly extend Record" is never displayed for the records.
>
> With best regards,
> Tagir Valeev.
>
> On Thu, Dec 19, 2019 at 11:45 AM Tagir Valeev <amaembo at gmail.com> wrote:
>> Hello!
>>
>> Consider the following code:
>>
>> class Test extends Record {}
>>
>> When I compile it (build 14-ea+27-1339) I see the following message:
>>
>> Test.java:1: error: records cannot directly extend Record
>> class Test extends Record {}
>> ^
>> Note: Test.java uses preview language features.
>> Note: Recompile with -Xlint:preview for details.
>> 1 error
>>
>> I think it's somewhat confusing as it's not a record at all. For
>> comparison, here's what we have if we change Record to Enum:
>>
>> Test.java:1: error: classes cannot directly extend java.lang.Enum
>> class Test extends Enum {}
>> ^
>>
>> I expect a similar message like "classes cannot directly extend
>> java.lang.Record" in the first case. WDYT?
>>
>> With best regards,
>> Tagir Valeev.


More information about the amber-dev mailing list