Skip to content

Commit 9d869e4

Browse files
authored
Merge pull request #4034 from dotty-staging/fix-4030
Fix #4030: avoid adding duplicate binders
2 parents 1b4fbf3 + a9d1d95 commit 9d869e4

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -910,8 +910,10 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
910910
/** Add a `Bind` node for each `bound` symbol in a type application `unapp` */
911911
def addBinders(unapp: Tree, bound: List[Symbol]) = unapp match {
912912
case TypeApply(fn, args) =>
913+
var remain = bound.toSet
913914
def addBinder(arg: Tree) = arg.tpe.stripTypeVar match {
914-
case ref: TypeRef if bound.contains(ref.symbol) =>
915+
case ref: TypeRef if remain.contains(ref.symbol) =>
916+
remain -= ref.symbol
915917
tpd.Bind(ref.symbol, Ident(ref))
916918
case _ =>
917919
arg

tests/patmat/i4030.check

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9: Pattern Match Exhaustivity: (C4(), _), (_, C4())

tests/patmat/i4030.scala

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
sealed trait Root[T]
2+
case object C1 extends Root[Int]
3+
case object C2 extends Root[String]
4+
case class C3[X, Y]() extends Root[(X => X)|(Y => Y)|(X => Y)]
5+
case class C4[X, Y]() extends Root[(X => X)|(Y => Y)|(X => Y)]
6+
7+
object TestGADT {
8+
9+
def f[A <: Seq[_], B, Foo >: A => B](v: Root[Foo], u: Root[Foo]) = (v, u) match {
10+
case (C3(), C3()) =>
11+
}
12+
f(C3[Seq[_], Long](), C4[Seq[_], Long]())
13+
}

0 commit comments

Comments
 (0)