Skip to content

Fix #14726: call exclusiveLower before addLess during unification #14727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ 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)
val up = constraint.exclusiveUpper(p1, p2)

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,9 +374,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
constraint = constraint.updateEntry(pKept, newBounds).replace(pRemoved, pKept)

Expand Down
21 changes: 21 additions & 0 deletions tests/pos/i14726-upper.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def test0[A >: Int] = {
def test1[X, B >: X <: X] = {
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 Int <: (A <: B <:) X for X.
val t0: X = 0
case _ =>
}
case _ =>
}
}
}
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 // should work too
val t2: Int = t0 : A // works
case _ =>
}
case _ =>
}
}