@@ -316,7 +316,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
316
316
extends TypeTraverser , ConstraintAwareTraversal [Unit ]:
317
317
318
318
var add : Boolean = compiletime.uninitialized
319
- private val seen = util.HashSet [LazyRef ]()
319
+ val seen = util.HashSet [LazyRef ]()
320
320
321
321
def update (deps : ReverseDeps , referenced : TypeParamRef ): ReverseDeps =
322
322
val prev = deps.at(referenced)
@@ -352,6 +352,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
352
352
def adjustReferenced (bound : Type , isLower : Boolean , add : Boolean ) =
353
353
adjuster.variance = if isLower then 1 else - 1
354
354
adjuster.add = add
355
+ adjuster.seen.clear()
355
356
adjuster.traverse(bound)
356
357
357
358
/** Use an optimized strategy to adjust dependencies to account for the delta
@@ -695,13 +696,17 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
695
696
case tvar : TypeVar =>
696
697
if tvar.isInstantiated
697
698
then
698
- // That's the case if replace is called from TypeVar's instantiateWith.
699
- // Forget about instantiation for old dependencies.
699
+ // If the type variuable has been instantiated, we need to forget about
700
+ // the instantiation for old dependencies.
701
+ // I.e. to find out what the old entry was, we should not follow
702
+ // the newly instantiated type variable but assume the type variable's origin `param`.
703
+ // An example where this happens is if `replace` is called from TypeVar's `instantiateWith`.
700
704
oldDepEntry = mapReplacedTypeVarTo(param)(oldDepEntry)
701
705
else
702
- // That's the case if replace is called from unify.
703
- // Assume parameter has been replaced for new dependencies
704
- // (the actual replacement is done below).
706
+ // If the type variuable has not been instantiated, we need to replace references to it
707
+ // in the new entry by `replacement`. Otherwise we would get stuck in an uninstantiated
708
+ // type variable.
709
+ // An example where this happens is if `replace` is called from unify.
705
710
newDepEntry = mapReplacedTypeVarTo(replacement)(newDepEntry)
706
711
case _ =>
707
712
if oldDepEntry ne newDepEntry then
0 commit comments