@@ -163,12 +163,11 @@ object Types {
163
163
* Like in isStableMember, "stability" means idempotence.
164
164
* Rationale: If an expression has a stable type, the expression must be idempotent, so stable types
165
165
* must be singleton types of stable expressions. */
166
- final def isStable (using Context ): Boolean = stripTypeVar match {
166
+ final def isStable (using Context ): Boolean = stripped match {
167
167
case tp : TermRef => tp.symbol.isStableMember && tp.prefix.isStable || tp.info.isStable
168
168
case _ : SingletonType | NoPrefix => true
169
169
case tp : RefinedOrRecType => tp.parent.isStable
170
170
case tp : ExprType => tp.resultType.isStable
171
- case tp : AnnotatedType => tp.parent.isStable
172
171
case tp : AndType =>
173
172
tp.tp1.isStable && (realizability(tp.tp2) eq Realizable ) ||
174
173
tp.tp2.isStable && (realizability(tp.tp1) eq Realizable )
@@ -181,7 +180,7 @@ object Types {
181
180
* It makes no sense for it to be an alias type because isRef would always
182
181
* return false in that case.
183
182
*/
184
- def isRef (sym : Symbol , skipRefined : Boolean = true )(using Context ): Boolean = stripAnnots.stripTypeVar match {
183
+ def isRef (sym : Symbol , skipRefined : Boolean = true )(using Context ): Boolean = stripped match {
185
184
case this1 : TypeRef =>
186
185
this1.info match { // see comment in Namer#typeDefSig
187
186
case TypeAlias (tp) => tp.isRef(sym, skipRefined)
@@ -196,7 +195,7 @@ object Types {
196
195
case _ => false
197
196
}
198
197
199
- /** Is this type a (neither aliased nor applied) reference to class `sym`? */
198
+ /** Is this type a (neither aliased nor applied nor annotated ) reference to class `sym`? */
200
199
def isDirectRef (sym : Symbol )(using Context ): Boolean = stripTypeVar match {
201
200
case this1 : TypeRef =>
202
201
this1.name == sym.name && // avoid forcing info if names differ
@@ -214,7 +213,7 @@ object Types {
214
213
/** Does this type refer exactly to class symbol `sym`, instead of to a subclass of `sym`?
215
214
* Implemented like `isRef`, but follows more types: all type proxies as well as and- and or-types
216
215
*/
217
- private [Types ] def isTightPrefix (sym : Symbol )(using Context ): Boolean = stripTypeVar match {
216
+ private [Types ] def isTightPrefix (sym : Symbol )(using Context ): Boolean = stripped match {
218
217
case tp : NamedType => tp.info.isTightPrefix(sym)
219
218
case tp : ClassInfo => tp.cls eq sym
220
219
case tp : Types .ThisType => tp.cls eq sym
@@ -369,7 +368,7 @@ object Types {
369
368
370
369
/** Is this a match type or a higher-kinded abstraction of one?
371
370
*/
372
- def isMatch (using Context ): Boolean = stripTypeVar.stripAnnots match {
371
+ def isMatch (using Context ): Boolean = stripped match {
373
372
case _ : MatchType => true
374
373
case tp : HKTypeLambda => tp.resType.isMatch
375
374
case _ => false
@@ -1070,9 +1069,12 @@ object Types {
1070
1069
def stripTypeVar (using Context ): Type = this
1071
1070
1072
1071
/** Remove all AnnotatedTypes wrapping this type.
1073
- */
1072
+ */
1074
1073
def stripAnnots (using Context ): Type = this
1075
1074
1075
+ /** Strip TypeVars and Annotation wrappers */
1076
+ def stripped (using Context ): Type = this
1077
+
1076
1078
def rewrapAnnots (tp : Type )(using Context ): Type = tp.stripTypeVar match {
1077
1079
case AnnotatedType (tp1, annot) => AnnotatedType (rewrapAnnots(tp1), annot)
1078
1080
case _ => this
@@ -1105,7 +1107,7 @@ object Types {
1105
1107
case tp : SingletonType => tp.underlying.widen
1106
1108
case tp : ExprType => tp.resultType.widen
1107
1109
case tp =>
1108
- val tp1 = tp.stripTypeVar.stripAnnots
1110
+ val tp1 = tp.stripped
1109
1111
if tp1 eq tp then tp
1110
1112
else
1111
1113
val tp2 = tp1.widen
@@ -1114,7 +1116,7 @@ object Types {
1114
1116
/** Widen from singleton type to its underlying non-singleton
1115
1117
* base type by applying one or more `underlying` dereferences.
1116
1118
*/
1117
- final def widenSingleton (using Context ): Type = stripTypeVar.stripAnnots match {
1119
+ final def widenSingleton (using Context ): Type = stripped match {
1118
1120
case tp : SingletonType if ! tp.isOverloaded => tp.underlying.widenSingleton
1119
1121
case _ => this
1120
1122
}
@@ -1805,6 +1807,9 @@ object Types {
1805
1807
if (hash == NotCached ) System .identityHashCode(this ) else hash
1806
1808
}
1807
1809
1810
+ abstract class StrippableProxyType extends CachedProxyType :
1811
+ override def stripped (using Context ): Type = stripAnnots.stripTypeVar.stripped
1812
+
1808
1813
/** Instances of this class are uncached and are not proxies. */
1809
1814
abstract class UncachedGroundType extends Type {
1810
1815
final def hash : Int = NotCached
@@ -4198,7 +4203,7 @@ object Types {
4198
4203
* @param origin The parameter that's tracked by the type variable.
4199
4204
* @param creatorState The typer state in which the variable was created.
4200
4205
*/
4201
- final class TypeVar private (initOrigin : TypeParamRef , creatorState : TyperState , nestingLevel : Int ) extends CachedProxyType with ValueType {
4206
+ final class TypeVar private (initOrigin : TypeParamRef , creatorState : TyperState , nestingLevel : Int ) extends StrippableProxyType with ValueType {
4202
4207
4203
4208
private var currentOrigin = initOrigin
4204
4209
@@ -4692,7 +4697,7 @@ object Types {
4692
4697
// ----- Annotated and Import types -----------------------------------------------
4693
4698
4694
4699
/** An annotated type tpe @ annot */
4695
- abstract case class AnnotatedType (parent : Type , annot : Annotation ) extends CachedProxyType with ValueType {
4700
+ abstract case class AnnotatedType (parent : Type , annot : Annotation ) extends StrippableProxyType with ValueType {
4696
4701
4697
4702
override def underlying (using Context ): Type = parent
4698
4703
0 commit comments