Skip to content

Commit ce8e0f9

Browse files
committed
add test case and all green
1 parent fdf420a commit ce8e0f9

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,10 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
393393
case Bind(_, pat) => project(pat)
394394
case UnApply(fun, _, pats) =>
395395
if (fun.symbol.name == nme.unapplySeq)
396-
projectSeq(pats)
396+
if (fun.symbol.owner == scalaSeqFactoryClass)
397+
projectSeq(pats)
398+
else
399+
Prod(pat.tpe.stripAnnots, fun.tpe.widen, fun.symbol, projectSeq(pats) :: Nil, irrefutable(fun))
397400
else
398401
Prod(pat.tpe.stripAnnots, fun.tpe.widen, fun.symbol, pats.map(project), irrefutable(fun))
399402
case Typed(pat @ UnApply(_, _, _), _) => project(pat)
@@ -484,7 +487,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
484487
.map(_.info.asSeenFrom(mt.resultType, mt.resultType.classSymbol).widen)
485488
}
486489
else {
487-
val resTp = mt.resultType.select(nme.get).resultType
490+
val resTp = mt.resultType.select(nme.get).resultType.widen
488491
if (isUnapplySeq) scalaListType.appliedTo(resTp.argTypes.head) :: Nil
489492
else if (argLen == 0) Nil
490493
else productSelectors(resTp).map(_.info.asSeenFrom(resTp, resTp.classSymbol).widen)

tests/patmat/i3004.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
object O {
2+
sealed trait Fruit
3+
object Apple extends Fruit
4+
object Banana extends Fruit
5+
sealed class C(f1: Fruit, f2: Fruit)
6+
7+
object C {
8+
def unapply(c: C): Some[Banana.type] = Some(Banana)
9+
}
10+
11+
def m(c: C) = c match { case C(b) => b }
12+
}

tests/patmat/t9232.check

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
13: Pattern Match Exhaustivity: Node2(), Node1(Foo(_))
1+
13: Pattern Match Exhaustivity: Node2()
2+
17: Pattern Match Exhaustivity: Node2(), Node1(Foo(Nil)), Node1(Foo(List(_, _*)))

tests/patmat/t9232.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ case class Node2() extends Tree
1111

1212
object Test {
1313
def transformTree(tree: Tree): Any = tree match {
14-
case Node1(Foo(1)) => ???
14+
case Node1(Foo(_: _*)) => ???
15+
}
16+
17+
def transformTree2(tree: Tree): Any = tree match {
18+
case Node1(Foo(1, _: _*)) => ???
1519
}
1620
}

0 commit comments

Comments
 (0)