Commit fb5b562
committed
Fix reachability of non-reducing match type children
The reduction of a match type gets "stuck" when a case doesn't match but
is also not provably disjoint from it. In these situations the match
type reduction returns NoType, which means that in `A <:< B` if B
reduces to NoType, then false will be returned.
In the reachability/Space logic subtype checks are used to refine the
candidate children of the scrutinee type so that impossible children
aren't marked as missing and possible cases aren't marked as
unreachable. To achieve that there is already some type mapping that
runs before subtyping to approximate the parent.
We extend that parent approximating logic so that non-reducing match
types in the parent don't result in all the candidate children being
rejected.
The motivating case is NonEmptyTuple, its single-child `*:`, and the
`Tuple.Tail` match type. In `Tuple.Tail[NonEmptyTuple]`, `case _ *: xs
=>` won't match because NonEmptyTuple isn't a subtype of `*:` but it's
also not provably disjoint from it (indeed it's `*:` parent)! So the
reduction gets stuck, leading to NoType, leading to not a subtype.
I had initially looked to fix this for single-child abstract sealed
types, but that would still cause false positives in legitimate
multi-child sealed types and an exhaustive match type (see
WithExhaustiveMatch in patmat/i13189.scala). Also it's less scary to
change the subtyping wrapping logic rather than the actually match
type's reduction/matching logic.
In a way the problem is that subtyping checks is too boolean: the
candidate rejection wants to drop children that are definitely not
subtypes, but the match type reduction is too conservative by returning
NoType as soon as the obvious case isn't met. What subtyping should say
there is ¯\_(ツ)_/¯1 parent e8255c9 commit fb5b562
File tree
3 files changed
+98
-7
lines changed- compiler/src/dotty/tools/dotc/core
- tests/patmat
3 files changed
+98
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
702 | 702 | | |
703 | 703 | | |
704 | 704 | | |
| 705 | + | |
705 | 706 | | |
706 | 707 | | |
707 | 708 | | |
708 | 709 | | |
709 | 710 | | |
710 | | - | |
711 | | - | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
712 | 717 | | |
713 | 718 | | |
714 | 719 | | |
| |||
729 | 734 | | |
730 | 735 | | |
731 | 736 | | |
732 | | - | |
| 737 | + | |
733 | 738 | | |
734 | 739 | | |
735 | 740 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
427 | 427 | | |
428 | 428 | | |
429 | 429 | | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
| 430 | + | |
434 | 431 | | |
435 | 432 | | |
436 | 433 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
0 commit comments