Skip to content

Commit 2cd41da

Browse files
committed
In replace, update param after updating dependent params
1 parent 747771d commit 2cd41da

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -591,37 +591,34 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
591591
val replacement = tp.dealiasKeepAnnots.stripTypeVar
592592
if param == replacement then this.checkWellFormed()
593593
else
594+
assert(replacement.isValueTypeOrLambda)
595+
594596
val droppedTypeVar = typeVarOfParam(param)
595597

596598
//println(i"replace $param, $droppedTypeVar with $replacement in $this")
597599
val dropTypeVar = new TypeMap:
598600
override def apply(t: Type): Type =
599601
if t.exists && (t eq droppedTypeVar) then param else mapOver(t)
600602

601-
assert(replacement.isValueTypeOrLambda)
602-
var current =
603-
if isRemovable(param.binder) then remove(param.binder)
604-
else updateEntry(this, param, replacement)
603+
var current = this
605604

606605
def removeParam(ps: List[TypeParamRef]) = ps.filterConserve(param ne _)
607-
608-
def replaceParam(entry: Type, atPoly: TypeLambda, atIdx: Int): Type =
609-
val pref = atPoly.paramRefs(atIdx)
610-
val newEntry = current.ensureNonCyclic(pref, entry.substParam(param, replacement))
611-
adjustDeps(newEntry, entry, pref)
612-
newEntry
613-
614606
for lo <- lower(param) do
615607
current = upperLens.map(this, current, lo, removeParam)
616608
for hi <- upper(param) do
617609
current = lowerLens.map(this, current, hi, removeParam)
618610

619611
current.foreachParam { (p, i) =>
620612
val other = p.paramRefs(i)
621-
val oldEntry = current.entry(other)
622-
val newEntry = current.ensureNonCyclic(other, oldEntry.substParam(param, replacement))
623-
current = updateEntryNoOrdering(current, other, newEntry, dropTypeVar(oldEntry))
613+
if other != param then
614+
val oldEntry = current.entry(other)
615+
val newEntry = current.ensureNonCyclic(other, oldEntry.substParam(param, replacement))
616+
current = updateEntryNoOrdering(current, other, newEntry, dropTypeVar(oldEntry))
624617
}
618+
619+
current =
620+
if isRemovable(param.binder) then current.remove(param.binder)
621+
else updateEntry(current, param, replacement)
625622
current.dropDeps(param)
626623
current.checkWellFormed()
627624
end replace

0 commit comments

Comments
 (0)