@@ -392,18 +392,13 @@ object Types {
392
392
final def foreachPart (p : Type => Unit , stopAtStatic : Boolean = false )(using Context ): Unit =
393
393
new ForeachAccumulator (p, stopAtStatic).apply((), this )
394
394
395
- /** The parts of this type which are type or term refs */
396
- final def namedParts (using Context ): collection.Set [NamedType ] =
397
- namedPartsWith(alwaysTrue)
398
-
399
395
/** The parts of this type which are type or term refs and which
400
396
* satisfy predicate `p`.
401
397
*
402
398
* @param p The predicate to satisfy
403
399
*/
404
- def namedPartsWith (p : NamedType => Boolean )
405
- (using Context ): collection.Set [NamedType ] =
406
- new NamedPartsAccumulator (p).apply(mutable.LinkedHashSet (), this )
400
+ def namedPartsWith (p : NamedType => Boolean )(using Context ): List [NamedType ] =
401
+ new NamedPartsAccumulator (p).apply(Nil , this )
407
402
408
403
/** Map function `f` over elements of an AndType, rebuilding with function `g` */
409
404
def mapReduceAnd [T ](f : Type => T )(g : (T , T ) => T )(using Context ): T = stripTypeVar match {
@@ -5519,36 +5514,33 @@ object Types {
5519
5514
override def isEqual (x : Type , y : Type ) = x.eq(y)
5520
5515
5521
5516
class NamedPartsAccumulator (p : NamedType => Boolean )(using Context )
5522
- extends TypeAccumulator [mutable. Set [NamedType ]] {
5523
- def maybeAdd (x : mutable. Set [NamedType ], tp : NamedType ): mutable. Set [NamedType ] = if ( p(tp)) x += tp else x
5517
+ extends TypeAccumulator [List [NamedType ]]:
5518
+ def maybeAdd (xs : List [NamedType ], tp : NamedType ): List [NamedType ] = if p(tp) then tp :: xs else xs
5524
5519
val seen = TypeHashSet ()
5525
- def apply (x : mutable. Set [NamedType ], tp : Type ): mutable. Set [NamedType ] =
5526
- if ( seen contains tp) x
5527
- else {
5520
+ def apply (xs : List [NamedType ], tp : Type ): List [NamedType ] =
5521
+ if seen contains tp then xs
5522
+ else
5528
5523
seen.addEntry(tp)
5529
- tp match {
5524
+ tp match
5530
5525
case tp : TypeRef =>
5531
- foldOver(maybeAdd(x , tp), tp)
5526
+ foldOver(maybeAdd(xs , tp), tp)
5532
5527
case tp : ThisType =>
5533
- apply(x , tp.tref)
5528
+ apply(xs , tp.tref)
5534
5529
case NoPrefix =>
5535
- foldOver(x , tp)
5530
+ foldOver(xs , tp)
5536
5531
case tp : TermRef =>
5537
- apply(foldOver(maybeAdd(x , tp), tp), tp.underlying)
5532
+ apply(foldOver(maybeAdd(xs , tp), tp), tp.underlying)
5538
5533
case tp : AppliedType =>
5539
- foldOver(x , tp)
5534
+ foldOver(xs , tp)
5540
5535
case TypeBounds (lo, hi) =>
5541
- apply(x, lo)
5542
- apply(x, hi)
5536
+ apply(apply(xs, lo), hi)
5543
5537
case tp : ParamRef =>
5544
- apply(x , tp.underlying)
5538
+ apply(xs , tp.underlying)
5545
5539
case tp : ConstantType =>
5546
- apply(x , tp.underlying)
5540
+ apply(xs , tp.underlying)
5547
5541
case _ =>
5548
- foldOver(x, tp)
5549
- }
5550
- }
5551
- }
5542
+ foldOver(xs, tp)
5543
+ end NamedPartsAccumulator
5552
5544
5553
5545
class isGroundAccumulator (using Context ) extends TypeAccumulator [Boolean ] {
5554
5546
def apply (x : Boolean , tp : Type ): Boolean = x && {
0 commit comments