Skip to content

Commit 5bbdb30

Browse files
committed
Address review comments
1 parent 18b574a commit 5bbdb30

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
316316
extends TypeTraverser, ConstraintAwareTraversal[Unit]:
317317

318318
var add: Boolean = compiletime.uninitialized
319-
private val seen = util.HashSet[LazyRef]()
319+
val seen = util.HashSet[LazyRef]()
320320

321321
def update(deps: ReverseDeps, referenced: TypeParamRef): ReverseDeps =
322322
val prev = deps.at(referenced)
@@ -352,6 +352,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
352352
def adjustReferenced(bound: Type, isLower: Boolean, add: Boolean) =
353353
adjuster.variance = if isLower then 1 else -1
354354
adjuster.add = add
355+
adjuster.seen.clear()
355356
adjuster.traverse(bound)
356357

357358
/** Use an optimized strategy to adjust dependencies to account for the delta
@@ -695,13 +696,17 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
695696
case tvar: TypeVar =>
696697
if tvar.isInstantiated
697698
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`.
700704
oldDepEntry = mapReplacedTypeVarTo(param)(oldDepEntry)
701705
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.
705710
newDepEntry = mapReplacedTypeVarTo(replacement)(newDepEntry)
706711
case _ =>
707712
if oldDepEntry ne newDepEntry then

0 commit comments

Comments
 (0)