RFR: 8361570: Incorrect 'sealed is not allowed here' compile-time error [v2]
Jan Lahoda
jlahoda at openjdk.org
Tue Jul 8 13:16:39 UTC 2025
On Tue, 8 Jul 2025 12:23:21 GMT, Chen Liang <liach at openjdk.org> wrote:
>> Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Fixing tests.
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java line 559:
>
>> 557: RECORD(Flags.RECORD),
>> 558: RECOVERABLE(Flags.RECOVERABLE),
>> 559: RESTRICTED(Flags.RESTRICTED),
>
> Why do we need to add RESTRCITED this time?
For every `long` value, the needs to be a `enum Flag` constant (which is weak, of course, as there are conceptually multiple flags using the same value, so the mapping to the enum would need to include the Symbol kind). As sealed now has a different number than `RESTRICTED`, `RESTRICTED` needs its own constant.
> test/langtools/tools/javac/flags/ExtendedStandardFlagsOverlayFlagsConflict.java line 66:
>
>> 64: }
>> 65: long flag = ((Number) f.get(null)).longValue();
>> 66: value2FlagFields.computeIfAbsent(flag, _ -> new ArrayList<>())
>
> If we are performing general flag checks, I recommend including checks to ensure there is exactly one bit set (like `Long.lowestOneBit(flag) == flag`)
>
> So we no longer need a map, but can use a Field[64] and use `Long.numberOfTrailingZeros` to map to the array index.
I don't think this check is very general, it is more like a test checking one corner that is apparently problematic. Maurizio proposed a more general test below. There are constants in `Flags` that have multiple bits set (like `ExtendedStandardFlags`). We could filter those out, but having the map allows to collect all flags with the same value, not only 1+1.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26181#discussion_r2192490897
PR Review Comment: https://git.openjdk.org/jdk/pull/26181#discussion_r2192497227
More information about the compiler-dev
mailing list