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

Jan Lahoda jlahoda at openjdk.java.net
Thu Jan 28 19:27:43 UTC 2021

On Thu, 28 Jan 2021 18:45:21 GMT, Vicente Romero <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.

Looking at the spec here:

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

More information about the compiler-dev mailing list