@@ -171,7 +171,7 @@ object Types {
171
171
case this1 : RefinedOrRecType =>
172
172
this1.parent.isRef(sym)
173
173
case this1 : AppliedType =>
174
- val this2 = this1.dealias
174
+ val this2 = this1.dealiasStripAnnots
175
175
if (this2 ne this1) this2.isRef(sym)
176
176
else this1.underlying.isRef(sym)
177
177
case _ => false
@@ -244,7 +244,7 @@ object Types {
244
244
}
245
245
246
246
/** Is this type a (possibly aliased) singleton type? */
247
- def isSingleton (implicit ctx : Context ) = dealias .isInstanceOf [SingletonType ]
247
+ def isSingleton (implicit ctx : Context ) = dealiasStripAnnots .isInstanceOf [SingletonType ]
248
248
249
249
/** Is this type of kind `AnyKind`? */
250
250
def hasAnyKind (implicit ctx : Context ): Boolean = {
@@ -931,6 +931,11 @@ object Types {
931
931
*/
932
932
def stripAnnots (implicit ctx : Context ): Type = this
933
933
934
+ def rewrapAnnots (tp : Type )(implicit ctx : Context ): Type = tp.stripTypeVar match {
935
+ case AnnotatedType (tp1, annot) => AnnotatedType (rewrapAnnots(tp1), annot)
936
+ case _ => this
937
+ }
938
+
934
939
/** Strip PolyType prefix */
935
940
def stripPoly (implicit ctx : Context ): Type = this match {
936
941
case tp : PolyType => tp.resType.stripPoly
@@ -1046,18 +1051,21 @@ object Types {
1046
1051
final def dealiasKeepAnnots (implicit ctx : Context ): Type =
1047
1052
dealias1(keepAnnots = true )
1048
1053
1054
+ final def dealias (implicit ctx : Context ): Type = dealiasStripAnnots
1055
+
1049
1056
/** Follow aliases and dereferences LazyRefs, annotated types and instantiated
1050
1057
* TypeVars until type is no longer alias type, annotated type, LazyRef,
1051
1058
* or instantiated type variable.
1052
1059
*/
1053
- final def dealias (implicit ctx : Context ): Type =
1060
+ final def dealiasStripAnnots (implicit ctx : Context ): Type =
1054
1061
dealias1(keepAnnots = false )
1055
1062
1056
1063
/** Perform successive widenings and dealiasings until none can be applied anymore */
1057
- @ tailrec final def widenDealias (implicit ctx : Context ): Type = {
1058
- val res = this .widen.dealias
1059
- if (res eq this ) res else res.widenDealias
1064
+ @ tailrec final def widenDealiasStripAnnots (implicit ctx : Context ): Type = {
1065
+ val res = this .widen.dealiasStripAnnots
1066
+ if (res eq this ) res else res.widenDealiasStripAnnots
1060
1067
}
1068
+ final def widenDealias (implicit ctx : Context ): Type = widenDealiasStripAnnots
1061
1069
1062
1070
/** Widen from constant type to its underlying non-constant
1063
1071
* base type.
@@ -1068,7 +1076,7 @@ object Types {
1068
1076
}
1069
1077
1070
1078
/** Dealias, and if result is a dependent function type, drop the `apply` refinement. */
1071
- final def dropDependentRefinement (implicit ctx : Context ): Type = dealias match {
1079
+ final def dropDependentRefinement (implicit ctx : Context ): Type = dealiasStripAnnots match {
1072
1080
case RefinedType (parent, nme.apply, _) => parent
1073
1081
case tp => tp
1074
1082
}
@@ -1083,7 +1091,7 @@ object Types {
1083
1091
* a class, the class type ref, otherwise NoType.
1084
1092
* @param refinementOK If `true` we also skip refinements.
1085
1093
*/
1086
- def underlyingClassRef (refinementOK : Boolean )(implicit ctx : Context ): Type = dealias match {
1094
+ def underlyingClassRef (refinementOK : Boolean )(implicit ctx : Context ): Type = dealiasStripAnnots match {
1087
1095
case tp : TypeRef =>
1088
1096
if (tp.symbol.isClass) tp
1089
1097
else if (tp.symbol.isAliasType) tp.underlying.underlyingClassRef(refinementOK)
@@ -1805,8 +1813,8 @@ object Types {
1805
1813
case arg : TypeBounds =>
1806
1814
val v = param.paramVariance
1807
1815
val pbounds = param.paramInfo
1808
- if (v > 0 && pbounds.loBound.dealias .isBottomType) TypeAlias (arg.hiBound & rebase(pbounds.hiBound))
1809
- else if (v < 0 && pbounds.hiBound.dealias .isTopType) TypeAlias (arg.loBound | rebase(pbounds.loBound))
1816
+ if (v > 0 && pbounds.loBound.dealiasKeepAnnots .isBottomType) TypeAlias (arg.hiBound & rebase(pbounds.hiBound))
1817
+ else if (v < 0 && pbounds.hiBound.dealiasKeepAnnots .isTopType) TypeAlias (arg.loBound | rebase(pbounds.loBound))
1810
1818
else arg recoverable_& rebase(pbounds)
1811
1819
case arg => TypeAlias (arg)
1812
1820
}
@@ -4165,11 +4173,12 @@ object Types {
4165
4173
*/
4166
4174
def tryWiden (tp : NamedType , pre : Type ): Type = pre.member(tp.name) match {
4167
4175
case d : SingleDenotation =>
4168
- d.info.dealias match {
4176
+ val tp1 = d.info.dealiasKeepAnnots
4177
+ tp1.stripAnnots match {
4169
4178
case TypeAlias (alias) =>
4170
4179
// if H#T = U, then for any x in L..H, x.T =:= U,
4171
4180
// hence we can replace with U under all variances
4172
- reapply(alias)
4181
+ reapply(alias.rewrapAnnots(tp1) )
4173
4182
case TypeBounds (lo, hi) =>
4174
4183
// If H#T = _ >: S <: U, then for any x in L..H, S <: x.T <: U,
4175
4184
// hence we can replace with S..U under all variances
0 commit comments