[jdk17] RFR: 8269146: Missing unreported constraints on pattern and other case label combination [v2]

Jan Lahoda jlahoda at openjdk.java.net
Tue Jul 6 15:02:56 UTC 2021


On Tue, 6 Jul 2021 10:16:42 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Fixing fallthrough.
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java line 1684:
> 
>> 1682:             boolean hasTotalPattern = false;      // Is there a total pattern?
>> 1683:             boolean hasNullPattern = false;       // Is there a null pattern?
>> 1684:             boolean wasConstant = false;          // Seen a constant in the same case label
> 
> I'd suggest to move the `wasXYZ` variables inside the case label loop - since they are not meant to be variables that are global to the entire switch construct?

I agree it would be much better to have the flags closer, but the flags sadly generally apply across case clauses. The conditions don't allow `case <type pattern>, default:` as well as `case <type pattern>: /*no statements*/ case default:`, because both are `SwitchLabel`s. So we need to keep information across `case` clauses if the case has an empty list of statements, and in some cases even if the list of statements is not empty, but there is a fall-through to the following case (which is to prevent cases like `case null: System.err.println(); /*no break*/ case Integer i:`).

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

PR: https://git.openjdk.java.net/jdk17/pull/194


More information about the compiler-dev mailing list