Skip to content

Commit c466fa0

Browse files
authored
Fix match type reduction with wildcard type arguments (#17065)
Done during the issue spree of Mar 7 2023, with dwijnand, decel, jan-pieter and nmcb.
2 parents 833a41e + 50ff047 commit c466fa0

File tree

10 files changed

+65
-52
lines changed

10 files changed

+65
-52
lines changed

compiler/src/dotty/tools/dotc/core/MatchTypeTrace.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,16 @@ object MatchTypeTrace:
100100
case TryReduce(scrut: Type) =>
101101
i" trying to reduce $scrut"
102102
case NoMatches(scrut, cases) =>
103-
i""" failed since selector $scrut
103+
i""" failed since selector $scrut
104104
| matches none of the cases
105105
|
106106
| ${casesText(cases)}"""
107107
case EmptyScrutinee(scrut) =>
108-
i""" failed since selector $scrut
108+
i""" failed since selector $scrut
109109
| is uninhabited (there are no values of that type)."""
110110
case Stuck(scrut, stuckCase, otherCases) =>
111111
val msg =
112-
i""" failed since selector $scrut
112+
i""" failed since selector $scrut
113113
| does not match ${caseText(stuckCase)}
114114
| and cannot be shown to be disjoint from it either."""
115115
if otherCases.length == 0 then msg
@@ -121,14 +121,14 @@ object MatchTypeTrace:
121121
| ${casesText(otherCases)}"""
122122
case NoInstance(scrut, stuckCase, fails) =>
123123
def params = if fails.length == 1 then "parameter" else "parameters"
124-
i""" failed since selector $scrut
124+
i""" failed since selector $scrut
125125
| does not uniquely determine $params ${fails.map(_._1)}%, % in
126126
| ${caseText(stuckCase)}
127127
| The computed bounds for the $params are:
128128
| ${fails.map((name, bounds) => i"$name$bounds")}%\n %"""
129129

130130
def noMatchesText(scrut: Type, cases: List[Type])(using Context): String =
131-
i"""failed since selector $scrut
131+
i"""failed since selector $scrut
132132
|matches none of the cases
133133
|
134134
| ${casesText(cases)}"""

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2725,7 +2725,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
27252725
x && {
27262726
t.dealias match {
27272727
case tp: TypeRef if !tp.symbol.isClass => false
2728-
case _: SkolemType | _: TypeVar | _: TypeParamRef => false
2728+
case _: SkolemType | _: TypeVar | _: TypeParamRef | _: TypeBounds => false
27292729
case _ => foldOver(x, t)
27302730
}
27312731
}

tests/neg/6570-1.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
| Note: a match type could not be fully reduced:
88
|
99
| trying to reduce N[Box[Int & String]]
10-
| failed since selector Box[Int & String]
10+
| failed since selector Box[Int & String]
1111
| is uninhabited (there are no values of that type).
1212
|
1313
| longer explanation available when compiling with `-explain`
@@ -23,7 +23,7 @@
2323
| Note: a match type could not be fully reduced:
2424
|
2525
| trying to reduce M[T]
26-
| failed since selector T
26+
| failed since selector T
2727
| does not uniquely determine parameter x in
2828
| case Cov[x] => N[x]
2929
| The computed bounds for the parameter are:

tests/neg/6571.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
| Note: a match type could not be fully reduced:
88
|
99
| trying to reduce Test.M[Test.Inv[Int] & Test.Inv[String]]
10-
| failed since selector Test.Inv[Int] & Test.Inv[String]
10+
| failed since selector Test.Inv[Int] & Test.Inv[String]
1111
| is uninhabited (there are no values of that type).
1212
|
1313
| longer explanation available when compiling with `-explain`
@@ -20,7 +20,7 @@
2020
| Note: a match type could not be fully reduced:
2121
|
2222
| trying to reduce Test.M[Test.Inv[String] & Test.Inv[Int]]
23-
| failed since selector Test.Inv[String] & Test.Inv[Int]
23+
| failed since selector Test.Inv[String] & Test.Inv[Int]
2424
| is uninhabited (there are no values of that type).
2525
|
2626
| longer explanation available when compiling with `-explain`

tests/neg/i11982a.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| Note: a match type could not be fully reduced:
77
|
88
| trying to reduce Tuple.Tail[X]
9-
| failed since selector X
9+
| failed since selector X
1010
| does not uniquely determine parameter xs in
1111
| case _ *: xs => xs
1212
| The computed bounds for the parameter are:
@@ -21,7 +21,7 @@
2121
| Note: a match type could not be fully reduced:
2222
|
2323
| trying to reduce Tuple.Tail[X]
24-
| failed since selector X
24+
| failed since selector X
2525
| does not uniquely determine parameter xs in
2626
| case _ *: xs => xs
2727
| The computed bounds for the parameter are:
@@ -36,7 +36,7 @@
3636
| Note: a match type could not be fully reduced:
3737
|
3838
| trying to reduce Tuple.Tail[X]
39-
| failed since selector X
39+
| failed since selector X
4040
| does not uniquely determine parameter xs in
4141
| case _ *: xs => xs
4242
| The computed bounds for the parameter are:

tests/neg/i12049.check

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
| Note: a match type could not be fully reduced:
88
|
99
| trying to reduce M[B]
10-
| failed since selector B
10+
| failed since selector B
1111
| does not match case A => Int
1212
| and cannot be shown to be disjoint from it either.
1313
| Therefore, reduction cannot advance to the remaining case
@@ -18,15 +18,15 @@
1818
-- Error: tests/neg/i12049.scala:14:23 ---------------------------------------------------------------------------------
1919
14 |val y3: String = ??? : Last[Int *: Int *: Boolean *: String *: EmptyTuple] // error
2020
| ^
21-
| Match type reduction failed since selector EmptyTuple.type
21+
| Match type reduction failed since selector EmptyTuple.type
2222
| matches none of the cases
2323
|
2424
| case _ *: _ *: t => Last[t]
2525
| case t *: EmptyTuple => t
2626
-- Error: tests/neg/i12049.scala:22:26 ---------------------------------------------------------------------------------
2727
22 |val z3: (A, B, A) = ??? : Reverse[(A, B, A)] // error
2828
| ^
29-
| Match type reduction failed since selector A *: EmptyTuple.type
29+
| Match type reduction failed since selector A *: EmptyTuple.type
3030
| matches none of the cases
3131
|
3232
| case t1 *: t2 *: ts => Tuple.Concat[Reverse[ts], (t2, t1)]
@@ -39,7 +39,7 @@
3939
| Note: a match type could not be fully reduced:
4040
|
4141
| trying to reduce M[B]
42-
| failed since selector B
42+
| failed since selector B
4343
| does not match case A => Int
4444
| and cannot be shown to be disjoint from it either.
4545
| Therefore, reduction cannot advance to the remaining case
@@ -48,15 +48,15 @@
4848
-- Error: tests/neg/i12049.scala:25:26 ---------------------------------------------------------------------------------
4949
25 |val _ = summon[String =:= Last[Int *: Int *: Boolean *: String *: EmptyTuple]] // error
5050
| ^
51-
| Match type reduction failed since selector EmptyTuple.type
51+
| Match type reduction failed since selector EmptyTuple.type
5252
| matches none of the cases
5353
|
5454
| case _ *: _ *: t => Last[t]
5555
| case t *: EmptyTuple => t
5656
-- Error: tests/neg/i12049.scala:26:29 ---------------------------------------------------------------------------------
5757
26 |val _ = summon[(A, B, A) =:= Reverse[(A, B, A)]] // error
5858
| ^
59-
| Match type reduction failed since selector A *: EmptyTuple.type
59+
| Match type reduction failed since selector A *: EmptyTuple.type
6060
| matches none of the cases
6161
|
6262
| case t1 *: t2 *: ts => Tuple.Concat[Reverse[ts], (t2, t1)]
@@ -69,7 +69,7 @@
6969
| Note: a match type could not be fully reduced:
7070
|
7171
| trying to reduce M[B]
72-
| failed since selector B
72+
| failed since selector B
7373
| does not match case A => Int
7474
| and cannot be shown to be disjoint from it either.
7575
| Therefore, reduction cannot advance to the remaining case

tests/neg/i13780.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
| Note: a match type could not be fully reduced:
1111
|
1212
| trying to reduce Head[X]
13-
| failed since selector X
13+
| failed since selector X
1414
| does not uniquely determine parameters a, b in
1515
| case (a, b) => a
1616
| The computed bounds for the parameters are:
@@ -30,7 +30,7 @@
3030
| Note: a match type could not be fully reduced:
3131
|
3232
| trying to reduce Head[X]
33-
| failed since selector X
33+
| failed since selector X
3434
| does not uniquely determine parameters a, b in
3535
| case (a, b) => a
3636
| The computed bounds for the parameters are:

tests/neg/i15618.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| Note: a match type could not be fully reduced:
1010
|
1111
| trying to reduce ScalaType[T]
12-
| failed since selector T
12+
| failed since selector T
1313
| does not match case Float16 => Float
1414
| and cannot be shown to be disjoint from it either.
1515
| Therefore, reduction cannot advance to the remaining cases

0 commit comments

Comments
 (0)