From 49af9cfb6cdf0714cf6fddc1d240a30ba3666145 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Wed, 14 Dec 2022 22:48:18 +0100 Subject: [PATCH] Fix typo leading to incorrect unreachable case warning --- compiler/src/dotty/tools/dotc/transform/patmat/Space.scala | 2 +- tests/patmat/isSubspace-Typ-Prod.scala | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/patmat/isSubspace-Typ-Prod.scala diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 8e891f822255..c15eb413e083 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -187,7 +187,7 @@ trait SpaceLogic { case (Typ(tp1, _), Prod(tp2, fun, ss)) => isSubType(tp1, tp2) && covers(fun, tp1, ss.length) - && isSubspace(Prod(tp2, fun, signature(fun, tp2, ss.length).map(Typ(_, false))), b) + && isSubspace(Prod(tp2, fun, signature(fun, tp1, ss.length).map(Typ(_, false))), b) case (Prod(_, fun1, ss1), Prod(_, fun2, ss2)) => isSameUnapply(fun1, fun2) && ss1.zip(ss2).forall((isSubspace _).tupled) } diff --git a/tests/patmat/isSubspace-Typ-Prod.scala b/tests/patmat/isSubspace-Typ-Prod.scala new file mode 100644 index 000000000000..df17c99d67be --- /dev/null +++ b/tests/patmat/isSubspace-Typ-Prod.scala @@ -0,0 +1,7 @@ +case class Foo[T](x: T) +class Bar extends Foo[String]("") + +def test(x: Any) = x match + case Foo(1) => + case _: Bar => // used to warn about unreachable case + // case _: Foo[_] => // still warns, something else is wrong