diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala index c3d0f9c3a8a3..3d71118c6988 100644 --- a/src/dotty/tools/dotc/ast/Desugar.scala +++ b/src/dotty/tools/dotc/ast/Desugar.scala @@ -860,7 +860,7 @@ object desugar { case tree @ Bind(_, tree1) => add(tree, TypeTree()) collect(tree1) - case Typed(id: Ident, t) if isVarPattern(id) && id.name != nme.WILDCARD => + case Typed(id: Ident, t) if isVarPattern(id) && id.name != nme.WILDCARD && !isWildcardStarArg(tree) => add(id, t) case id: Ident if isVarPattern(id) && id.name != nme.WILDCARD => add(id, TypeTree()) diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index d5153bf1384d..5fdbc89a673e 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -325,7 +325,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit def typedTyped(tree: untpd.Typed, pt: Type)(implicit ctx: Context): Tree = track("typedTyped") { def regularTyped(isWildcard: Boolean) = { - val tpt1 = typedType(tree.tpt) + val tpt1 = + if (untpd.isWildcardStarArg(tree)) + TypeTree(defn.SeqClass.typeRef.appliedTo(pt :: Nil)) + else + typedType(tree.tpt) val expr1 = if (isWildcard) tree.expr withType tpt1.tpe else typed(tree.expr, tpt1.tpe) @@ -336,7 +340,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit if (id.name == nme.WILDCARD) regularTyped(isWildcard = true) else { import untpd._ - typed(Bind(id.name, Typed(Ident(nme.WILDCARD), tree.tpt)).withPos(id.pos)) + typed(Bind(id.name, Typed(Ident(nme.WILDCARD), tree.tpt)).withPos(id.pos), pt) } case _ => if (untpd.isWildcardStarArg(tree)) diff --git a/tests/pos/vararg-pattern.scala b/tests/pos/vararg-pattern.scala new file mode 100644 index 000000000000..314d6460f840 --- /dev/null +++ b/tests/pos/vararg-pattern.scala @@ -0,0 +1,12 @@ +object Test { + + List(1, 2, 3, 4) match { + case List(1, 2, xs: _*) => + val ys: Seq[Int] = xs + println(ys) + } + val List(1, 2, x: _*) = List(1, 2, 3, 4) + +} + +