RFR: 8254105: allow static nested declarations [v4]

Maurizio Cimadamore mcimadamore at openjdk.java.net
Wed Oct 28 18:02:48 UTC 2020


On Tue, 27 Oct 2020 14:23:37 GMT, Vicente Romero <vromero at openjdk.org> wrote:

>> Please review the fix for [JDK-8254105](https://bugs.openjdk.java.net/browse/JDK-8254105). The intention of the fix is to allow static members to be declared inside inner classes. The spec allowing this change can be seen at [Local and Nested Static Declarations](http://cr.openjdk.java.net/~gbierman/8246771/8246771-20200928/specs/local-statics-jls.html). This change is part of the [Records JEP](https://openjdk.java.net/jeps/395). The idea is to allow not only records to be defined inside inner classes but also interfaces, enums, static classes and methods.
>> 
>> TIA,
>> Vicente
>> 
>> PS: the records spec can be accessed here [Record Classes](http://cr.openjdk.java.net/~gbierman/8246771/8246771-20200928/specs/records-jls.html). This patch also adds a test to check the changes in the Records spec to Chapter 13 "Binary Compatibility". I'm OK moving that test to a separate PR.
>
> Vicente Romero has updated the pull request incrementally with one additional commit since the last revision:
> 
>   removing duplicated test

The changes look good, but I have one concern: this patch seem to apply the improvements unconditionally, regardless of the source version - is this what we want? While I understand that the risk is low (this patch makes space of compilable programs bigger), at the same times it feels wrong that when compiling with `--source 14` I can now nest static classes inside member classes (which is not compatible with what the SE 14 spec says).

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java line 1232:

> 1230:                     mask |= STATIC;
> 1231:                 else if ((flags & ENUM) != 0 || (flags & RECORD) != 0) {
> 1232:                     //log.error(pos, Errors.StaticDeclarationNotAllowedInInnerClasses);

Can't you get rid of the `else if` here?

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java line 1306:

> 1304:                                 SEALED,
> 1305:                            FINAL | NON_SEALED)
> 1306:                  && checkDisjoint(pos, flags,

Where is this coming from? This seems outside the scope of the change?

-------------

PR: https://git.openjdk.java.net/jdk/pull/571


More information about the compiler-dev mailing list