Skip to content

Commit afc5752

Browse files
committed
Fix #14726: call exclusiveLower before addLess during unification
1 parent b90752d commit afc5752

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ 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+
355357
constraint = constraint.addLess(p2, p1, direction = if pKept eq p1 then KeepParam2 else KeepParam1)
356358

357359
val boundKept = constraint.nonParamBounds(pKept).substParam(pRemoved, pKept)
@@ -371,7 +373,6 @@ trait ConstraintHandling {
371373
if !isSub(lo, hi) then
372374
boundRemoved = TypeBounds(lo & hi, hi)
373375

374-
val down = constraint.exclusiveLower(p2, p1)
375376
val up = constraint.exclusiveUpper(p1, p2)
376377

377378
val newBounds = (boundKept & boundRemoved).bounds

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 // error
16+
val t2: Int = t0 : A // cast explicitly, works
17+
case _ =>
18+
}
19+
case _ =>
20+
}
21+
}

0 commit comments

Comments
 (0)