Skip to content

Commit 08c90e9

Browse files
Merge pull request #4485 from dotty-staging/fix-#4449
Fix #4449: PatternMatcher needs to split call nodes if arguments differ
2 parents eb4d2c8 + 41bf78d commit 08c90e9

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,13 +698,15 @@ object PatternMatcher {
698698
for ((rhs, _) <- seenVars if !seenAtLabel(plan.label).contains(rhs))
699699
yield (rhs, newVar(rhs.tree, Param))
700700
}
701-
plan.args =
701+
val newArgs =
702702
for {
703703
(rhs, actual) <- seenVars.toList
704704
formal <- paramsOfLabel(plan.label).get(rhs)
705705
}
706706
yield (formal -> actual)
707-
plan
707+
if (plan.args.isEmpty) { plan.args = newArgs; plan }
708+
else if (newArgs == plan.args) plan
709+
else CallPlan(plan.label, newArgs)
708710
}
709711
}
710712
(new Merge(Map()))(plan)

tests/pos/i4449.scala

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
class TreeAccumulator2 {
2+
3+
def foo(tasty: Tasty2)(tree: Any): Unit = {
4+
import tasty._
5+
tree match {
6+
case A() =>
7+
case B() =>
8+
case C() =>
9+
case D() =>
10+
}
11+
}
12+
13+
}
14+
15+
abstract class Tasty2 {
16+
17+
type X
18+
type Y
19+
20+
implicit def xct: scala.reflect.ClassTag[X]
21+
implicit def yct: scala.reflect.ClassTag[Y]
22+
23+
val A: AExtractor
24+
trait AExtractor {
25+
def unapply(x: X): Boolean
26+
}
27+
28+
val B: BExtractor
29+
trait BExtractor {
30+
def unapply(x: X): Boolean
31+
}
32+
33+
val C: CExtractor
34+
trait CExtractor {
35+
def unapply(x: Y): Boolean // Note the type Y
36+
}
37+
38+
val D: DExtractor
39+
trait DExtractor {
40+
def unapply(x: X): Boolean
41+
}
42+
43+
}

0 commit comments

Comments
 (0)