Skip to content

Commit

Permalink
Fix scala#14726: call exclusiveLower before addLess during unification
Browse files Browse the repository at this point in the history
  • Loading branch information
Linyxus committed Mar 21, 2022
1 parent b90752d commit afc5752
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ trait ConstraintHandling {
val pKept = if level1 <= level2 then p1 else p2
val pRemoved = if level1 <= level2 then p2 else p1

val down = constraint.exclusiveLower(p2, p1)

constraint = constraint.addLess(p2, p1, direction = if pKept eq p1 then KeepParam2 else KeepParam1)

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

val down = constraint.exclusiveLower(p2, p1)
val up = constraint.exclusiveUpper(p1, p2)

val newBounds = (boundKept & boundRemoved).bounds
Expand Down
21 changes: 21 additions & 0 deletions tests/pos/i14726.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def test[X, A >: X <: X, B <: Int] = {
enum Expr[+T]:
case TagA() extends Expr[A]
case TagB() extends Expr[B]

import Expr._

def foo(e1: Expr[A], e2: Expr[B]) = e1 match {
case TagB() => // add GADT constr: B <: A
e2 match {
case TagA() =>
// add GADT constr: A <: B
// should propagate bound X (<: A <: B) <: Int for X.
val t0: X = ???
val t1: Int = t0 // error
val t2: Int = t0 : A // cast explicitly, works
case _ =>
}
case _ =>
}
}

0 comments on commit afc5752

Please sign in to comment.