Skip to content

Commit bb9ba6b

Browse files
committed
Propagate bounds when unifying type parameters
1 parent 6011847 commit bb9ba6b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ trait ConstraintHandling {
197197
private def unify(p1: TypeParamRef, p2: TypeParamRef)(using Context): Boolean = {
198198
constr.println(s"unifying $p1 $p2")
199199
assert(constraint.isLess(p1, p2))
200+
constraint = constraint.addLess(p2, p1)
200201
val down = constraint.exclusiveLower(p2, p1)
201202
val up = constraint.exclusiveUpper(p1, p2)
202203
constraint = constraint.unify(p1, p2)

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,15 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
353353
else {
354354
assert(contains(param1), i"$param1")
355355
assert(contains(param2), i"$param2")
356-
val newUpper = param2 :: exclusiveUpper(param2, param1)
357-
val newLower = param1 :: exclusiveLower(param1, param2)
356+
// Is `order` called during parameter unification?
357+
val unifying = isLess(param2, param1)
358+
val newUpper = param2 :: exclusiveUpper(param2, param1).filterNot(_ eq param1)
359+
val newLower =
360+
if unifying then
361+
// Do not add bounds for param1 since it will be unified to param2 soon.
362+
exclusiveLower(param1, param2).filterNot(_ eq param2)
363+
else
364+
param1 :: exclusiveLower(param1, param2).filterNot(_ eq param2)
358365
val current1 = newLower.foldLeft(current)(upperLens.map(this, _, _, newUpper ::: _))
359366
val current2 = newUpper.foldLeft(current1)(lowerLens.map(this, _, _, newLower ::: _))
360367
current2

0 commit comments

Comments
 (0)