Skip to content

Commit

Permalink
Fix match type reduction with wildcard type arguments (#17065)
Browse files Browse the repository at this point in the history
Done during the issue spree of Mar 7 2023, with dwijnand, decel,
jan-pieter and nmcb.
  • Loading branch information
smarter authored Mar 7, 2023
2 parents 833a41e + 50ff047 commit c466fa0
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 52 deletions.
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/core/MatchTypeTrace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ object MatchTypeTrace:
case TryReduce(scrut: Type) =>
i" trying to reduce $scrut"
case NoMatches(scrut, cases) =>
i""" failed since selector $scrut
i""" failed since selector $scrut
| matches none of the cases
|
| ${casesText(cases)}"""
case EmptyScrutinee(scrut) =>
i""" failed since selector $scrut
i""" failed since selector $scrut
| is uninhabited (there are no values of that type)."""
case Stuck(scrut, stuckCase, otherCases) =>
val msg =
i""" failed since selector $scrut
i""" failed since selector $scrut
| does not match ${caseText(stuckCase)}
| and cannot be shown to be disjoint from it either."""
if otherCases.length == 0 then msg
Expand All @@ -121,14 +121,14 @@ object MatchTypeTrace:
| ${casesText(otherCases)}"""
case NoInstance(scrut, stuckCase, fails) =>
def params = if fails.length == 1 then "parameter" else "parameters"
i""" failed since selector $scrut
i""" failed since selector $scrut
| does not uniquely determine $params ${fails.map(_._1)}%, % in
| ${caseText(stuckCase)}
| The computed bounds for the $params are:
| ${fails.map((name, bounds) => i"$name$bounds")}%\n %"""

def noMatchesText(scrut: Type, cases: List[Type])(using Context): String =
i"""failed since selector $scrut
i"""failed since selector $scrut
|matches none of the cases
|
| ${casesText(cases)}"""
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2725,7 +2725,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
x && {
t.dealias match {
case tp: TypeRef if !tp.symbol.isClass => false
case _: SkolemType | _: TypeVar | _: TypeParamRef => false
case _: SkolemType | _: TypeVar | _: TypeParamRef | _: TypeBounds => false
case _ => foldOver(x, t)
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/neg/6570-1.check
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
| Note: a match type could not be fully reduced:
|
| trying to reduce N[Box[Int & String]]
| failed since selector Box[Int & String]
| failed since selector Box[Int & String]
| is uninhabited (there are no values of that type).
|
| longer explanation available when compiling with `-explain`
Expand All @@ -23,7 +23,7 @@
| Note: a match type could not be fully reduced:
|
| trying to reduce M[T]
| failed since selector T
| failed since selector T
| does not uniquely determine parameter x in
| case Cov[x] => N[x]
| The computed bounds for the parameter are:
Expand Down
4 changes: 2 additions & 2 deletions tests/neg/6571.check
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
| Note: a match type could not be fully reduced:
|
| trying to reduce Test.M[Test.Inv[Int] & Test.Inv[String]]
| failed since selector Test.Inv[Int] & Test.Inv[String]
| failed since selector Test.Inv[Int] & Test.Inv[String]
| is uninhabited (there are no values of that type).
|
| longer explanation available when compiling with `-explain`
Expand All @@ -20,7 +20,7 @@
| Note: a match type could not be fully reduced:
|
| trying to reduce Test.M[Test.Inv[String] & Test.Inv[Int]]
| failed since selector Test.Inv[String] & Test.Inv[Int]
| failed since selector Test.Inv[String] & Test.Inv[Int]
| is uninhabited (there are no values of that type).
|
| longer explanation available when compiling with `-explain`
6 changes: 3 additions & 3 deletions tests/neg/i11982a.check
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| Note: a match type could not be fully reduced:
|
| trying to reduce Tuple.Tail[X]
| failed since selector X
| failed since selector X
| does not uniquely determine parameter xs in
| case _ *: xs => xs
| The computed bounds for the parameter are:
Expand All @@ -21,7 +21,7 @@
| Note: a match type could not be fully reduced:
|
| trying to reduce Tuple.Tail[X]
| failed since selector X
| failed since selector X
| does not uniquely determine parameter xs in
| case _ *: xs => xs
| The computed bounds for the parameter are:
Expand All @@ -36,7 +36,7 @@
| Note: a match type could not be fully reduced:
|
| trying to reduce Tuple.Tail[X]
| failed since selector X
| failed since selector X
| does not uniquely determine parameter xs in
| case _ *: xs => xs
| The computed bounds for the parameter are:
Expand Down
14 changes: 7 additions & 7 deletions tests/neg/i12049.check
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
| Note: a match type could not be fully reduced:
|
| trying to reduce M[B]
| failed since selector B
| failed since selector B
| does not match case A => Int
| and cannot be shown to be disjoint from it either.
| Therefore, reduction cannot advance to the remaining case
Expand All @@ -18,15 +18,15 @@
-- Error: tests/neg/i12049.scala:14:23 ---------------------------------------------------------------------------------
14 |val y3: String = ??? : Last[Int *: Int *: Boolean *: String *: EmptyTuple] // error
| ^
| Match type reduction failed since selector EmptyTuple.type
| Match type reduction failed since selector EmptyTuple.type
| matches none of the cases
|
| case _ *: _ *: t => Last[t]
| case t *: EmptyTuple => t
-- Error: tests/neg/i12049.scala:22:26 ---------------------------------------------------------------------------------
22 |val z3: (A, B, A) = ??? : Reverse[(A, B, A)] // error
| ^
| Match type reduction failed since selector A *: EmptyTuple.type
| Match type reduction failed since selector A *: EmptyTuple.type
| matches none of the cases
|
| case t1 *: t2 *: ts => Tuple.Concat[Reverse[ts], (t2, t1)]
Expand All @@ -39,7 +39,7 @@
| Note: a match type could not be fully reduced:
|
| trying to reduce M[B]
| failed since selector B
| failed since selector B
| does not match case A => Int
| and cannot be shown to be disjoint from it either.
| Therefore, reduction cannot advance to the remaining case
Expand All @@ -48,15 +48,15 @@
-- Error: tests/neg/i12049.scala:25:26 ---------------------------------------------------------------------------------
25 |val _ = summon[String =:= Last[Int *: Int *: Boolean *: String *: EmptyTuple]] // error
| ^
| Match type reduction failed since selector EmptyTuple.type
| Match type reduction failed since selector EmptyTuple.type
| matches none of the cases
|
| case _ *: _ *: t => Last[t]
| case t *: EmptyTuple => t
-- Error: tests/neg/i12049.scala:26:29 ---------------------------------------------------------------------------------
26 |val _ = summon[(A, B, A) =:= Reverse[(A, B, A)]] // error
| ^
| Match type reduction failed since selector A *: EmptyTuple.type
| Match type reduction failed since selector A *: EmptyTuple.type
| matches none of the cases
|
| case t1 *: t2 *: ts => Tuple.Concat[Reverse[ts], (t2, t1)]
Expand All @@ -69,7 +69,7 @@
| Note: a match type could not be fully reduced:
|
| trying to reduce M[B]
| failed since selector B
| failed since selector B
| does not match case A => Int
| and cannot be shown to be disjoint from it either.
| Therefore, reduction cannot advance to the remaining case
Expand Down
4 changes: 2 additions & 2 deletions tests/neg/i13780.check
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
| Note: a match type could not be fully reduced:
|
| trying to reduce Head[X]
| failed since selector X
| failed since selector X
| does not uniquely determine parameters a, b in
| case (a, b) => a
| The computed bounds for the parameters are:
Expand All @@ -30,7 +30,7 @@
| Note: a match type could not be fully reduced:
|
| trying to reduce Head[X]
| failed since selector X
| failed since selector X
| does not uniquely determine parameters a, b in
| case (a, b) => a
| The computed bounds for the parameters are:
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i15618.check
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
| Note: a match type could not be fully reduced:
|
| trying to reduce ScalaType[T]
| failed since selector T
| failed since selector T
| does not match case Float16 => Float
| and cannot be shown to be disjoint from it either.
| Therefore, reduction cannot advance to the remaining cases
Expand Down
Loading

0 comments on commit c466fa0

Please sign in to comment.