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