Skip to content

Commit cc63c9e

Browse files
committed
handle SeqLiteral in patterns
1 parent 4025987 commit cc63c9e

File tree

5 files changed

+10
-3
lines changed

5 files changed

+10
-3
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ class Definitions {
7777
val cls = denot.asClass.classSymbol
7878
val paramDecls = newScope
7979
val typeParam = enterSyntheticTypeParam(cls, paramFlags, paramDecls)
80-
val parents = parentConstrs.toList
80+
def instantiate(tpe: Type) =
81+
if (tpe.typeParams.nonEmpty) tpe.appliedTo(typeParam.typeRef)
82+
else tpe
83+
val parents = parentConstrs.toList map instantiate
8184
denot.info = ClassInfo(ScalaPackageClass.thisType, cls, parents, paramDecls)
8285
}
8386
}

compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ object PatternMatcher {
351351
}
352352
case WildcardPattern() =>
353353
onSuccess
354+
case SeqLiteral(pats, _) =>
355+
matchElemsPlan(scrutinee, pats, exact = true, onSuccess)
354356
case _ =>
355357
TestPlan(EqualTest(tree), scrutinee, tree.pos, onSuccess, onFailure)
356358
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
395395
Typ(pat.tpe.stripAnnots, false)
396396
case Alternative(trees) => Or(trees.map(project(_)))
397397
case Bind(_, pat) => project(pat)
398+
case SeqLiteral(pats, _) => projectSeq(pats)
398399
case UnApply(fun, _, pats) =>
399400
if (fun.symbol.name == nme.unapplySeq)
400401
if (fun.symbol.owner == scalaSeqFactoryClass)
@@ -496,7 +497,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
496497

497498
debug.println(s"signature of ${unappSym.showFullName} ----> ${sig.map(_.show).mkString(", ")}")
498499

499-
sig
500+
sig.map(_.annotatedToRepeated)
500501
}
501502

502503
/** Decompose a type into subspaces -- assume the type can be decomposed */

tests/patmat/t8178.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ case class FailsChild2(a: Seq[String]) extends Fails
44
object FailsTest {
55
def matchOnVarArgsFirstFails(f: Fails) = {
66
f match {
7-
case VarArgs1(_) => ???
7+
case VarArgs1(_: _*) => ???
88
// BUG: Without this line we should get a non-exhaustive match compiler error.
99
//case FailsChild2(_) => ???
1010
}

tests/run/i3248.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ object Test extends App {
1313

1414
def bar(f: Any) = f match {
1515
case Bar(1, 2, 3) => 0
16+
case Bar(a, b) => a + b
1617
case Bar(ns: _*) => ns.length
1718
}
1819

0 commit comments

Comments
 (0)