RFR: 8282274: Compiler implementation for Pattern Matching for switch (Third Preview) [v3]

Vicente Romero vromero at openjdk.java.net
Fri Apr 15 03:56:42 UTC 2022


On Thu, 14 Apr 2022 08:46:50 GMT, Aggelos Biboudis <duke at openjdk.java.net> wrote:

>> Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Cleanup.
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java line 1377:
> 
>> 1375:         }
>> 1376:         JCExpression guard = ((JCPattern) cse).guard;
>> 1377:         if (guard != null && guard.type.hasTag(BOOLEAN)) {
> 
> In the spec we see the following:
> 
>> A pattern case element is said to be unrefined if either (i) it has no associated when expression, or (ii) it has an associated when expression that is a constant expression ([15.29](https://docs.oracle.com/javase/specs/jls/se18/html/jls-15.html#jls-15.29)) with value true. A case element is unrefined if it is not a pattern case element or it is an unrefined pattern case element.
> 
> However, in the definition of `unconditional` I don't see the part for the constant expression.
> 
> I wonder if the spec should be updated or the code at this point

the code below checks that the guard is boolean constant `true`, this is the way the compiler can do that, a constant can be retrieved using the `constValue` method

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

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


More information about the core-libs-dev mailing list