Skip to content

Commit c373db7

Browse files
EnzeXingolhotak
authored andcommitted
fix error in product-sequence match
1 parent 35c2ef3 commit c373db7

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

compiler/src/dotty/tools/dotc/transform/init/Objects.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,6 +1804,9 @@ class Objects(using Context @constructorOnly):
18041804
val seqPats = pats.drop(selectors.length - 1)
18051805
val toSeqRes = call(resToMatch, selectors.last, Nil, resultTp, superType = NoType, needResolve = true)
18061806
val toSeqResTp = resultTp.memberInfo(selectors.last).finalResultType
1807+
elemTp = unapplySeqTypeElemTp(toSeqResTp)
1808+
// elemTp must conform to the signature in sequence match
1809+
assert(elemTp.exists, "Product sequence match fails on " + pat + " since last element type of product is " + toSeqResTp)
18071810
evalSeqPatterns(toSeqRes, toSeqResTp, elemTp, seqPats)
18081811
end if
18091812
// TODO: refactor the code of product sequence match, avoid passing NoType to parameter elemTp in evalSeqPatterns
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
trait Node {
2+
val prefix = 5
3+
val child = Array(3)
4+
}
5+
6+
class SpecialNode extends Node
7+
8+
class Group extends Node
9+
10+
class C extends Node
11+
12+
object Elem {
13+
def apply(prefix: Int, children: Int*) = new C
14+
def unapplySeq(n: Node) = n match {
15+
case _: SpecialNode | _: Group => None
16+
case _ => Some((n.prefix, n.child.toSeq))
17+
}
18+
}
19+
20+
object O {
21+
def updateNode(node: Node): Node =
22+
node match {
23+
case Elem(prefix, children @ _*) =>
24+
Elem(prefix, children*)
25+
case other => other
26+
}
27+
28+
val a = updateNode(new Group)
29+
}

0 commit comments

Comments
 (0)