@@ -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