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

Maurizio Cimadamore mcimadamore at openjdk.java.net
Fri May 13 14:35:50 UTC 2022


On Fri, 13 May 2022 11:34:32 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

>> 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.

ok!

>> 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`.

Good - I suspected it had to do with error recovery - but wanted to make sure I didn't miss anything.

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

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


More information about the core-libs-dev mailing list