Skip to content

Commit 7818ed3

Browse files
committed
Fix derivedRefinedType in ApproximatingTypeMap
The logic before was overcomplicated since I did not take into account that Range refinedInfos could only happen at variance 0. On the othet hand, it did not take into account all the subtleties of alias types with variances.
1 parent 8c1a6dc commit 7818ed3

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3923,20 +3923,20 @@ object Types {
39233923
case Range(parentLo, parentHi) =>
39243924
range(derivedRefinedType(tp, parentLo, info), derivedRefinedType(tp, parentHi, info))
39253925
case _ =>
3926+
def propagate(lo: Type, hi: Type) =
3927+
range(derivedRefinedType(tp, parent, lo), derivedRefinedType(tp, parent, hi))
39263928
if (parent.isBottomType) parent
39273929
else info match {
3930+
case Range(infoLo: TypeBounds, infoHi: TypeBounds) =>
3931+
assert(variance == 0)
3932+
val v1 = infoLo.variance
3933+
val v2 = infoHi.variance
3934+
if (v1 > 0 && v2 > 0) propagate(infoLo, infoHi)
3935+
else if (v1 < 0 && v2 < 0) propagate(infoHi, infoLo)
3936+
else if (!infoLo.isAlias && !infoHi.isAlias) propagate(infoLo, infoHi)
3937+
else range(tp.bottomType, tp.topType)
39283938
case Range(infoLo, infoHi) =>
3929-
def propagate(lo: Type, hi: Type) =
3930-
range(derivedRefinedType(tp, parent, lo), derivedRefinedType(tp, parent, hi))
3931-
tp.refinedInfo match {
3932-
case rinfo: TypeBounds =>
3933-
val v = if (rinfo.isAlias) rinfo.variance * variance else variance
3934-
if (v > 0) tp.derivedRefinedType(parent, tp.refinedName, rangeToBounds(info))
3935-
else if (v < 0) propagate(infoHi, infoLo)
3936-
else range(tp.bottomType, tp.topType)
3937-
case _ =>
3938-
propagate(infoLo, infoHi)
3939-
}
3939+
propagate(infoLo, infoHi)
39403940
case _ =>
39413941
tp.derivedRefinedType(parent, tp.refinedName, info)
39423942
}

0 commit comments

Comments
 (0)