diff --git a/compiler/src/dotty/tools/dotc/reporting/Message.scala b/compiler/src/dotty/tools/dotc/reporting/Message.scala index 1ac5c6ecf407..1481ce685c1f 100644 --- a/compiler/src/dotty/tools/dotc/reporting/Message.scala +++ b/compiler/src/dotty/tools/dotc/reporting/Message.scala @@ -405,7 +405,7 @@ abstract class Message(val errorId: ErrorMessageID)(using Context) { self => override def canExplain = true /** Override with `true` for messages that should always be shown even if their - * position overlaps another message of a different class. On the other hand + * position overlaps another messsage of a different class. On the other hand * multiple messages of the same class with overlapping positions will lead * to only a single message of that class to be issued. */ diff --git a/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala b/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala index 082c239c6443..c2f8b98d0236 100644 --- a/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala +++ b/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala @@ -74,7 +74,7 @@ object TypeTestsCasts { }.apply(tp) /** Returns true if the type arguments of `P` can be determined from `X` */ - def typeArgsDeterminable(X: Type, P: AppliedType)(using Context) = inContext(ctx.fresh.setExploreTyperState().setFreshGADTBounds) { + def typeArgsTrivial(X: Type, P: AppliedType)(using Context) = inContext(ctx.fresh.setExploreTyperState().setFreshGADTBounds) { val AppliedType(tycon, _) = P def underlyingLambda(tp: Type): TypeLambda = tp.ensureLambdaSub match { @@ -161,7 +161,7 @@ object TypeTestsCasts { val tparams = x.typeParams if tparams.isEmpty then x else x.appliedTo(tparams.map(_ => WildcardType)) TypeComparer.provablyDisjoint(xApplied, tpe.derivedAppliedType(tycon, targs.map(_ => WildcardType))) - || typeArgsDeterminable(X, tpe) + || typeArgsTrivial(X, tpe) ||| i"its type arguments can't be determined from $X" } case AndType(tp1, tp2) => recur(X, tp1) && recur(X, tp2) diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 97816bd71b84..bb1160d501a1 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -370,7 +370,7 @@ object SpaceEngine { project(pat) case Typed(_, tpt) => - Typ(erase(tpt.tpe.stripAnnots, isValue = true, isTyped = true), decomposed = false) + Typ(erase(tpt.tpe.stripAnnots, isValue = true), decomposed = false) case This(_) => Typ(pat.tpe.stripAnnots, decomposed = false) @@ -455,13 +455,13 @@ object SpaceEngine { tp.derivedAppliedType(erase(tycon, inArray, isValue = false), args2) case tp @ OrType(tp1, tp2) => - OrType(erase(tp1, inArray, isValue, isTyped), erase(tp2, inArray, isValue, isTyped), tp.isSoft) + OrType(erase(tp1, inArray, isValue), erase(tp2, inArray, isValue), tp.isSoft) case AndType(tp1, tp2) => - AndType(erase(tp1, inArray, isValue, isTyped), erase(tp2, inArray, isValue, isTyped)) + AndType(erase(tp1, inArray, isValue), erase(tp2, inArray, isValue)) case tp @ RefinedType(parent, _, _) => - erase(parent, inArray, isValue, isTyped) + erase(parent, inArray, isValue) case tref: TypeRef if tref.symbol.isPatternBound => if inArray then erase(tref.underlying, inArray, isValue, isTyped) diff --git a/tests/pending/neg/i16451.check b/tests/pending/neg/i16451.check new file mode 100644 index 000000000000..acd44ca97478 --- /dev/null +++ b/tests/pending/neg/i16451.check @@ -0,0 +1,24 @@ +-- Error: tests/neg/i16451.scala:13:9 ---------------------------------------------------------------------------------- +13 | case x: Wrapper[Color.Red.type] => Some(x) // error + | ^ + |the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color] +-- Error: tests/neg/i16451.scala:21:9 ---------------------------------------------------------------------------------- +21 | case x: Wrapper[Color.Red.type] => Some(x) // error + | ^ + |the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Any +-- Error: tests/neg/i16451.scala:25:9 ---------------------------------------------------------------------------------- +25 | case x: Wrapper[Color.Red.type] => Some(x) // error + | ^ + |the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color] +-- Error: tests/neg/i16451.scala:29:9 ---------------------------------------------------------------------------------- +29 | case x: Wrapper[Color.Red.type] => Some(x) // error + | ^ + |the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from A1 +-- Error: tests/neg/i16451.scala:34:11 --------------------------------------------------------------------------------- +34 | case x: Wrapper[Color.Red.type] => x // error + | ^ + |the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color] +-- Error: tests/neg/i16451.scala:39:11 --------------------------------------------------------------------------------- +39 | case x: Wrapper[Color.Red.type] => x // error + | ^ + |the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color] \ No newline at end of file diff --git a/tests/warn/i16451.scala b/tests/pending/neg/i16451.scala similarity index 58% rename from tests/warn/i16451.scala rename to tests/pending/neg/i16451.scala index 138af3632772..3a93a97e1f03 100644 --- a/tests/warn/i16451.scala +++ b/tests/pending/neg/i16451.scala @@ -1,42 +1,38 @@ -// +//> using options -Werror enum Color: case Red, Green -//sealed trait Color -//object Color: -// case object Red extends Color -// case object Green extends Color case class Wrapper[A](value: A) object Test: def test_correct(x: Wrapper[Color]): Option[Wrapper[Color.Red.type]] = x match - case x: Wrapper[Color.Red.type] => Some(x) // warn: unchecked - case x: Wrapper[Color.Green.type] => None // warn: unreachable // also: unchecked (hidden) + case x: Wrapper[Color.Red.type] => Some(x) // error + case null => None def test_different(x: Wrapper[Color]): Option[Wrapper[Color]] = x match case x @ Wrapper(_: Color.Red.type) => Some(x) case x @ Wrapper(_: Color.Green.type) => None def test_any(x: Any): Option[Wrapper[Color.Red.type]] = x match - case x: Wrapper[Color.Red.type] => Some(x) // warn: unchecked - case x: Wrapper[Color.Green.type] => None // warn: unreachable // also: unchecked (hidden) + case x: Wrapper[Color.Red.type] => Some(x) // error + case _ => None def test_wrong(x: Wrapper[Color]): Option[Wrapper[Color.Red.type]] = x match - case x: Wrapper[Color.Red.type] => Some(x) // warn: unchecked + case x: Wrapper[Color.Red.type] => Some(x) // error case null => None def t2[A1 <: Wrapper[Color]](x: A1): Option[Wrapper[Color.Red.type]] = x match - case x: Wrapper[Color.Red.type] => Some(x) // warn: unchecked + case x: Wrapper[Color.Red.type] => Some(x) // error case null => None def test_wrong_seq(xs: Seq[Wrapper[Color]]): Seq[Wrapper[Color.Red.type]] = xs.collect { - case x: Wrapper[Color.Red.type] => x // warn: unchecked + case x: Wrapper[Color.Red.type] => x // error } def test_wrong_seq2(xs: Seq[Wrapper[Color]]): Seq[Wrapper[Color.Red.type]] = xs.collect { x => x match - case x: Wrapper[Color.Red.type] => x // warn: unchecked + case x: Wrapper[Color.Red.type] => x // error } def main(args: Array[String]): Unit = diff --git a/tests/warn/enum-approx2.check b/tests/warn/enum-approx2.check deleted file mode 100644 index a75c15b424ff..000000000000 --- a/tests/warn/enum-approx2.check +++ /dev/null @@ -1,14 +0,0 @@ --- [E030] Match case Unreachable Warning: tests/warn/enum-approx2.scala:7:12 ------------------------------------------- -7 | case Fun(x: Exp[Int => String]) => ??? // warn: unreachable // also: unchecked (hidden) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | Unreachable case --- [E121] Pattern Match Warning: tests/warn/enum-approx2.scala:8:9 ----------------------------------------------------- -8 | case _ => // warn: unreachable-only-null - | ^ - | Unreachable case except for null (if this is intentional, consider writing case null => instead). --- [E092] Pattern Match Unchecked Warning: tests/warn/enum-approx2.scala:6:13 ------------------------------------------ -6 | case Fun(x: Fun[Int, Double]) => ??? // warn: unchecked - | ^ - |the type test for Fun[Int, Double] cannot be checked at runtime because its type arguments can't be determined from Exp[Int => Int] - | - | longer explanation available when compiling with `-explain` diff --git a/tests/warn/enum-approx2.scala b/tests/warn/enum-approx2.scala deleted file mode 100644 index 38a78cd6a5e9..000000000000 --- a/tests/warn/enum-approx2.scala +++ /dev/null @@ -1,10 +0,0 @@ -sealed trait Exp[T] -case class Fun[A, B](f: Exp[A => B]) extends Exp[A => B] - -class Test { - def eval(e: Fun[Int, Int]) = e match { - case Fun(x: Fun[Int, Double]) => ??? // warn: unchecked - case Fun(x: Exp[Int => String]) => ??? // warn: unreachable // also: unchecked (hidden) - case _ => // warn: unreachable-only-null - } -} diff --git a/tests/warn/i11178.scala b/tests/warn/i11178.scala index a59b899be365..7544e21a3791 100644 --- a/tests/warn/i11178.scala +++ b/tests/warn/i11178.scala @@ -12,6 +12,7 @@ object Test1 { def test[A](bar: Bar[A]) = bar match { case _: Bar[Boolean] => ??? // warn + case _ => ??? } } @@ -22,6 +23,7 @@ object Test2 { def test[A](bar: Bar[A]) = bar match { case _: Bar[Boolean] => ??? // warn + case _ => ??? } } @@ -32,5 +34,6 @@ object Test3 { def test[A](bar: Bar[A]) = bar match { case _: Bar[Boolean] => ??? // warn + case _ => ??? } } diff --git a/tests/warn/i16451.check b/tests/warn/i16451.check deleted file mode 100644 index 09c2a7df8179..000000000000 --- a/tests/warn/i16451.check +++ /dev/null @@ -1,44 +0,0 @@ --- [E030] Match case Unreachable Warning: tests/warn/i16451.scala:14:9 ------------------------------------------------- -14 | case x: Wrapper[Color.Green.type] => None // warn: unreachable // also: unchecked (hidden) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | Unreachable case --- [E030] Match case Unreachable Warning: tests/warn/i16451.scala:22:9 ------------------------------------------------- -22 | case x: Wrapper[Color.Green.type] => None // warn: unreachable // also: unchecked (hidden) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | Unreachable case --- [E092] Pattern Match Unchecked Warning: tests/warn/i16451.scala:13:9 ------------------------------------------------ -13 | case x: Wrapper[Color.Red.type] => Some(x) // warn: unchecked - | ^ - |the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color] - | - | longer explanation available when compiling with `-explain` --- [E092] Pattern Match Unchecked Warning: tests/warn/i16451.scala:21:9 ------------------------------------------------ -21 | case x: Wrapper[Color.Red.type] => Some(x) // warn: unchecked - | ^ - |the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Any - | - | longer explanation available when compiling with `-explain` --- [E092] Pattern Match Unchecked Warning: tests/warn/i16451.scala:25:9 ------------------------------------------------ -25 | case x: Wrapper[Color.Red.type] => Some(x) // warn: unchecked - | ^ - |the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color] - | - | longer explanation available when compiling with `-explain` --- [E092] Pattern Match Unchecked Warning: tests/warn/i16451.scala:29:9 ------------------------------------------------ -29 | case x: Wrapper[Color.Red.type] => Some(x) // warn: unchecked - | ^ - |the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from A1 - | - | longer explanation available when compiling with `-explain` --- [E092] Pattern Match Unchecked Warning: tests/warn/i16451.scala:34:11 ----------------------------------------------- -34 | case x: Wrapper[Color.Red.type] => x // warn: unchecked - | ^ - |the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color] - | - | longer explanation available when compiling with `-explain` --- [E092] Pattern Match Unchecked Warning: tests/warn/i16451.scala:39:11 ----------------------------------------------- -39 | case x: Wrapper[Color.Red.type] => x // warn: unchecked - | ^ - |the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color] - | - | longer explanation available when compiling with `-explain` diff --git a/tests/warn/i5826.check b/tests/warn/i5826.check index 18ff50a933cb..b108aef8010a 100644 --- a/tests/warn/i5826.check +++ b/tests/warn/i5826.check @@ -10,20 +10,20 @@ |the type test for List[Int] cannot be checked at runtime because its type arguments can't be determined from List[String] | | longer explanation available when compiling with `-explain` --- [E092] Pattern Match Unchecked Warning: tests/warn/i5826.scala:16:9 ------------------------------------------------- -16 | case ls: A[X] => 4 // warn +-- [E092] Pattern Match Unchecked Warning: tests/warn/i5826.scala:17:9 ------------------------------------------------- +17 | case ls: A[X] => 4 // warn | ^ |the type test for Foo.this.A[X] cannot be checked at runtime because its type arguments can't be determined from Foo.this.B[X] | | longer explanation available when compiling with `-explain` --- [E092] Pattern Match Unchecked Warning: tests/warn/i5826.scala:21:9 ------------------------------------------------- -21 | case ls: List[Int] => ls.head // warn, List extends Int => T +-- [E092] Pattern Match Unchecked Warning: tests/warn/i5826.scala:22:9 ------------------------------------------------- +22 | case ls: List[Int] => ls.head // warn, List extends Int => T | ^ |the type test for List[Int] cannot be checked at runtime because its type arguments can't be determined from A => Int | | longer explanation available when compiling with `-explain` --- [E092] Pattern Match Unchecked Warning: tests/warn/i5826.scala:27:54 ------------------------------------------------ -27 | def test5[T](x: A[T] | B[T] | Option[T]): Boolean = x.isInstanceOf[C[String]] // warn +-- [E092] Pattern Match Unchecked Warning: tests/warn/i5826.scala:28:54 ------------------------------------------------ +28 | def test5[T](x: A[T] | B[T] | Option[T]): Boolean = x.isInstanceOf[C[String]] // warn | ^ |the type test for Foo.this.C[String] cannot be checked at runtime because its type arguments can't be determined from Foo.this.A[T] | diff --git a/tests/warn/i5826.scala b/tests/warn/i5826.scala index f54d6e58d033..69c157f89c27 100644 --- a/tests/warn/i5826.scala +++ b/tests/warn/i5826.scala @@ -6,6 +6,7 @@ class Foo { def test2: List[Int] | List[String] => Int = { case ls: List[Int] => ls.head // warn: unchecked + case _ => 0 } trait A[T] diff --git a/tests/warn/i8932.scala b/tests/warn/i8932.scala index 95a4e86e9791..c52d2659614d 100644 --- a/tests/warn/i8932.scala +++ b/tests/warn/i8932.scala @@ -6,7 +6,7 @@ class Dummy extends Bar[Nothing] with Foo[String] def bugReport[A](foo: Foo[A]): Foo[A] = foo match { case bar: Bar[A] => bar // warn: unchecked - case dummy: Dummy => ??? // warn: unreachable + case dummy: Dummy => ??? } def test = bugReport(new Dummy: Foo[String]) diff --git a/tests/warn/suppressed-type-test-warnings.scala b/tests/warn/suppressed-type-test-warnings.scala index c78e8e263153..99fef5e97fac 100644 --- a/tests/warn/suppressed-type-test-warnings.scala +++ b/tests/warn/suppressed-type-test-warnings.scala @@ -1,11 +1,9 @@ object Test { sealed trait Foo[A, B] final case class Bar[X](x: X) extends Foo[X, X] - def foo[A, B](value: Foo[A, B], a: A => Int): B = value match { case Bar(x) => a(x); x } - def bar[A, B](value: Foo[A, B], a: A => Int): B = value match { case b: Bar[a] => b.x } @@ -18,10 +16,12 @@ object Test { def err2[A, B](value: Foo[A, B], a: A => Int): B = value match { case b: Bar[B] => // spurious // warn b.x + case _ => ??? // avoid fatal inexhaustivity warnings suppressing the uncheckable warning } def fail[A, B](value: Foo[A, B], a: A => Int): B = value match { case b: Bar[Int] => // warn b.x + case _ => ??? // avoid fatal inexhaustivity warnings suppressing the uncheckable warning } -} +} \ No newline at end of file