@@ -3891,6 +3891,9 @@ object Types {
38913891 case class Range (lo : Type , hi : Type ) extends UncachedGroundType {
38923892 assert(! lo.isInstanceOf [Range ])
38933893 assert(! hi.isInstanceOf [Range ])
3894+
3895+ override def toText (printer : Printer ): Text =
3896+ lo.toText(printer) ~ " .." ~ hi.toText(printer)
38943897 }
38953898
38963899 /** A type map that approximates TypeBounds types depending on
@@ -3925,14 +3928,23 @@ object Types {
39253928 case _ => tp
39263929 }
39273930
3931+ def atVariance [T ](v : Int )(op : => T ): T = {
3932+ val saved = variance
3933+ variance = v
3934+ try op finally variance = saved
3935+ }
3936+
39283937 override protected def derivedSelect (tp : NamedType , pre : Type ) =
39293938 if (pre eq tp.prefix) tp
39303939 else pre match {
39313940 case Range (preLo, preHi) =>
39323941 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))
39363948 }
39373949 case _ => tp.derivedSelect(pre)
39383950 }
@@ -3950,23 +3962,27 @@ object Types {
39503962 tp.derivedRefinedType(parent, tp.refinedName, rangeToBounds(info))
39513963 }
39523964 }
3965+
39533966 override protected def derivedRecType (tp : RecType , parent : Type ) =
39543967 parent match {
39553968 case Range (lo, hi) => range(tp.rebind(lo), tp.rebind(hi))
39563969 case _ => tp.rebind(parent)
39573970 }
3971+
39583972 override protected def derivedTypeAlias (tp : TypeAlias , alias : Type ) =
39593973 alias match {
39603974 case Range (lo, hi) =>
39613975 if (variance > 0 ) TypeBounds (lo, hi)
39623976 else range(TypeAlias (lo), TypeAlias (hi))
39633977 case _ => tp.derivedTypeAlias(alias)
39643978 }
3979+
39653980 override protected def derivedTypeBounds (tp : TypeBounds , lo : Type , hi : Type ) =
39663981 if (isRange(lo) || isRange(hi))
39673982 if (variance > 0 ) TypeBounds (loBound(lo), hiBound(hi))
39683983 else range(TypeBounds (hiBound(lo), loBound(hi)), TypeBounds (loBound(lo), hiBound(hi)))
39693984 else tp.derivedTypeBounds(lo, hi)
3985+
39703986 override protected def derivedSuperType (tp : SuperType , thistp : Type , supertp : Type ) =
39713987 if (isRange(thistp) || isRange(supertp)) range()
39723988 else tp.derivedSuperType(thistp, supertp)
@@ -4006,6 +4022,7 @@ object Types {
40064022 if (tp.isAnd) range(loBound(tp1) & loBound(tp2), hiBound(tp1) & hiBound(tp2))
40074023 else range(loBound(tp1) | loBound(tp2), hiBound(tp1) | hiBound(tp2))
40084024 else tp.derivedAndOrType(tp1, tp2)
4025+
40094026 override protected def derivedAnnotatedType (tp : AnnotatedType , underlying : Type , annot : Annotation ) =
40104027 underlying match {
40114028 case Range (lo, hi) =>
@@ -4017,6 +4034,7 @@ object Types {
40174034 override protected def derivedWildcardType (tp : WildcardType , bounds : Type ) = {
40184035 tp.derivedWildcardType(rangeToBounds(bounds))
40194036 }
4037+
40204038 override protected def derivedClassInfo (tp : ClassInfo , pre : Type ): Type = {
40214039 assert(! pre.isInstanceOf [Range ])
40224040 tp.derivedClassInfo(pre)
0 commit comments