RFR: 8194743: Compiler implementation for Statements before super() [v2]

Archie Cobbs acobbs at openjdk.org
Wed Apr 26 02:27:24 UTC 2023


On Wed, 26 Apr 2023 01:06:37 GMT, ExE Boss <duke at openjdk.org> wrote:

>> Archie Cobbs has updated the pull request incrementally with two additional commits since the last revision:
>> 
>>  - Small refactoring to avoid redundant test.
>>  - Fix typo in comment.
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java line 5591:
> 
>> 5589:         }
>> 5590: 
>> 5591:         // Check for proper placement of super()/init() calls.
> 
> Suggestion:
> 
>         // Check for proper placement of super()/this() calls.

Thanks for catching that - fixed in 0e638da2daa.

> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java line 2859:
> 
>> 2857:                         letInit(tree.pos(), sym);
>> 2858:                 }
>> 2859:             }
> 
> The common `isConstructor` check can be moved to an enclosing `if` statement:
> 
> Suggestion:
> 
>             if (isConstructor) {
>                 // If super(): at this point all initialization blocks will execute
>                 Name name = TreeInfo.name(tree.meth);
>                 if (name == names._super) {
>                     forEachInitializer(classDef, false, def -> {
>                         scan(def);
>                         clearPendingExits(false);
>                     });
>                 }
> 
>                 // If this(): at this point all final uninitialized fields will get initialized
>                 else if (name == names._this) {
>                     for (int address = firstadr; address < nextadr; address++) {
>                         VarSymbol sym = vardecls[address].sym;
>                         if (isFinalUninitializedField(sym) && !sym.isStatic())
>                             letInit(tree.pos(), sym);
>                     }
>                 }
>             }

Yep, thanks - applied in 0e638da2daa.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13656#discussion_r1177249124
PR Review Comment: https://git.openjdk.org/jdk/pull/13656#discussion_r1177249633


More information about the compiler-dev mailing list