Skip to content

Commit e6a6e30

Browse files
authored
Merge pull request #14727 from Linyxus/fix-i14726
2 parents d26a860 + 50477c8 commit e6a6e30

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ trait ConstraintHandling {
352352
val pKept = if level1 <= level2 then p1 else p2
353353
val pRemoved = if level1 <= level2 then p2 else p1
354354

355+
val down = constraint.exclusiveLower(p2, p1)
356+
val up = constraint.exclusiveUpper(p1, p2)
357+
355358
constraint = constraint.addLess(p2, p1, direction = if pKept eq p1 then KeepParam2 else KeepParam1)
356359

357360
val boundKept = constraint.nonParamBounds(pKept).substParam(pRemoved, pKept)
@@ -371,9 +374,6 @@ trait ConstraintHandling {
371374
if !isSub(lo, hi) then
372375
boundRemoved = TypeBounds(lo & hi, hi)
373376

374-
val down = constraint.exclusiveLower(p2, p1)
375-
val up = constraint.exclusiveUpper(p1, p2)
376-
377377
val newBounds = (boundKept & boundRemoved).bounds
378378
constraint = constraint.updateEntry(pKept, newBounds).replace(pRemoved, pKept)
379379

tests/pos/i14726-upper.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def test0[A >: Int] = {
2+
def test1[X, B >: X <: X] = {
3+
enum Expr[+T]:
4+
case TagA() extends Expr[A]
5+
case TagB() extends Expr[B]
6+
7+
import Expr._
8+
9+
def foo(e1: Expr[A], e2: Expr[B]) = e1 match {
10+
case TagB() => // add GADT constr: B <: A
11+
e2 match {
12+
case TagA() =>
13+
// add GADT constr: A <: B
14+
// should propagate bound Int <: (A <: B <:) X for X.
15+
val t0: X = 0
16+
case _ =>
17+
}
18+
case _ =>
19+
}
20+
}
21+
}

tests/pos/i14726.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def test[X, A >: X <: X, B <: Int] = {
2+
enum Expr[+T]:
3+
case TagA() extends Expr[A]
4+
case TagB() extends Expr[B]
5+
6+
import Expr._
7+
8+
def foo(e1: Expr[A], e2: Expr[B]) = e1 match {
9+
case TagB() => // add GADT constr: B <: A
10+
e2 match {
11+
case TagA() =>
12+
// add GADT constr: A <: B
13+
// should propagate bound X (<: A <: B) <: Int for X.
14+
val t0: X = ???
15+
val t1: Int = t0 // should work too
16+
val t2: Int = t0 : A // works
17+
case _ =>
18+
}
19+
case _ =>
20+
}
21+
}

0 commit comments

Comments
 (0)