@@ -5329,7 +5329,7 @@ object Types {
5329
5329
5330
5330
protected def applyToAnnot (x : T , annot : Annotation ): T = x // don't go into annotations
5331
5331
5332
- protected final def applyToPrefix (x : T , tp : NamedType ): T =
5332
+ protected def applyToPrefix (x : T , tp : NamedType ): T =
5333
5333
atVariance(variance max 0 )(this (x, tp.prefix)) // see remark on NamedType case in TypeMap
5334
5334
5335
5335
def foldOver (x : T , tp : Type ): T = {
@@ -5452,15 +5452,29 @@ object Types {
5452
5452
}
5453
5453
5454
5454
class NamedPartsAccumulator (p : NamedType => Boolean ,
5455
- widenSingletons : Boolean = false ,
5455
+ widenSingletons : Boolean = false , // if set, also consider underlying types in singleton path prefixes
5456
5456
excludeLowerBounds : Boolean = false )
5457
5457
(implicit ctx : Context ) extends TypeAccumulator [mutable.Set [NamedType ]] {
5458
+
5458
5459
override def stopAtStatic : Boolean = false
5459
- def maybeAdd (x : mutable.Set [NamedType ], tp : NamedType ): mutable.Set [NamedType ] = if (p(tp)) x += tp else x
5460
+
5461
+ def maybeAdd (x : mutable.Set [NamedType ], tp : NamedType ): mutable.Set [NamedType ] =
5462
+ if (p(tp)) x += tp else x
5463
+
5460
5464
val seen : util.HashSet [Type ] = new util.HashSet [Type ](64 ) {
5461
5465
override def hash (x : Type ): Int = System .identityHashCode(x)
5462
5466
override def isEqual (x : Type , y : Type ) = x.eq(y)
5463
5467
}
5468
+
5469
+ override def applyToPrefix (x : mutable.Set [NamedType ], tp : NamedType ): mutable.Set [NamedType ] =
5470
+ tp.prefix match
5471
+ case pre : TermRef if ! widenSingletons =>
5472
+ foldOver(maybeAdd(x, pre), pre)
5473
+ case pre : ThisType if ! widenSingletons =>
5474
+ x
5475
+ case _ =>
5476
+ super .applyToPrefix(x, tp)
5477
+
5464
5478
def apply (x : mutable.Set [NamedType ], tp : Type ): mutable.Set [NamedType ] =
5465
5479
if (seen contains tp) x
5466
5480
else {
@@ -5469,10 +5483,9 @@ object Types {
5469
5483
case tp : TypeRef =>
5470
5484
foldOver(maybeAdd(x, tp), tp)
5471
5485
case tp : TermRef =>
5472
- val x1 = foldOver(maybeAdd(x, tp), tp)
5473
- if widenSingletons then apply(x1, tp.underlying) else x1
5486
+ apply(foldOver(maybeAdd(x, tp), tp), tp.underlying)
5474
5487
case tp : ThisType =>
5475
- if widenSingletons then apply(x, tp.tref) else x
5488
+ apply(x, tp.tref)
5476
5489
case NoPrefix =>
5477
5490
foldOver(x, tp)
5478
5491
case tp : AppliedType =>
0 commit comments