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