@@ -5760,6 +5760,10 @@ object Types extends TypeUtils {
5760
5760
variance = saved
5761
5761
derivedLambdaType(tp)(ptypes1, this (restpe))
5762
5762
5763
+ protected def mapOverTypeVar (tp : TypeVar ) =
5764
+ val inst = tp.instanceOpt
5765
+ if (inst.exists) apply(inst) else tp
5766
+
5763
5767
def isRange (tp : Type ): Boolean = tp.isInstanceOf [Range ]
5764
5768
5765
5769
protected def mapCapturingType (tp : Type , parent : Type , refs : CaptureSet , v : Int ): Type =
@@ -5797,8 +5801,7 @@ object Types extends TypeUtils {
5797
5801
derivedTypeBounds(tp, lo1, this (tp.hi))
5798
5802
5799
5803
case tp : TypeVar =>
5800
- val inst = tp.instanceOpt
5801
- if (inst.exists) apply(inst) else tp
5804
+ mapOverTypeVar(tp)
5802
5805
5803
5806
case tp : ExprType =>
5804
5807
derivedExprType(tp, this (tp.resultType))
@@ -6208,6 +6211,16 @@ object Types extends TypeUtils {
6208
6211
else
6209
6212
super .mapCapturingType(tp, parent, refs, v)
6210
6213
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
+
6211
6224
protected def reapply (tp : Type ): Type = apply(tp)
6212
6225
}
6213
6226
0 commit comments