Skip to content

Commit 191885c

Browse files
Instantiate constraint entries when updated to equal bounds
1 parent 2ca0ce7 commit 191885c

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ trait ConstraintHandling {
327327
(c1 eq constraint)
328328
|| {
329329
constraint = c1
330-
val TypeBounds(lo, hi) = constraint.entry(param): @unchecked
330+
val TypeBounds(lo, hi) = constraint.nonParamBounds(param)
331331
isSub(lo, hi)
332332
}
333333
end addOneBound

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ object OrderingConstraint {
104104
def updateEntries(c: OrderingConstraint, poly: TypeLambda, entries: Array[Type])(using Context): OrderingConstraint =
105105
c.newConstraint(boundsMap = c.boundsMap.updated(poly, entries))
106106
def initial = NoType
107+
108+
override def update(prev: OrderingConstraint, current: OrderingConstraint,
109+
poly: TypeLambda, idx: Int, entry: Type)(using Context): OrderingConstraint =
110+
entry match
111+
case TypeBounds(lo, hi) if lo eq hi =>
112+
val replaceParams = new TypeMap:
113+
def apply(tp: Type): Type = tp match
114+
case tp: TypeParamRef => current.typeVarOfParam(tp)
115+
case _ => mapOver(tp)
116+
super.update(prev, current, poly, idx, replaceParams(hi))
117+
case _ =>
118+
super.update(prev, current, poly, idx, entry)
107119
}
108120

109121
private val lowerLens: ConstraintLens[List[TypeParamRef]] = new ConstraintLens[List[TypeParamRef]] {
@@ -483,7 +495,10 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
483495
case param: TypeParamRef if contains(param) =>
484496
todos += (if isUpper then order(_, _, param) else order(_, param, _))
485497
NoType
486-
case tp: TypeBounds =>
498+
case tp: TypeBounds if tp.lo ne tp.hi =>
499+
// IMPROVE
500+
// - pass current ? or
501+
// - do opt in add too
487502
val lo1 = stripParams(tp.lo, todos, !isUpper).orElse(defn.NothingType)
488503
val hi1 = stripParams(tp.hi, todos, isUpper).orElse(tp.topType)
489504
tp.derivedTypeBounds(lo1, hi1)

0 commit comments

Comments
 (0)