Skip to content

Commit 609ee7b

Browse files
committed
Fix bias in ConstraintHandling#subsumes
Previously, if c2 had instantiated a variable, it would not be iterated over and would not be compared with c1.
1 parent 483285f commit 609ee7b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ trait ConstraintHandling[AbstractContext] {
345345
else {
346346
val saved = constraint
347347
try
348-
c2.forallParams(p =>
348+
pre.forallParams(p =>
349349
c1.contains(p) &&
350350
c2.upper(p).forall(c1.isLess(p, _)) &&
351351
isSubTypeWhenFrozen(c1.nonParamBounds(p), c2.nonParamBounds(p)))

tests/neg/overconstrained-type-variables-gadt.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@ object Test {
22
trait T1[A] { def a: A }
33
trait T2[B] { def b: B }
44

5-
def foo[X, Y](u: T1[X] | T2[Y]): X = u match {
5+
def foo[X, Y](v: T1[X] | T2[Y]): X = v match {
66
case t1: T1[t] =>
77
// consider: foo[Int, String](new T1[String] with T2[String] { ... })
88
t1.a // error
99
}
1010

1111
class T1Int extends T1[Int] { def a = 0 }
12-
def bar[X, Y](u: T1[X] | T2[Y]): X = u match {
12+
def bar[X, Y](v: T1[X] | T2[Y]): X = v match {
1313
case t1: T1Int =>
1414
// similar reasoning to above applies
1515
t1.a // error
1616
}
17+
18+
class T1IntT2String extends T1[Int] with T2[String] {
19+
def a = 0
20+
def b = ""
21+
}
22+
def baz[X](v: T1[X] | T2[X]): Unit = v match {
23+
case _: T1IntT2String =>
24+
val x1: X = 0 // error
25+
val x2: X = "" // error
26+
}
1727
}

0 commit comments

Comments
 (0)