@@ -3865,6 +3865,9 @@ object Types {
3865
3865
case class Range (lo : Type , hi : Type ) extends UncachedGroundType {
3866
3866
assert(! lo.isInstanceOf [Range ])
3867
3867
assert(! hi.isInstanceOf [Range ])
3868
+
3869
+ override def toText (printer : Printer ): Text =
3870
+ lo.toText(printer) ~ " .." ~ hi.toText(printer)
3868
3871
}
3869
3872
3870
3873
/** A type map that approximates TypeBounds types depending on
@@ -3899,14 +3902,23 @@ object Types {
3899
3902
case _ => tp
3900
3903
}
3901
3904
3905
+ def atVariance [T ](v : Int )(op : => T ): T = {
3906
+ val saved = variance
3907
+ variance = v
3908
+ try op finally variance = saved
3909
+ }
3910
+
3902
3911
override protected def derivedSelect (tp : NamedType , pre : Type ) =
3903
3912
if (pre eq tp.prefix) tp
3904
3913
else pre match {
3905
3914
case Range (preLo, preHi) =>
3906
3915
tp.info match {
3907
- case TypeAlias (alias) => apply(alias)
3908
- case TypeBounds (lo, hi) => range(apply(lo), apply(hi))
3909
- case _ => range(tp.derivedSelect(preLo), tp.derivedSelect(preHi))
3916
+ case TypeAlias (alias) =>
3917
+ apply(alias)
3918
+ case TypeBounds (lo, hi) =>
3919
+ range(atVariance(- 1 )(apply(lo)), atVariance(1 )(apply(hi)))
3920
+ case _ =>
3921
+ range(tp.derivedSelect(preLo), tp.derivedSelect(preHi))
3910
3922
}
3911
3923
case _ => tp.derivedSelect(pre)
3912
3924
}
@@ -3924,23 +3936,27 @@ object Types {
3924
3936
tp.derivedRefinedType(parent, tp.refinedName, rangeToBounds(info))
3925
3937
}
3926
3938
}
3939
+
3927
3940
override protected def derivedRecType (tp : RecType , parent : Type ) =
3928
3941
parent match {
3929
3942
case Range (lo, hi) => range(tp.rebind(lo), tp.rebind(hi))
3930
3943
case _ => tp.rebind(parent)
3931
3944
}
3945
+
3932
3946
override protected def derivedTypeAlias (tp : TypeAlias , alias : Type ) =
3933
3947
alias match {
3934
3948
case Range (lo, hi) =>
3935
3949
if (variance > 0 ) TypeBounds (lo, hi)
3936
3950
else range(TypeAlias (lo), TypeAlias (hi))
3937
3951
case _ => tp.derivedTypeAlias(alias)
3938
3952
}
3953
+
3939
3954
override protected def derivedTypeBounds (tp : TypeBounds , lo : Type , hi : Type ) =
3940
3955
if (isRange(lo) || isRange(hi))
3941
3956
if (variance > 0 ) TypeBounds (loBound(lo), hiBound(hi))
3942
3957
else range(TypeBounds (hiBound(lo), loBound(hi)), TypeBounds (loBound(lo), hiBound(hi)))
3943
3958
else tp.derivedTypeBounds(lo, hi)
3959
+
3944
3960
override protected def derivedSuperType (tp : SuperType , thistp : Type , supertp : Type ) =
3945
3961
if (isRange(thistp) || isRange(supertp)) range()
3946
3962
else tp.derivedSuperType(thistp, supertp)
@@ -3980,6 +3996,7 @@ object Types {
3980
3996
if (tp.isAnd) range(loBound(tp1) & loBound(tp2), hiBound(tp1) & hiBound(tp2))
3981
3997
else range(loBound(tp1) | loBound(tp2), hiBound(tp1) | hiBound(tp2))
3982
3998
else tp.derivedAndOrType(tp1, tp2)
3999
+
3983
4000
override protected def derivedAnnotatedType (tp : AnnotatedType , underlying : Type , annot : Annotation ) =
3984
4001
underlying match {
3985
4002
case Range (lo, hi) =>
@@ -3991,6 +4008,7 @@ object Types {
3991
4008
override protected def derivedWildcardType (tp : WildcardType , bounds : Type ) = {
3992
4009
tp.derivedWildcardType(rangeToBounds(bounds))
3993
4010
}
4011
+
3994
4012
override protected def derivedClassInfo (tp : ClassInfo , pre : Type ): Type = {
3995
4013
assert(! pre.isInstanceOf [Range ])
3996
4014
tp.derivedClassInfo(pre)
0 commit comments