RFR: 8259905: Compiler treats 'sealed' keyword as 'var' keyword

Gavin Bierman Gavin.Bierman at oracle.com
Thu Jan 28 21:41:24 UTC 2021


No that is an omission. `sealed` and `permits` should be classified as restricted identifiers (new concept to JLS 16) and thus not valid type identifiers. I’ll fix this in the next version of the spec.

Gavin

> On 28 Jan 2021, at 19:27, Jan Lahoda <jlahoda at openjdk.java.net> wrote:
> 
> On Thu, 28 Jan 2021 18:45:21 GMT, Vicente Romero <vromero at openjdk.org <mailto:vromero at openjdk.org>> wrote:
> 
>> Hi,
>> 
>> Please review this fix which is basically fixing an oversaw issue affecting new restricted keywords: `sealed` and `permits`. The fix per se is in lines: 3341-3343, but then I made some additional changes to the position where previous errors were reported at method JavacParser::variableDeclaratorRest. That was done for consistency with the new code. I could have done the other way but then users would have two error notifications for some code, one for the use of the restricted type per se and another one for the use of the variable or field so like:
>> 
>> void m() {
>>    sealed s1;
>>    ^
>>    compiler error here
>>           ^
>>                and before you go, compiler error here too
>> }
>> I guess it make sense for the already existing code to be positioned on the use of the restricted type and not on the variable declared afterwards. Doing that adjustment has implied some changes to the golden file associated to test ParserTest. Also I added another case and did some additional editing to test SealedCompilationTests.
>> 
>> TIA
> 
> Looking at the spec here:
> http://cr.openjdk.java.net/~gbierman/jep397/jep397-20201204/specs/sealed-classes-jls.html <http://cr.openjdk.java.net/~gbierman/jep397/jep397-20201204/specs/sealed-classes-jls.html>
> 
> It does not seem to exclude `sealed` from `TypeIdentifier` (as the specs exclude `var`, `yield` and `record`). So it should be possible to have a class named `"sealed"`? Seems `sealed` is a keyword only on particular places, like e.g. `open`? But possibly I am not reading the spec properly?
> 
> -------------
> 
> PR: https://git.openjdk.java.net/jdk/pull/2298 <https://git.openjdk.java.net/jdk/pull/2298>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20210128/3054b83b/attachment-0001.htm>


More information about the compiler-dev mailing list