Skip to content

Commit 6e5f540

Browse files
Move override of mapOverTypeVar logic in ApproximatingTypeMap
1 parent f58cbf9 commit 6e5f540

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,7 @@ trait ConstraintHandling {
248248
override def apply(tp: Type): Type = tp match
249249
case tp: TypeVar if !tp.isInstantiated && !levelOK(tp.nestingLevel, maxLevel) =>
250250
legalVar(tp)
251-
// TypeParamRef can occur in tl bounds
252-
case tp: TypeVar if tp.isInstantiated =>
253-
/* `TypeMap` always strips instantiated type variables in `mapOver`.
254-
* We can keep the original type var if its instance is not transformed
255-
* by the LevelAvoidMap. This allows for simpler bounds and for
256-
* derived skolems (see ApproximatingTypeMap#derivedSkolemType) to
257-
* remain the same by keeping their info unchanged. Loosing skolems
258-
* in the legalBound computation prevented type vars from being
259-
* instantiated with theses skolems, even if they were within the bounds.
260-
*/
261-
val res = apply(tp.instanceOpt)
262-
if res eq tp.instanceOpt then tp else res
251+
// TypeParamRef can occur in tl bounds
263252
case tp: TypeParamRef =>
264253
constraint.typeVarOfParam(tp) match
265254
case tvar: TypeVar =>

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6180,6 +6180,10 @@ object Types extends TypeUtils {
61806180
variance = saved
61816181
derivedLambdaType(tp)(ptypes1, this(restpe))
61826182

6183+
protected def mapOverTypeVar(tp: TypeVar) =
6184+
val inst = tp.instanceOpt
6185+
if (inst.exists) apply(inst) else tp
6186+
61836187
def isRange(tp: Type): Boolean = tp.isInstanceOf[Range]
61846188

61856189
protected def mapCapturingType(tp: Type, parent: Type, refs: CaptureSet, v: Int): Type =
@@ -6217,8 +6221,7 @@ object Types extends TypeUtils {
62176221
derivedTypeBounds(tp, lo1, this(tp.hi))
62186222

62196223
case tp: TypeVar =>
6220-
val inst = tp.instanceOpt
6221-
if (inst.exists) apply(inst) else tp
6224+
mapOverTypeVar(tp)
62226225

62236226
case tp: ExprType =>
62246227
derivedExprType(tp, this(tp.resultType))
@@ -6632,6 +6635,16 @@ object Types extends TypeUtils {
66326635
tp.derivedLambdaType(tp.paramNames, formals, restpe)
66336636
}
66346637

6638+
override protected def mapOverTypeVar(tp: TypeVar) =
6639+
val inst = tp.instanceOpt
6640+
if !inst.exists then tp
6641+
else
6642+
// We can keep the original type var if its instance is not transformed
6643+
// by the ApproximatingTypeMap. This allows for simpler bounds and for
6644+
// derivedSkolemType to retain more skolems, by keeping the info unchanged.
6645+
val res = apply(inst)
6646+
if res eq inst then tp else res
6647+
66356648
protected def reapply(tp: Type): Type = apply(tp)
66366649
}
66376650

0 commit comments

Comments
 (0)