When several patterns are total ?
forax at univ-mlv.fr
forax at univ-mlv.fr
Sun Aug 30 21:58:04 UTC 2020
----- Mail original -----
> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Envoyé: Dimanche 30 Août 2020 16:37:53
> Objet: Re: When several patterns are total ?
> ,
>> i've hinted that there is an issue with intersection type and totality, but we
>> did not follow up.
>>
>> Here is the issue
>> var value = flag? "foo": 42;
>> switch(value) {
>> case String s -> ...
>> case Integer i -> ...
>> case Serializable s ->
>> case Comparable<?> c ->
>> }
>>
>> given that the type of value is an intersection type Serializable &
>> Comparable<?> & ...
>> the last two cases are total with respect to the type of value. which does not
>> go well with the current semantics that can only have one total case.
>
> Let’s separate the issues here. The type involved is an infinite type, which I
> think we can agree is a distraction. But lets assume the type of value were
> Serializable&Comparable (S&C for short.)
>
> Because S&C <: S, the `case S` in your example is already total, so the `case C`
> should be a dead case and yield a compilation error. According to the rule we
> have, `case S` is total on any U <: S, so it is total on S&C, so the current
> model covers this, and the `case C` is identified as dead by the compiler.
> Which makes sense because there’s no value it can match.
>
> I’m not seeing the problem?
Ok, that seems logical, good.
Rémi
More information about the amber-spec-experts
mailing list