Commit 0182e06
committed
Fix improper usage of
In multiple places, we had code equivalent to the following pattern:
val (tl2, targs) = constrained(tl)
tl2.resultType <:< ...
which lead to subtype checks directly involving the TypeParamRefs of the
constrained type lambda. This commit uses the following pattern instead:
val (tl2, targs) = constrained(tl)
tl2.instantiate(targs.map(_.tpe)) <:< ...
which substitutes the TypeParamRefs by the corresponding TypeVars in the
constraint. This is necessary because when comparing
TypeParamRefs in isSubType:
- we only recurse on the bounds of the TypeParamRef using
`isSubTypeWhenFrozen` which prevents further constraints from being
added (see the added stm.scala test case for an example where this
matters).
- if the corresponding TypeVar is instantiated and the TyperState has
been gc()'ed, there is no way to find the instantiation corresponding
to the current TypeParamRef anymore.
There is one place where I left the old logic intact:
`TrackingTypeComparer#matchCase` because the match type caching
logic (in `MatchType#reduced`) conflicted with the use of TypeVars since
it retracts the current TyperState.
This change breaks a test which involves an unlikely combination of
implicit conversion, overloading and apply insertion. Given that there
is always a tension between type inference and implicit conversion, and
that we're discouraging uses of implicit conversions, I think that's an
acceptable trade-off.constrained breaking type inference1 parent faf9538 commit 0182e06
File tree
6 files changed
+27
-13
lines changed- compiler
- src/dotty/tools/dotc/typer
- test/dotty/tools/dotc/core
- tests/pos
6 files changed
+27
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
411 | 411 | | |
412 | 412 | | |
413 | 413 | | |
414 | | - | |
| 414 | + | |
415 | 415 | | |
416 | 416 | | |
417 | 417 | | |
| |||
1571 | 1571 | | |
1572 | 1572 | | |
1573 | 1573 | | |
1574 | | - | |
| 1574 | + | |
1575 | 1575 | | |
1576 | 1576 | | |
1577 | 1577 | | |
| |||
1738 | 1738 | | |
1739 | 1739 | | |
1740 | 1740 | | |
1741 | | - | |
| 1741 | + | |
1742 | 1742 | | |
1743 | 1743 | | |
1744 | 1744 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
659 | 659 | | |
660 | 660 | | |
661 | 661 | | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
662 | 667 | | |
663 | 668 | | |
664 | 669 | | |
| |||
707 | 712 | | |
708 | 713 | | |
709 | 714 | | |
710 | | - | |
| 715 | + | |
711 | 716 | | |
712 | 717 | | |
713 | 718 | | |
| |||
726 | 731 | | |
727 | 732 | | |
728 | 733 | | |
729 | | - | |
| 734 | + | |
730 | 735 | | |
731 | 736 | | |
732 | 737 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | | - | |
22 | | - | |
| 22 | + | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | | - | |
41 | | - | |
| 41 | + | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | | - | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | | - | |
39 | 38 | | |
40 | 39 | | |
41 | 40 | | |
| |||
0 commit comments