From 71f5b3aac74bcd8d45d0cac8afb816cc70fdcc62 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Tue, 28 Apr 2020 11:02:18 +0200 Subject: [PATCH] Fix #8757: check wildcard star patterns by tree instead of type --- .../src/dotty/tools/dotc/transform/patmat/Space.scala | 4 ++-- tests/patmat/i8757.check | 1 + tests/patmat/i8757.scala | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/patmat/i8757.check create mode 100644 tests/patmat/i8757.scala diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 776ebf076aa3..bc74d9542a61 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -481,8 +481,8 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { def projectSeq(pats: List[Tree]): Space = { if (pats.isEmpty) return Typ(scalaNilType, false) - val (items, zero) = if (pats.last.tpe.isRepeatedParam) - (pats.init, Typ(scalaListType.appliedTo(pats.last.tpe.argTypes.head), false)) + val (items, zero) = if (isWildcardStarArg(pats.last)) + (pats.init, Typ(scalaListType.appliedTo(pats.last.tpe.elemType), false)) else (pats, Typ(scalaNilType, false)) diff --git a/tests/patmat/i8757.check b/tests/patmat/i8757.check new file mode 100644 index 000000000000..a0606bf625c6 --- /dev/null +++ b/tests/patmat/i8757.check @@ -0,0 +1 @@ +8: Pattern Match Exhaustivity: C() diff --git a/tests/patmat/i8757.scala b/tests/patmat/i8757.scala new file mode 100644 index 000000000000..2056bfb74527 --- /dev/null +++ b/tests/patmat/i8757.scala @@ -0,0 +1,10 @@ +sealed trait T + +case class C(xs: Int*) extends T + +def f(): Unit = (C(42): T) match { case C(xs: _*) => } +def g(): Unit = (C(42): T) match { case C(_: _*) => } + +def h(): Unit = (C(42): T) match + case C(5, _: _*) => + case C(x, xs: _*) =>