@@ -118,7 +118,7 @@ object Types {
118
118
t.symbol.is(Provisional ) ||
119
119
apply(x, t.prefix) || {
120
120
t.info match {
121
- case TypeAlias (alias) => apply(x, alias)
121
+ case info : AliasingBounds => apply(x, info. alias)
122
122
case TypeBounds (lo, hi) => apply(apply(x, lo), hi)
123
123
case _ => false
124
124
}
@@ -319,7 +319,7 @@ object Types {
319
319
}
320
320
321
321
/** Is this an alias TypeBounds? */
322
- final def isAlias : Boolean = this .isInstanceOf [TypeAlias ]
322
+ final def isTypeAlias : Boolean = this .isInstanceOf [TypeAlias ]
323
323
324
324
/** Is this a MethodType which is from Java */
325
325
def isJavaMethod : Boolean = false
@@ -628,8 +628,8 @@ object Types {
628
628
val rinfo = tp.refinedInfo
629
629
if (name.isTypeName && ! pinfo.isInstanceOf [ClassInfo ]) { // simplified case that runs more efficiently
630
630
val jointInfo =
631
- if (rinfo.isAlias ) rinfo
632
- else if (pinfo.isAlias ) pinfo
631
+ if (rinfo.isTypeAlias ) rinfo
632
+ else if (pinfo.isTypeAlias ) pinfo
633
633
else if (ctx.base.pendingMemberSearches.contains(name)) pinfo safe_& rinfo
634
634
else pinfo recoverable_& rinfo
635
635
pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, jointInfo)
@@ -1238,7 +1238,7 @@ object Types {
1238
1238
*/
1239
1239
@ tailrec final def normalizedPrefix (implicit ctx : Context ): Type = this match {
1240
1240
case tp : NamedType =>
1241
- if (tp.symbol.info.isAlias ) tp.info.normalizedPrefix else tp.prefix
1241
+ if (tp.symbol.info.isTypeAlias ) tp.info.normalizedPrefix else tp.prefix
1242
1242
case tp : ClassInfo =>
1243
1243
tp.prefix
1244
1244
case tp : TypeProxy =>
@@ -3085,8 +3085,8 @@ object Types {
3085
3085
3086
3086
def derivedLambdaAbstraction (paramNames : List [TypeName ], paramInfos : List [TypeBounds ], resType : Type )(implicit ctx : Context ): Type =
3087
3087
resType match {
3088
- case resType @ TypeAlias (alias) =>
3089
- resType.derivedTypeAlias (newLikeThis(paramNames, paramInfos, alias))
3088
+ case resType : AliasingBounds =>
3089
+ resType.derivedAlias (newLikeThis(paramNames, paramInfos, resType. alias))
3090
3090
case resType @ TypeBounds (lo, hi) =>
3091
3091
resType.derivedTypeBounds(
3092
3092
if (lo.isRef(defn.NothingClass )) lo else newLikeThis(paramNames, paramInfos, lo),
@@ -3187,8 +3187,8 @@ object Types {
3187
3187
override def fromParams [PI <: ParamInfo .Of [TypeName ]](params : List [PI ], resultType : Type )(implicit ctx : Context ): Type = {
3188
3188
def expand (tp : Type ) = super .fromParams(params, tp)
3189
3189
resultType match {
3190
- case rt : TypeAlias =>
3191
- rt.derivedTypeAlias (expand(rt.alias))
3190
+ case rt : AliasingBounds =>
3191
+ rt.derivedAlias (expand(rt.alias))
3192
3192
case rt @ TypeBounds (lo, hi) =>
3193
3193
rt.derivedTypeBounds(
3194
3194
if (lo.isRef(defn.NothingClass )) lo else expand(lo), expand(hi))
@@ -3526,6 +3526,14 @@ object Types {
3526
3526
3527
3527
// ------ MatchType ---------------------------------------------------------------
3528
3528
3529
+ /** scrutinee match { case_1 ... case_n }
3530
+ *
3531
+ * where
3532
+ *
3533
+ * case_i = [X1, ..., Xn] patternType => resultType
3534
+ *
3535
+ * and `X_1,...X_n` are the type variables bound in `patternType`
3536
+ */
3529
3537
abstract case class MatchType (scrutinee : Type , cases : List [Type ]) extends CachedProxyType with TermType {
3530
3538
override def computeHash (bs : Binders ) = doHash(bs, scrutinee, cases)
3531
3539
@@ -3781,51 +3789,64 @@ object Types {
3781
3789
case _ => super .| (that)
3782
3790
}
3783
3791
3784
- def effectiveLo (implicit ctx : Context ) =
3785
- if (hi.isMatch) hi else lo
3786
-
3787
3792
override def computeHash (bs : Binders ) = doHash(bs, lo, hi)
3788
3793
override def stableHash = lo.stableHash && hi.stableHash
3789
3794
3790
3795
override def equals (that : Any ): Boolean = equals(that, null )
3791
3796
3792
3797
override def iso (that : Any , bs : BinderPairs ): Boolean = that match {
3793
- case that : TypeAlias => false
3798
+ case that : AliasingBounds => false
3794
3799
case that : TypeBounds => lo.equals(that.lo, bs) && hi.equals(that.hi, bs)
3795
3800
case _ => false
3796
3801
}
3797
3802
3798
3803
override def eql (that : Type ) = that match {
3799
- case that : TypeAlias => false
3804
+ case that : AliasingBounds => false
3800
3805
case that : TypeBounds => lo.eq(that.lo) && hi.eq(that.hi)
3801
3806
case _ => false
3802
3807
}
3803
3808
}
3804
3809
3805
3810
class RealTypeBounds (lo : Type , hi : Type ) extends TypeBounds (lo, hi)
3806
3811
3807
- abstract class TypeAlias (val alias : Type ) extends TypeBounds (alias, alias) {
3812
+ /** Common supertype of `TypeAlias` and `MatchAlias` */
3813
+ abstract class AliasingBounds (val alias : Type ) extends TypeBounds (alias, alias) {
3808
3814
3809
- /** pre: this is a type alias */
3810
- def derivedTypeAlias (alias : Type )(implicit ctx : Context ) =
3811
- if (alias eq this .alias) this else TypeAlias (alias)
3815
+ def derivedAlias (alias : Type )(implicit ctx : Context ): AliasingBounds
3812
3816
3813
3817
override def computeHash (bs : Binders ) = doHash(bs, alias)
3814
3818
override def stableHash = alias.stableHash
3815
3819
3816
3820
override def iso (that : Any , bs : BinderPairs ): Boolean = that match {
3817
- case that : TypeAlias => alias.equals(that.alias, bs)
3821
+ case that : AliasingBounds => this .isTypeAlias == that.isTypeAlias && alias.equals(that.alias, bs)
3818
3822
case _ => false
3819
3823
}
3820
3824
// equals comes from case class; no matching override is needed
3821
3825
3822
3826
override def eql (that : Type ): Boolean = that match {
3823
- case that : TypeAlias => alias.eq(that.alias)
3827
+ case that : AliasingBounds => this .isTypeAlias == that.isTypeAlias && alias.eq(that.alias)
3824
3828
case _ => false
3825
3829
}
3826
3830
}
3827
3831
3828
- class CachedTypeAlias (alias : Type ) extends TypeAlias (alias)
3832
+ /** = T
3833
+ */
3834
+ class TypeAlias (alias : Type ) extends AliasingBounds (alias) {
3835
+ def derivedAlias (alias : Type )(implicit ctx : Context ) =
3836
+ if (alias eq this .alias) this else TypeAlias (alias)
3837
+ }
3838
+
3839
+ /** = T where `T` is a `MatchType`
3840
+ *
3841
+ * Match aliases are treated differently from type aliases. Their sides are mutually
3842
+ * subtypes of each other but one side is not generally substitutable for the other.
3843
+ * If we assumed full substitutivity, we would have to reject all recursive match
3844
+ * aliases (or else take the jump and allow full recursive types).
3845
+ */
3846
+ class MatchAlias (alias : Type ) extends AliasingBounds (alias) {
3847
+ def derivedAlias (alias : Type )(implicit ctx : Context ) =
3848
+ if (alias eq this .alias) this else MatchAlias (alias)
3849
+ }
3829
3850
3830
3851
object TypeBounds {
3831
3852
def apply (lo : Type , hi : Type )(implicit ctx : Context ): TypeBounds =
@@ -3836,11 +3857,15 @@ object Types {
3836
3857
}
3837
3858
3838
3859
object TypeAlias {
3839
- def apply (alias : Type )(implicit ctx : Context ) =
3840
- unique(new CachedTypeAlias (alias))
3860
+ def apply (alias : Type )(implicit ctx : Context ) = unique(new TypeAlias (alias))
3841
3861
def unapply (tp : TypeAlias ): Option [Type ] = Some (tp.alias)
3842
3862
}
3843
3863
3864
+ object MatchAlias {
3865
+ def apply (alias : Type )(implicit ctx : Context ) = unique(new MatchAlias (alias))
3866
+ def unapply (tp : MatchAlias ): Option [Type ] = Some (tp.alias)
3867
+ }
3868
+
3844
3869
// ----- Annotated and Import types -----------------------------------------------
3845
3870
3846
3871
/** An annotated type tpe @ annot */
@@ -4042,8 +4067,8 @@ object Types {
4042
4067
def apply (tp : Type ): Type = tp match {
4043
4068
case tp : TypeRef if tp.symbol.is(ClassTypeParam ) && tp.symbol.owner == cls =>
4044
4069
tp.info match {
4045
- case TypeAlias (alias) =>
4046
- mapOver(alias)
4070
+ case info : AliasingBounds =>
4071
+ mapOver(info. alias)
4047
4072
case TypeBounds (lo, hi) =>
4048
4073
range(atVariance(- variance)(apply(lo)), apply(hi))
4049
4074
case _ =>
@@ -4099,8 +4124,8 @@ object Types {
4099
4124
tp.derivedRefinedType(parent, tp.refinedName, info)
4100
4125
protected def derivedRecType (tp : RecType , parent : Type ): Type =
4101
4126
tp.rebind(parent)
4102
- protected def derivedTypeAlias (tp : TypeAlias , alias : Type ): Type =
4103
- tp.derivedTypeAlias (alias)
4127
+ protected def derivedAlias (tp : AliasingBounds , alias : Type ): Type =
4128
+ tp.derivedAlias (alias)
4104
4129
protected def derivedTypeBounds (tp : TypeBounds , lo : Type , hi : Type ): Type =
4105
4130
tp.derivedTypeBounds(lo, hi)
4106
4131
protected def derivedSuperType (tp : SuperType , thistp : Type , supertp : Type ): Type =
@@ -4167,8 +4192,8 @@ object Types {
4167
4192
case tp : RefinedType =>
4168
4193
derivedRefinedType(tp, this (tp.parent), this (tp.refinedInfo))
4169
4194
4170
- case tp : TypeAlias =>
4171
- derivedTypeAlias (tp, atVariance(0 )(this (tp.alias)))
4195
+ case tp : AliasingBounds =>
4196
+ derivedAlias (tp, atVariance(0 )(this (tp.alias)))
4172
4197
4173
4198
case tp : TypeBounds =>
4174
4199
variance = - variance
@@ -4387,7 +4412,7 @@ object Types {
4387
4412
else info match {
4388
4413
case Range (infoLo : TypeBounds , infoHi : TypeBounds ) =>
4389
4414
assert(variance == 0 )
4390
- if (! infoLo.isAlias && ! infoHi.isAlias ) propagate(infoLo, infoHi)
4415
+ if (! infoLo.isTypeAlias && ! infoHi.isTypeAlias ) propagate(infoLo, infoHi)
4391
4416
else range(defn.NothingType , tp.parent)
4392
4417
case Range (infoLo, infoHi) =>
4393
4418
propagate(infoLo, infoHi)
@@ -4403,13 +4428,13 @@ object Types {
4403
4428
case _ => tp.rebind(parent)
4404
4429
}
4405
4430
4406
- override protected def derivedTypeAlias (tp : TypeAlias , alias : Type ) =
4431
+ override protected def derivedAlias (tp : AliasingBounds , alias : Type ) =
4407
4432
if (alias eq tp.alias) tp
4408
4433
else alias match {
4409
4434
case Range (lo, hi) =>
4410
4435
if (variance > 0 ) TypeBounds (lo, hi)
4411
- else range(TypeAlias (lo), TypeAlias (hi))
4412
- case _ => tp.derivedTypeAlias (alias)
4436
+ else range(tp.derivedAlias (lo), tp.derivedAlias (hi))
4437
+ case _ => tp.derivedAlias (alias)
4413
4438
}
4414
4439
4415
4440
override protected def derivedTypeBounds (tp : TypeBounds , lo : Type , hi : Type ) =
0 commit comments