Skip to content

Commit 4108960

Browse files
committed
ApproximatingTypeMap: fix skolem handling
By definition, a skolem is neither a subtype nor a supertype of a different skolem, so regardless of the variance, we shouldn't return a new skolem when approximating an existing skolem. Fixing derivedSkolemType to not do this lets us remove a special-case in `avoid`.
1 parent 6ac8b47 commit 4108960

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,6 @@ object TypeOps:
459459
// Therefore, either they don't appear in the type to be avoided, or
460460
// it must be a class that encloses the block whose type is to be avoided.
461461
tp
462-
case tp: SkolemType if partsToAvoid(Nil, tp.info).nonEmpty =>
463-
range(defn.NothingType, apply(tp.info))
464462
case tp: TypeVar if mapCtx.typerState.constraint.contains(tp) =>
465463
val lo = TypeComparer.instanceType(
466464
tp.origin, fromBelow = variance > 0 || variance == 0 && tp.hasLowerBound)(using mapCtx)

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5941,12 +5941,13 @@ object Types {
59415941
case Range(lo, hi) => range(bound.bounds.lo, bound.bounds.hi)
59425942
case _ => tp.derivedMatchType(bound, scrutinee, cases)
59435943

5944-
override protected def derivedSkolemType(tp: SkolemType, info: Type): Type = info match {
5945-
case Range(lo, hi) =>
5946-
range(tp.derivedSkolemType(lo), tp.derivedSkolemType(hi))
5947-
case _ =>
5948-
tp.derivedSkolemType(info)
5949-
}
5944+
override protected def derivedSkolemType(tp: SkolemType, info: Type): Type =
5945+
if info eq tp.info then tp
5946+
// By definition, a skolem is neither a subtype nor a supertype of a
5947+
// different skolem. So, regardless of `variance`, we cannot return a
5948+
// fresh skolem when approximating an existing skolem, we can only return
5949+
// a range.
5950+
else range(defn.NothingType, info)
59505951

59515952
override protected def derivedClassInfo(tp: ClassInfo, pre: Type): Type = {
59525953
assert(!isRange(pre))

0 commit comments

Comments
 (0)