@@ -3888,6 +3888,9 @@ object Types {
3888
3888
case class Range (lo : Type , hi : Type ) extends UncachedGroundType {
3889
3889
assert(! lo.isInstanceOf [Range ])
3890
3890
assert(! hi.isInstanceOf [Range ])
3891
+
3892
+ override def toText (printer : Printer ): Text =
3893
+ lo.toText(printer) ~ " .." ~ hi.toText(printer)
3891
3894
}
3892
3895
3893
3896
/** A type map that approximates TypeBounds types depending on
@@ -3922,14 +3925,23 @@ object Types {
3922
3925
case _ => tp
3923
3926
}
3924
3927
3928
+ def atVariance [T ](v : Int )(op : => T ): T = {
3929
+ val saved = variance
3930
+ variance = v
3931
+ try op finally variance = saved
3932
+ }
3933
+
3925
3934
override protected def derivedSelect (tp : NamedType , pre : Type ) =
3926
3935
if (pre eq tp.prefix) tp
3927
3936
else pre match {
3928
3937
case Range (preLo, preHi) =>
3929
3938
tp.info match {
3930
- case TypeAlias (alias) => apply(alias)
3931
- case TypeBounds (lo, hi) => range(apply(lo), apply(hi))
3932
- case _ => range(tp.derivedSelect(preLo), tp.derivedSelect(preHi))
3939
+ case TypeAlias (alias) =>
3940
+ apply(alias)
3941
+ case TypeBounds (lo, hi) =>
3942
+ range(atVariance(- 1 )(apply(lo)), atVariance(1 )(apply(hi)))
3943
+ case _ =>
3944
+ range(tp.derivedSelect(preLo), tp.derivedSelect(preHi))
3933
3945
}
3934
3946
case _ => tp.derivedSelect(pre)
3935
3947
}
@@ -3947,23 +3959,27 @@ object Types {
3947
3959
tp.derivedRefinedType(parent, tp.refinedName, rangeToBounds(info))
3948
3960
}
3949
3961
}
3962
+
3950
3963
override protected def derivedRecType (tp : RecType , parent : Type ) =
3951
3964
parent match {
3952
3965
case Range (lo, hi) => range(tp.rebind(lo), tp.rebind(hi))
3953
3966
case _ => tp.rebind(parent)
3954
3967
}
3968
+
3955
3969
override protected def derivedTypeAlias (tp : TypeAlias , alias : Type ) =
3956
3970
alias match {
3957
3971
case Range (lo, hi) =>
3958
3972
if (variance > 0 ) TypeBounds (lo, hi)
3959
3973
else range(TypeAlias (lo), TypeAlias (hi))
3960
3974
case _ => tp.derivedTypeAlias(alias)
3961
3975
}
3976
+
3962
3977
override protected def derivedTypeBounds (tp : TypeBounds , lo : Type , hi : Type ) =
3963
3978
if (isRange(lo) || isRange(hi))
3964
3979
if (variance > 0 ) TypeBounds (loBound(lo), hiBound(hi))
3965
3980
else range(TypeBounds (hiBound(lo), loBound(hi)), TypeBounds (loBound(lo), hiBound(hi)))
3966
3981
else tp.derivedTypeBounds(lo, hi)
3982
+
3967
3983
override protected def derivedSuperType (tp : SuperType , thistp : Type , supertp : Type ) =
3968
3984
if (isRange(thistp) || isRange(supertp)) range()
3969
3985
else tp.derivedSuperType(thistp, supertp)
@@ -4003,6 +4019,7 @@ object Types {
4003
4019
if (tp.isAnd) range(loBound(tp1) & loBound(tp2), hiBound(tp1) & hiBound(tp2))
4004
4020
else range(loBound(tp1) | loBound(tp2), hiBound(tp1) | hiBound(tp2))
4005
4021
else tp.derivedAndOrType(tp1, tp2)
4022
+
4006
4023
override protected def derivedAnnotatedType (tp : AnnotatedType , underlying : Type , annot : Annotation ) =
4007
4024
underlying match {
4008
4025
case Range (lo, hi) =>
@@ -4014,6 +4031,7 @@ object Types {
4014
4031
override protected def derivedWildcardType (tp : WildcardType , bounds : Type ) = {
4015
4032
tp.derivedWildcardType(rangeToBounds(bounds))
4016
4033
}
4034
+
4017
4035
override protected def derivedClassInfo (tp : ClassInfo , pre : Type ): Type = {
4018
4036
assert(! pre.isInstanceOf [Range ])
4019
4037
tp.derivedClassInfo(pre)
0 commit comments