diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 2a0cbbdbf006..446fd4780acd 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -382,7 +382,12 @@ object SpaceEngine { project(pat) case Typed(_, tpt) => - Typ(erase(tpt.tpe.stripAnnots, isValue = true, isTyped = true), decomposed = false) + val tptTpe = + if isWildcardStarArg(pat) then + tpt.tpe.translateFromRepeated(toArray = false) + else + tpt.tpe + Typ(erase(tptTpe.stripAnnots, isValue = true, isTyped = true), decomposed = false) case This(_) => Typ(pat.tpe.stripAnnots, decomposed = false) diff --git a/tests/warn/i23459.check b/tests/warn/i23459.check new file mode 100644 index 000000000000..bbe9bf5a4ec7 --- /dev/null +++ b/tests/warn/i23459.check @@ -0,0 +1,6 @@ +-- [E092] Pattern Match Unchecked Warning: tests/warn/i23459.scala:7:14 ------------------------------------------------ +7 | case Test(x*) => println(x) // warn + | ^ + |the type test for Seq[Int]* cannot be checked at runtime because its type arguments can't be determined from Seq[Int] + | + | longer explanation available when compiling with `-explain` diff --git a/tests/warn/i23459.scala b/tests/warn/i23459.scala new file mode 100644 index 000000000000..af6a01e2ebce --- /dev/null +++ b/tests/warn/i23459.scala @@ -0,0 +1,8 @@ +case class Test() +object Test: + def unapply(t: Test): Some[Seq[Int]] = Some(Seq(1, 2)) + +@main def run(): Unit = + Test() match + case Test(x*) => println(x) // warn + diff --git a/tests/warn/i23459b.check b/tests/warn/i23459b.check new file mode 100644 index 000000000000..cd82f2005906 --- /dev/null +++ b/tests/warn/i23459b.check @@ -0,0 +1,6 @@ +-- [E092] Pattern Match Unchecked Warning: tests/warn/i23459b.scala:7:14 ----------------------------------------------- +7 | case Test(_*) => () // warn + | ^ + |the type test for Seq[Int]* cannot be checked at runtime because its type arguments can't be determined from Seq[Int] + | + | longer explanation available when compiling with `-explain` diff --git a/tests/warn/i23459b.scala b/tests/warn/i23459b.scala new file mode 100644 index 000000000000..792afafe038e --- /dev/null +++ b/tests/warn/i23459b.scala @@ -0,0 +1,8 @@ +case class Test() +object Test: + def unapply(t: Test): Some[Seq[Int]] = Some(Seq(1, 2)) + +@main def run(): Unit = + Test() match + case Test(_*) => () // warn +