diff --git a/compiler/src/dotty/tools/dotc/core/MatchTypeTrace.scala b/compiler/src/dotty/tools/dotc/core/MatchTypeTrace.scala index 062ddd5e846c..60ebc95e7bed 100644 --- a/compiler/src/dotty/tools/dotc/core/MatchTypeTrace.scala +++ b/compiler/src/dotty/tools/dotc/core/MatchTypeTrace.scala @@ -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 @@ -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)}""" diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index f097bd160fdd..9dda18c72f26 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -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) } } diff --git a/tests/neg/6570-1.check b/tests/neg/6570-1.check index fa53e71cbb6b..bdbadd0f752a 100644 --- a/tests/neg/6570-1.check +++ b/tests/neg/6570-1.check @@ -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` @@ -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: diff --git a/tests/neg/6571.check b/tests/neg/6571.check index 42997407765f..4172abb2919b 100644 --- a/tests/neg/6571.check +++ b/tests/neg/6571.check @@ -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` @@ -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` diff --git a/tests/neg/i11982a.check b/tests/neg/i11982a.check index bc07c82059cc..1977aa30e8b5 100644 --- a/tests/neg/i11982a.check +++ b/tests/neg/i11982a.check @@ -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: @@ -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: @@ -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: diff --git a/tests/neg/i12049.check b/tests/neg/i12049.check index a58624ec6778..11c648e35a57 100644 --- a/tests/neg/i12049.check +++ b/tests/neg/i12049.check @@ -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 @@ -18,7 +18,7 @@ -- 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] @@ -26,7 +26,7 @@ -- 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)] @@ -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 @@ -48,7 +48,7 @@ -- 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] @@ -56,7 +56,7 @@ -- 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)] @@ -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 diff --git a/tests/neg/i13780.check b/tests/neg/i13780.check index 56b6a67ac8e7..aa0a47db5737 100644 --- a/tests/neg/i13780.check +++ b/tests/neg/i13780.check @@ -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: @@ -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: diff --git a/tests/neg/i15618.check b/tests/neg/i15618.check index 16fadcd9b886..099e3fe0a0b7 100644 --- a/tests/neg/i15618.check +++ b/tests/neg/i15618.check @@ -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 diff --git a/tests/neg/matchtype-seq.check b/tests/neg/matchtype-seq.check index aba1e312da01..9c37fc08c4df 100644 --- a/tests/neg/matchtype-seq.check +++ b/tests/neg/matchtype-seq.check @@ -1,7 +1,7 @@ -- Error: tests/neg/matchtype-seq.scala:9:11 --------------------------------------------------------------------------- 9 | identity[T1[3]]("") // error | ^ - | Match type reduction failed since selector (3 : Int) + | Match type reduction failed since selector (3 : Int) | matches none of the cases | | case (1 : Int) => Int @@ -9,7 +9,7 @@ -- Error: tests/neg/matchtype-seq.scala:10:11 -------------------------------------------------------------------------- 10 | identity[T1[3]](1) // error | ^ - | Match type reduction failed since selector (3 : Int) + | Match type reduction failed since selector (3 : Int) | matches none of the cases | | case (1 : Int) => Int @@ -23,7 +23,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.T1[Int] - | failed since selector Int + | failed since selector Int | does not match case (1 : Int) => Int | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -40,7 +40,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.T1[Int] - | failed since selector Int + | failed since selector Int | does not match case (1 : Int) => Int | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -57,7 +57,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.T2[Int] - | failed since selector Int + | failed since selector Int | does not match case (1 : Int) => Int | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -81,7 +81,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.T2[Int] - | failed since selector Int + | failed since selector Int | does not match case (1 : Int) => Int | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -98,7 +98,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.T3[Test.A] - | failed since selector Test.A + | failed since selector Test.A | does not match case Test.B => Int | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -115,7 +115,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.T3[Test.A] - | failed since selector Test.A + | failed since selector Test.A | does not match case Test.B => Int | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -132,7 +132,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.T5[Test.A] - | failed since selector Test.A + | failed since selector Test.A | does not match case Test.C => String | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -149,7 +149,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.T5[Test.A] - | failed since selector Test.A + | failed since selector Test.A | does not match case Test.C => String | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -166,7 +166,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.T7[Test.D] - | failed since selector Test.D + | failed since selector Test.D | does not match case Test.A2 => Int | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -183,7 +183,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.T7[Test.D] - | failed since selector Test.D + | failed since selector Test.D | does not match case Test.A2 => Int | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -200,7 +200,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.T8[Test.E2] - | failed since selector Test.E2 + | failed since selector Test.E2 | does not match case Test.E1 => Int | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -224,7 +224,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.T8[Test.E2] - | failed since selector Test.E2 + | failed since selector Test.E2 | does not match case Test.E1 => Int | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -241,7 +241,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.T9[(Nothing, String)] - | failed since selector (Nothing, String) + | failed since selector (Nothing, String) | is uninhabited (there are no values of that type). | | longer explanation available when compiling with `-explain` @@ -254,7 +254,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.T9[(String, Nothing)] - | failed since selector (String, Nothing) + | failed since selector (String, Nothing) | is uninhabited (there are no values of that type). | | longer explanation available when compiling with `-explain` @@ -267,7 +267,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.T9[(Int, Nothing)] - | failed since selector (Int, Nothing) + | failed since selector (Int, Nothing) | is uninhabited (there are no values of that type). | | longer explanation available when compiling with `-explain` @@ -280,7 +280,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.T9[(Nothing, Int)] - | failed since selector (Nothing, Int) + | failed since selector (Nothing, Int) | is uninhabited (there are no values of that type). | | longer explanation available when compiling with `-explain` @@ -293,7 +293,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.T9[(?, ?)] - | failed since selector (?, ?) + | failed since selector (?, ?) | does not match case (Int, String) => Int | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -310,7 +310,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.T9[(?, ?)] - | failed since selector (?, ?) + | failed since selector (?, ?) | does not match case (Int, String) => Int | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -327,7 +327,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.T9[(Any, Any)] - | failed since selector (Any, Any) + | failed since selector (Any, Any) | does not match case (Int, String) => Int | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -344,7 +344,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.T9[(Any, Any)] - | failed since selector (Any, Any) + | failed since selector (Any, Any) | does not match case (Int, String) => Int | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -361,7 +361,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.TA[Test.Box2[Int, Int, String]] - | failed since selector Test.Box2[Int, Int, String] + | failed since selector Test.Box2[Int, Int, String] | does not match case Test.Box2[Int, Int, Int] => Int | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -378,7 +378,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.TA[Test.Box2[Int, Int, String]] - | failed since selector Test.Box2[Int, Int, String] + | failed since selector Test.Box2[Int, Int, String] | does not match case Test.Box2[Int, Int, Int] => Int | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -395,7 +395,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test.TD[Test.Box2_C[Int, Int, String]] - | failed since selector Test.Box2_C[Int, Int, String] + | failed since selector Test.Box2_C[Int, Int, String] | does not match case Test.Box2_C[Int, Int, Int] => Int | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -412,7 +412,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test2.M[Some[A]] - | failed since selector Some[A] + | failed since selector Some[A] | does not match case Option[Int] => String | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -429,7 +429,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test2.M[Some[A]] - | failed since selector Some[A] + | failed since selector Some[A] | does not match case Option[Int] => String | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -446,7 +446,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test3.M[Test3.Inv[A]] - | failed since selector Test3.Inv[A] + | failed since selector Test3.Inv[A] | does not match case Test3.Inv[Int] => String | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case @@ -463,7 +463,7 @@ | Note: a match type could not be fully reduced: | | trying to reduce Test4.M[Test4.Inv[Foo.this.A]] - | failed since selector Test4.Inv[Foo.this.A] + | failed since selector Test4.Inv[Foo.this.A] | does not match case Test4.Inv[Int] => String | and cannot be shown to be disjoint from it either. | Therefore, reduction cannot advance to the remaining case diff --git a/tests/pos/i16869.scala b/tests/pos/i16869.scala new file mode 100644 index 000000000000..4067e34ac8ef --- /dev/null +++ b/tests/pos/i16869.scala @@ -0,0 +1,13 @@ +class C[T] + +type Foo[T] = T match + case C[true] => true + case C[false] => false + +class W[T] extends C[Foo[T]] + +def f[T <: C[?]](t: T) = W[T]() + +def test = + val b = C[true]() + f(b): C[true]