Skip to content

Commit 7dabd1e

Browse files
committed
treat x* pattern arg as a Seq of the element type.
1 parent 5c51b7b commit 7dabd1e

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,12 @@ object SpaceEngine {
382382
project(pat)
383383

384384
case Typed(_, tpt) =>
385-
Typ(erase(tpt.tpe.stripAnnots, isValue = true, isTyped = true), decomposed = false)
385+
val tptTpe =
386+
if isWildcardStarArg(pat) then
387+
tpt.tpe.translateFromRepeated(toArray = false)
388+
else
389+
tpt.tpe
390+
Typ(erase(tptTpe.stripAnnots, isValue = true, isTyped = true), decomposed = false)
386391

387392
case This(_) =>
388393
Typ(pat.tpe.stripAnnots, decomposed = false)

tests/warn/i23459.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- [E092] Pattern Match Unchecked Warning: tests/warn/i23459.scala:7:14 ------------------------------------------------
2+
7 | case Test(x*) => println(x) // warn
3+
| ^
4+
|the type test for Seq[Int]* cannot be checked at runtime because its type arguments can't be determined from Seq[Int]
5+
|
6+
| longer explanation available when compiling with `-explain`

tests/warn/i23459.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
case class Test()
2+
object Test:
3+
def unapply(t: Test): Some[Seq[Int]] = Some(Seq(1, 2))
4+
5+
@main def run(): Unit =
6+
Test() match
7+
case Test(x*) => println(x) // warn
8+

0 commit comments

Comments
 (0)