RFR: 8282274: Compiler implementation for Pattern Matching for switch (Third Preview) [v11]
Jan Lahoda
jlahoda at openjdk.java.net
Fri May 13 11:39:09 UTC 2022
On Fri, 13 May 2022 09:29:20 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> Jan Lahoda has updated the pull request incrementally with two additional commits since the last revision:
>>
>> - Updating naming to more closely follow the spec: total patterns are renamed to unconditional patterns, unrefined is now unguarded.
>> - Case label elements cannot be unguarded if they have a guard of a type different than boolean.
>
> src/java.base/share/classes/java/lang/MatchException.java line 58:
>
>> 56: * @param message the detail message (which is saved for later retrieval
>> 57: * by the {@link #getMessage()} method).
>> 58: * @param cause the cause (which is saved for later retrieval by the
>
> This looks odd - it seems like the sentence is like this:
>
> `the cause ( foo ). (bar)`. E.g. the test in parenthesis exceeds the test outside parenthesis by a wide margin. I suggest both here and in the "message" @param to avoid the parenthesis and split the sentence instead. Examples:
>
>
> * @param message the detail message. The message is saved for later retrieval
> * by the {@link #getMessage()} method).
>
>
> and
>
>
> * @param cause the cause. The cause is saved for later retrieval by the
> * {@link #getCause()} method). A {@code null} value is
> * permitted, and indicates that the cause is nonexistent or
> * unknown.
>
>
> Of course this is just an idea.
I believe this text is taken form another exception in java.lang. If that would be OK, I'd look at this in a followup/separate issue.
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java line 1802:
>
>> 1800: unguarded &&
>> 1801: !patternType.isErroneous() &&
>> 1802: types.isSubtype(types.boxedTypeOrType(types.erasure(seltype)),
>
> This seems to be a change compared to the previous code - e.g. handling of boxing in the switch target type. Is this code even exercised? The test "NotApplicableTypes" seems to rule the combination `switch (int) ... case Integer` out.
Yes, `switch ("int") { case Integer i -> }` is not allowed. The intent of `boxedTypeOrType` is to reduce follow-up errors, as `Integer i` will be considered to be unconditional over `int`.
-------------
PR: https://git.openjdk.java.net/jdk/pull/8182
More information about the core-libs-dev
mailing list