----- Mail original -----
> De: "Brian Goetz" <brian.go...@oracle.com>
> À: "Remi Forax" <fo...@univ-mlv.fr>, "core-libs-dev" 
> <core-libs-dev@openjdk.java.net>
> Cc: "amber-spec-experts" <amber-spec-expe...@openjdk.java.net>
> Envoyé: Lundi 7 Juin 2021 17:06:20
> Objet: Re: case null vs case dominance

> On 6/7/2021 5:51 AM, Remi Forax wrote:
>> Hi all,
>> the first part of the message is about javac error message that could be
>> improved,
>> the second part is about the current spec being not very logical.
>>
>> With this code
>>
>>      Object o = null;
>>      var value = switch(o) {
>>            //case null -> 0;
>>            case Object __ -> 0;
>>            case null -> 0;
>>      };
>>      System.out.println(value);
>>
>> The error message is
>>    PatternMatching101.java:70: error: this case label is dominated by a 
>> preceding
>>    case label
>>            case null -> 0;
>>            ^
>>
>> The error message is wrong here, because it's 'case null' and you can put a 
>> case
>> null where you want but below a total pattern, so the error mesage should
>> reflect that.
> 
> But the case null *is* dominated by the total pattern, and therefore dead.

it depends on the order you applies the rules
you can also says that because there is a case null, Object does not accept 
null so it's not a total pattern so it doesn't not dominate null.

I think it's an error but i think there should be a special rule for it.

> 
>> Here is an example that compiles showing that case null can be below a case
>> String, which it dominates
>>
>>      Object o = null;
>>      var value = switch(o) {
>>            case String s -> 0;
>>            case null -> 0;
>>            default -> 0;
>>      };
> 
> In this case, the String pattern is not total, so it does not dominate null.

That's my point, cf above.

Rémi

Reply via email to