Commit f19de96
committed
Cut the Gordian Knot: Don't widen unions to transparent
The idea is that some unions usually make more sense than others. For instance,
if `Apply` and `Ident` are case classes that extend `Tree`, it makes sense to
widen `Apply | Ident` to `Tree`. But it makes less sense to widen `String | Int`
to `Matchable`.
Making sense means: (1) Matches our intuitive understanding, and (2) choosing not to
widen would usually not cause errors.
To explain (2): In the `Tree` case it might well be that we define an implicits on `Inv[Tree]` for
invariant class `Inv`, and then we would not find the implicit for `Inv[Apply | Ident]`.
But it's much less likely that we are looking for an implicit of type `Inv[Any]`.
This commit does two things:
- add logic not to widen a union if the result is a product of only transparent traits or classes.
- treat `Any`, `AnyVal`, `Object`, and `Matchable` as transparent.1 parent 275cfa8 commit f19de96
File tree
8 files changed
+41
-15
lines changed- compiler/src/dotty/tools/dotc/core
- tests
- neg
- pos-deep-subtype
- pos
- run
8 files changed
+41
-15
lines changedLines changed: 15 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
550 | 550 | | |
551 | 551 | | |
552 | 552 | | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
553 | 557 | | |
554 | 558 | | |
555 | 559 | | |
| |||
563 | 567 | | |
564 | 568 | | |
565 | 569 | | |
566 | | - | |
| 570 | + | |
567 | 571 | | |
568 | 572 | | |
569 | 573 | | |
| |||
648 | 652 | | |
649 | 653 | | |
650 | 654 | | |
651 | | - | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
652 | 665 | | |
653 | 666 | | |
654 | 667 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1839 | 1839 | | |
1840 | 1840 | | |
1841 | 1841 | | |
1842 | | - | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
1843 | 1847 | | |
1844 | 1848 | | |
1845 | 1849 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | | - | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | | - | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | | - | |
| 25 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
File renamed without changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
0 commit comments