Skip to content

Commit 3097d67

Browse files
committed
Move override of mapOverTypeVar logic in ApproximatingTypeMap
[Cherry-picked 6e5f540][modified]
1 parent 6803ec6 commit 3097d67

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

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

+1-12
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,7 @@ trait ConstraintHandling {
240240
override def apply(tp: Type): Type = tp match
241241
case tp: TypeVar if !tp.isInstantiated && !levelOK(tp.nestingLevel, maxLevel) =>
242242
legalVar(tp)
243-
// TypeParamRef can occur in tl bounds
244-
case tp: TypeVar if tp.isInstantiated =>
245-
/* `TypeMap` always strips instantiated type variables in `mapOver`.
246-
* We can keep the original type var if its instance is not transformed
247-
* by the LevelAvoidMap. This allows for simpler bounds and for
248-
* derived skolems (see ApproximatingTypeMap#derivedSkolemType) to
249-
* remain the same by keeping their info unchanged. Loosing skolems
250-
* in the legalBound computation prevented type vars from being
251-
* instantiated with theses skolems, even if they were within the bounds.
252-
*/
253-
val res = apply(tp.instanceOpt)
254-
if res eq tp.instanceOpt then tp else res
243+
// TypeParamRef can occur in tl bounds
255244
case tp: TypeParamRef =>
256245
constraint.typeVarOfParam(tp) match
257246
case tvar: TypeVar =>

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

+15-2
Original file line numberDiff line numberDiff line change
@@ -5760,6 +5760,10 @@ object Types extends TypeUtils {
57605760
variance = saved
57615761
derivedLambdaType(tp)(ptypes1, this(restpe))
57625762

5763+
protected def mapOverTypeVar(tp: TypeVar) =
5764+
val inst = tp.instanceOpt
5765+
if (inst.exists) apply(inst) else tp
5766+
57635767
def isRange(tp: Type): Boolean = tp.isInstanceOf[Range]
57645768

57655769
protected def mapCapturingType(tp: Type, parent: Type, refs: CaptureSet, v: Int): Type =
@@ -5797,8 +5801,7 @@ object Types extends TypeUtils {
57975801
derivedTypeBounds(tp, lo1, this(tp.hi))
57985802

57995803
case tp: TypeVar =>
5800-
val inst = tp.instanceOpt
5801-
if (inst.exists) apply(inst) else tp
5804+
mapOverTypeVar(tp)
58025805

58035806
case tp: ExprType =>
58045807
derivedExprType(tp, this(tp.resultType))
@@ -6208,6 +6211,16 @@ object Types extends TypeUtils {
62086211
else
62096212
super.mapCapturingType(tp, parent, refs, v)
62106213

6214+
override protected def mapOverTypeVar(tp: TypeVar) =
6215+
val inst = tp.instanceOpt
6216+
if !inst.exists then tp
6217+
else
6218+
// We can keep the original type var if its instance is not transformed
6219+
// by the ApproximatingTypeMap. This allows for simpler bounds and for
6220+
// derivedSkolemType to retain more skolems, by keeping the info unchanged.
6221+
val res = apply(inst)
6222+
if res eq inst then tp else res
6223+
62116224
protected def reapply(tp: Type): Type = apply(tp)
62126225
}
62136226

0 commit comments

Comments
 (0)