@@ -792,8 +792,8 @@ object Contexts {
792
792
}
793
793
794
794
def cautiousSubtype (tp1 : Type , tp2 : Type , isSubtype : Boolean ): Boolean = {
795
- val externalizedTp1 = ( new TypeVarRemovingMap ()(ctx)) (tp1)
796
- val externalizedTp2 = ( new TypeVarRemovingMap ()(ctx)) (tp2)
795
+ val externalizedTp1 = removeTypeVars (tp1)
796
+ val externalizedTp2 = removeTypeVars (tp2)
797
797
798
798
def descr = {
799
799
def op = s " frozen_ ${if (isSubtype) " <:<" else " >:>" }"
@@ -824,7 +824,7 @@ object Contexts {
824
824
return true
825
825
}
826
826
827
- val internalizedBound = ( new TypeVarInsertingMap ()(ctx)) (bound)
827
+ val internalizedBound = insertTypeVars (bound)
828
828
val res = stripInst(internalizedBound) match {
829
829
case boundTvar : TypeVar =>
830
830
if (boundTvar eq symTvar) true
@@ -850,7 +850,7 @@ object Contexts {
850
850
case tv =>
851
851
def retrieveBounds : TypeBounds = {
852
852
val tb = constraint.fullBounds(tv.origin)
853
- ( new TypeVarRemovingMap ()(ctx)) (tb).asInstanceOf [TypeBounds ]
853
+ removeTypeVars (tb).asInstanceOf [TypeBounds ]
854
854
}
855
855
val res =
856
856
if (checkInProgress || ctx.mode.is(Mode .GADTflexible )) retrieveBounds
@@ -883,31 +883,33 @@ object Contexts {
883
883
dirtyFlag
884
884
)
885
885
886
+ private def insertTypeVars (tp : Type , map : TypeMap = null )(implicit ctx : Context ) = tp match {
887
+ case tp : TypeRef =>
888
+ val sym = tp.typeSymbol
889
+ if (contains(sym)) tvar(sym) else tp
890
+ case _ =>
891
+ (if (map != null ) map else new TypeVarInsertingMap ()).mapOver(tp)
892
+ }
886
893
private final class TypeVarInsertingMap (implicit ctx : Context ) extends TypeMap {
887
- override def apply (tp : Type ): Type = tp match {
888
- case tp : TypeRef =>
889
- val sym = tp.typeSymbol
890
- if (contains(sym)) tvar(sym) else tp
891
- case _ =>
892
- mapOver(tp)
893
- }
894
+ override def apply (tp : Type ): Type = insertTypeVars(tp, this )
894
895
}
895
896
897
+ private def removeTypeVars (tp : Type , map : TypeMap = null )(implicit ctx : Context ) = tp match {
898
+ case tpr : TypeParamRef =>
899
+ reverseMapping(tpr) match {
900
+ case null => tpr
901
+ case sym => sym.typeRef
902
+ }
903
+ case tv : TypeVar =>
904
+ reverseMapping(tv.origin) match {
905
+ case null => tv
906
+ case sym => sym.typeRef
907
+ }
908
+ case _ =>
909
+ (if (map != null ) map else new TypeVarRemovingMap ()).mapOver(tp)
910
+ }
896
911
private final class TypeVarRemovingMap (implicit ctx : Context ) extends TypeMap {
897
- override def apply (tp : Type ): Type = tp match {
898
- case tpr : TypeParamRef =>
899
- reverseMapping(tpr) match {
900
- case null => tpr
901
- case sym => sym.typeRef
902
- }
903
- case tv : TypeVar =>
904
- reverseMapping(tv.origin) match {
905
- case null => tv
906
- case sym => sym.typeRef
907
- }
908
- case _ =>
909
- mapOver(tp)
910
- }
912
+ override def apply (tp : Type ): Type = removeTypeVars(tp, this )
911
913
}
912
914
}
913
915
0 commit comments