----- Mail original -----
> De: "Brian Goetz" <[email protected]>
> À: "Remi Forax" <[email protected]>
> Cc: "amber-spec-experts" <[email protected]>
> 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