Skip to content

Commit 03b67e4

Browse files
committed
Fix adjustDelta logic in adjustDeps
1 parent ab40d5c commit 03b67e4

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -331,39 +331,40 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
331331
* and/or prefix of `bound`, just add the new parts of `bound`.
332332
* @param isLower `bound` and `prevBound` are lower bounds
333333
*/
334-
def adjustDelta(bound: Type, prevBound: Type, isLower: Boolean): Boolean =
335-
if bound eq prevBound then true
334+
def adjustDelta(bound: Type, prevBound: Type, isLower: Boolean, baseCase: => Boolean): Boolean =
335+
if bound eq prevBound then
336+
baseCase
336337
else bound match
337338
case bound: AndOrType =>
338-
adjustDelta(bound.tp1, prevBound, isLower) && {
339+
adjustDelta(bound.tp1, prevBound, isLower, baseCase) && {
339340
adjustReferenced(bound.tp2, isLower, add = true)
340341
true
341342
}
342343
case _ => false
343344

344-
/** Adjust dependencies to account for the delta of previous bound `prevBound`
345-
* and new bound `bound`.
346-
* @param isLower `bound` and `prevBound` are lower bounds
345+
/** Adjust dependencies to account for the delta of previous bounds `prevBounds`
346+
* and new bounds `bounds`.
347+
* @param add true if the bounds are added, false if they are removed
347348
*/
348-
def adjustBounds(bound: Type, prevBound: Type, isLower: Boolean) =
349-
if !adjustDelta(bound, prevBound, isLower) then
350-
adjustReferenced(prevBound, isLower, add = false)
351-
adjustReferenced(bound, isLower, add = true)
349+
def adjustBounds(bounds: TypeBounds, add: Boolean) =
350+
adjustReferenced(bounds.lo, isLower = true, add)
351+
adjustReferenced(bounds.hi, isLower = false, add)
352352

353353
entry match
354-
case TypeBounds(lo, hi) =>
354+
case entry @ TypeBounds(lo, hi) =>
355355
prevEntry match
356-
case TypeBounds(plo, phi) =>
357-
adjustBounds(lo, plo, isLower = true)
358-
adjustBounds(hi, phi, isLower = false)
356+
case prevEntry @ TypeBounds(plo, phi) =>
357+
if !adjustDelta(lo, plo, isLower = true,
358+
adjustDelta(hi, phi, isLower = false, true))
359+
then
360+
adjustBounds(prevEntry, add = false)
361+
adjustBounds(entry, add = true)
359362
case _ =>
360-
adjustReferenced(lo, isLower = true, add = true)
361-
adjustReferenced(hi, isLower = false, add = true)
363+
adjustBounds(entry, add = true)
362364
case _ =>
363365
prevEntry match
364-
case TypeBounds(plo, phi) =>
365-
adjustReferenced(plo, isLower = true, add = false)
366-
adjustReferenced(phi, isLower = false, add = false)
366+
case prevEntry: TypeBounds =>
367+
adjustBounds(prevEntry, add = false)
367368
case _ =>
368369
dropDeps(srcParam)
369370
this
@@ -608,7 +609,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
608609
boundsLens.update(this, current, param, newEntry).adjustDeps(newEntry, oldEntry, param)
609610

610611
private def updateEntry(current: This, param: TypeParamRef, newEntry: Type)(using Context): This = {
611-
//println(i"update $param to $tp in $current")
612+
//println(i"update $param to $newEntry in $current")
612613
if Config.checkNoWildcardsInConstraint then assert(!newEntry.containsWildcardTypes)
613614
var current1 = updateEntryNoOrdering(current, param, newEntry, current.entry(param))
614615
newEntry match {

0 commit comments

Comments
 (0)