Skip to content

Commit c03317e

Browse files
committed
Fix #167
Can handle now vararg arguments in patterns.
1 parent 0c97f08 commit c03317e

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ object desugar {
860860
case tree @ Bind(_, tree1) =>
861861
add(tree, TypeTree())
862862
collect(tree1)
863-
case Typed(id: Ident, t) if isVarPattern(id) && id.name != nme.WILDCARD =>
863+
case Typed(id: Ident, t) if isVarPattern(id) && id.name != nme.WILDCARD && !isWildcardStarArg(tree) =>
864864
add(id, t)
865865
case id: Ident if isVarPattern(id) && id.name != nme.WILDCARD =>
866866
add(id, TypeTree())

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
325325

326326
def typedTyped(tree: untpd.Typed, pt: Type)(implicit ctx: Context): Tree = track("typedTyped") {
327327
def regularTyped(isWildcard: Boolean) = {
328-
val tpt1 = typedType(tree.tpt)
328+
val tpt1 =
329+
if (untpd.isWildcardStarArg(tree))
330+
TypeTree(defn.SeqClass.typeRef.appliedTo(pt :: Nil))
331+
else
332+
typedType(tree.tpt)
329333
val expr1 =
330334
if (isWildcard) tree.expr withType tpt1.tpe
331335
else typed(tree.expr, tpt1.tpe)
@@ -336,7 +340,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
336340
if (id.name == nme.WILDCARD) regularTyped(isWildcard = true)
337341
else {
338342
import untpd._
339-
typed(Bind(id.name, Typed(Ident(nme.WILDCARD), tree.tpt)).withPos(id.pos))
343+
typed(Bind(id.name, Typed(Ident(nme.WILDCARD), tree.tpt)).withPos(id.pos), pt)
340344
}
341345
case _ =>
342346
if (untpd.isWildcardStarArg(tree))

tests/pos/vararg-pattern.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
object Test {
2+
3+
List(1, 2, 3, 4) match {
4+
case List(1, 2, xs: _*) =>
5+
val ys: Seq[Int] = xs
6+
println(ys)
7+
}
8+
val List(1, 2, x: _*) = List(1, 2, 3, 4)
9+
10+
}
11+
12+

0 commit comments

Comments
 (0)