When several patterns are total ?
Tagir Valeev
amaembo at gmail.com
Sun Aug 30 14:55:14 UTC 2020
Interesting!
How about
try {...}
catch(Ex1 | Ex2 e) {
switch (e) {
case Ex1 -> ...
case Ex2 -> ...
}
}
?
With best regards,
Tagir Valeev.
вс, 30 авг. 2020 г., 21:38 Brian Goetz <brian.goetz at oracle.com>:
> ,
> > 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?
More information about the amber-spec-observers
mailing list