@@ -354,13 +354,18 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
354
354
* `<:<` relationships between parameters ("edges") but not bounds.
355
355
*/
356
356
def order (current : This , param1 : TypeParamRef , param2 : TypeParamRef , direction : UnificationDirection = NoUnification )(using Context ): This =
357
- if (param1 == param2 || current.isLess(param1, param2)) this
358
- else {
359
- assert(contains(param1), i " $param1" )
360
- assert(contains(param2), i " $param2" )
357
+ // /!\ Careful here: we're adding constraints on `current`, not `this`, so
358
+ // think twice when using an instance method! We only need to pass `this` as
359
+ // the `prev` argument in methods on `ConstraintLens`.
360
+ // TODO: Refactor this code to take `prev` as a parameter and add
361
+ // constraints on `this` instead?
362
+ if param1 == param2 || current.isLess(param1, param2) then current
363
+ else
364
+ assert(current.contains(param1), i " $param1" )
365
+ assert(current.contains(param2), i " $param2" )
361
366
val unifying = direction != NoUnification
362
367
val newUpper = {
363
- val up = exclusiveUpper(param2, param1)
368
+ val up = current. exclusiveUpper(param2, param1)
364
369
if unifying then
365
370
// Since param2 <:< param1 already holds now, filter out param1 to avoid adding
366
371
// duplicated orderings.
@@ -374,7 +379,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
374
379
param2 :: up
375
380
}
376
381
val newLower = {
377
- val lower = exclusiveLower(param1, param2)
382
+ val lower = current. exclusiveLower(param1, param2)
378
383
if unifying then
379
384
// Similarly, filter out param2 from lowerly-ordered parameters
380
385
// to avoid duplicated orderings.
@@ -390,7 +395,8 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
390
395
val current1 = newLower.foldLeft(current)(upperLens.map(this , _, _, newUpper ::: _))
391
396
val current2 = newUpper.foldLeft(current1)(lowerLens.map(this , _, _, newLower ::: _))
392
397
current2
393
- }
398
+ end if
399
+ end order
394
400
395
401
/** The list of parameters P such that, for a fresh type parameter Q:
396
402
*
0 commit comments