@@ -114,6 +114,7 @@ object Types {
114114 case _ : SingletonType | NoPrefix => true
115115 case tp : RefinedOrRecType => tp.parent.isStable
116116 case tp : ExprType => tp.resultType.isStable
117+ case tp : AnnotatedType => tp.tpe.isStable
117118 case _ => false
118119 }
119120
@@ -247,6 +248,9 @@ object Types {
247248 case _ => NoType
248249 }
249250
251+ /** Is this type a (possibly aliased) singleton type? */
252+ def isSingleton (implicit ctx : Context ) = dealias.isInstanceOf [SingletonType ]
253+
250254 /** Is this type guaranteed not to have `null` as a value? */
251255 final def isNotNull (implicit ctx : Context ): Boolean = this match {
252256 case tp : ConstantType => tp.value.value != null
@@ -354,7 +358,6 @@ object Types {
354358 @ tailrec final def typeSymbol (implicit ctx : Context ): Symbol = this match {
355359 case tp : TypeRef => tp.symbol
356360 case tp : ClassInfo => tp.cls
357- // case ThisType(cls) => cls // needed?
358361 case tp : SingletonType => NoSymbol
359362 case tp : TypeProxy => tp.underlying.typeSymbol
360363 case _ => NoSymbol
@@ -918,7 +921,8 @@ object Types {
918921 /** Widen from singleton type to its underlying non-singleton
919922 * base type by applying one or more `underlying` dereferences.
920923 */
921- final def widenSingleton (implicit ctx : Context ): Type = stripTypeVar match {
924+ final def widenSingleton (implicit ctx : Context ): Type = stripTypeVar.stripAnnots match {
925+ // case tp @ AnnotatedType(tp1, ann) => tp.derivedAnnotatedType(tp1.widenSingleton, ann)
922926 case tp : SingletonType if ! tp.isOverloaded => tp.underlying.widenSingleton
923927 case _ => this
924928 }
@@ -3555,16 +3559,18 @@ object Types {
35553559 // ----- Annotated and Import types -----------------------------------------------
35563560
35573561 /** An annotated type tpe @ annot */
3558- case class AnnotatedType (tpe : Type , annot : Annotation )
3559- extends UncachedProxyType with ValueType {
3562+ case class AnnotatedType (tpe : Type , annot : Annotation ) extends UncachedProxyType with ValueType {
35603563 // todo: cache them? but this makes only sense if annotations and trees are also cached.
3564+
35613565 override def underlying (implicit ctx : Context ): Type = tpe
3566+
35623567 def derivedAnnotatedType (tpe : Type , annot : Annotation ) =
35633568 if ((tpe eq this .tpe) && (annot eq this .annot)) this
35643569 else AnnotatedType (tpe, annot)
35653570
35663571 override def stripTypeVar (implicit ctx : Context ): Type =
35673572 derivedAnnotatedType(tpe.stripTypeVar, annot)
3573+
35683574 override def stripAnnots (implicit ctx : Context ): Type = tpe.stripAnnots
35693575 }
35703576
@@ -3965,7 +3971,7 @@ object Types {
39653971 */
39663972 def tryWiden (tp : NamedType , pre : Type ): Type = pre.member(tp.name) match {
39673973 case d : SingleDenotation =>
3968- d.info match {
3974+ d.info.dealias match {
39693975 case TypeAlias (alias) =>
39703976 // if H#T = U, then for any x in L..H, x.T =:= U,
39713977 // hence we can replace with U under all variances
0 commit comments