RFR: JDK-8315458 Implementation of Implicitly Declared Classes and Instance Main Method (Second Preview) [v2]

Jim Laskey jlaskey at openjdk.org
Thu Nov 2 12:01:13 UTC 2023

On Thu, 2 Nov 2023 11:12:14 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Jim Laskey has updated the pull request incrementally with one additional commit since the last revision:
>>   Remove obsolete tests
> src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java line 249:
>> 247:         STRING_TEMPLATES(JDK21, Fragments.FeatureStringTemplates, DiagKind.PLURAL),
>> 248:         UNNAMED_CLASSES(JDK21, Fragments.FeatureUnnamedClasses, DiagKind.PLURAL),
>> 249:         IMPLICIT_CLASSES(JDK21, Fragments.FeatureImplicitClasses, DiagKind.PLURAL),
> Should this be JDK22?

No. It should be left at the first preview level.

> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java line 442:
>> 440:                           Errors.ClassPublicShouldBeInFile(topElement, tree.name));
>> 441:             }
>> 442:             if ((tree.mods.flags & IMPLICIT_CLASS) != 0) {
> I'm not 100% sure about this. Another option would be to tweak Resolve::findType and make sure that `typeNotFound` (or some more specific message!) is returned when an implicit class is referred to by name. If you look at the first few lines in that method you will see:
> if (name == names.empty)
>             return typeNotFound; // do not allow inadvertent "lookup" of anonymous types
> So, there's already some logic there for skipping some types.

The main thing here is that it is done once at the source instead of every look up. The symbol should not exist in the compilation unit.

> src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java line 4057:
>> 4055:         Name name = names.fromString(simplename);
>> 4056:         JCModifiers implicitMods = F.at(Position.NOPOS)
>> 4057:                 .Modifiers(Flags.FINAL|Flags.MANDATED|Flags.IMPLICIT_CLASS, List.nil());
> I don't think the JVMS allows for a flag to have ACC_MANDATED flags?
> It is a limitation of the class file format that only formal parameters and modules can be flagged as ACC_MANDATED ([§4.7.24](https://docs.oracle.com/javase/specs/jvms/se21/html/jvms-4.html#jvms-4.7.24), [§4.7.25](https://docs.oracle.com/javase/specs/jvms/se21/html/jvms-4.html#jvms-4.7.25)) to indicate that, despite being compiler-generated, they are not considered implementation artifacts. There is no way to flag other compiler-generated constructs so that they too are not considered implementation artifacts (JLS §13.1). This limitation means that reflective APIs of the Java SE Platform may not accurately indicate the "mandated" status of such constructs.

The spec has been updated to include implicit classes.


PR Review Comment: https://git.openjdk.org/jdk/pull/16461#discussion_r1379993631
PR Review Comment: https://git.openjdk.org/jdk/pull/16461#discussion_r1379993078
PR Review Comment: https://git.openjdk.org/jdk/pull/16461#discussion_r1379990952

More information about the compiler-dev mailing list