Skip to content

Commit 4fde618

Browse files
committed
Refactor special handling for unification in order
1 parent bb9ba6b commit 4fde618

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,25 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
355355
assert(contains(param2), i"$param2")
356356
// Is `order` called during parameter unification?
357357
val unifying = isLess(param2, param1)
358-
val newUpper = param2 :: exclusiveUpper(param2, param1).filterNot(_ eq param1)
359-
val newLower =
358+
val newUpper = {
359+
val up = exclusiveUpper(param2, param1)
360+
if unifying then
361+
// Since param2 <:< param1 already holds now, filter out param1 to avoid adding
362+
// duplicated orderings.
363+
param2 :: up.filterNot(_ eq param1)
364+
else
365+
param2 :: up
366+
}
367+
val newLower = {
368+
val lower = exclusiveLower(param1, param2)
360369
if unifying then
361370
// Do not add bounds for param1 since it will be unified to param2 soon.
362-
exclusiveLower(param1, param2).filterNot(_ eq param2)
371+
// And, similarly filter out param2 from lowerly-ordered parameters
372+
// to avoid duplicated orderings.
373+
lower.filterNot(_ eq param2)
363374
else
364-
param1 :: exclusiveLower(param1, param2).filterNot(_ eq param2)
375+
param1 :: lower
376+
}
365377
val current1 = newLower.foldLeft(current)(upperLens.map(this, _, _, newUpper ::: _))
366378
val current2 = newUpper.foldLeft(current1)(lowerLens.map(this, _, _, newLower ::: _))
367379
current2

0 commit comments

Comments
 (0)