@@ -439,23 +439,23 @@ object Types {
439439
440440 /** Does this type contain wildcard types? */
441441 final def containsWildcardTypes (using Context ) =
442- existsPart(_.isInstanceOf [WildcardType ], stopAtStatic = true , forceLazy = false )
442+ existsPart(_.isInstanceOf [WildcardType ], StopAt . Static , forceLazy = false )
443443
444444// ----- Higher-order combinators -----------------------------------
445445
446446 /** Returns true if there is a part of this type that satisfies predicate `p`.
447447 */
448- final def existsPart (p : Type => Boolean , stopAtStatic : Boolean = false , forceLazy : Boolean = true )(using Context ): Boolean =
449- new ExistsAccumulator (p, stopAtStatic , forceLazy).apply(false , this )
448+ final def existsPart (p : Type => Boolean , stopAt : StopAt = StopAt . None , forceLazy : Boolean = true )(using Context ): Boolean =
449+ new ExistsAccumulator (p, stopAt , forceLazy).apply(false , this )
450450
451451 /** Returns true if all parts of this type satisfy predicate `p`.
452452 */
453453 final def forallParts (p : Type => Boolean )(using Context ): Boolean =
454454 ! existsPart(! p(_))
455455
456456 /** Performs operation on all parts of this type */
457- final def foreachPart (p : Type => Unit , stopAtStatic : Boolean = false )(using Context ): Unit =
458- new ForeachAccumulator (p, stopAtStatic ).apply((), this )
457+ final def foreachPart (p : Type => Unit , stopAt : StopAt = StopAt . None )(using Context ): Unit =
458+ new ForeachAccumulator (p, stopAt ).apply((), this )
459459
460460 /** The parts of this type which are type or term refs and which
461461 * satisfy predicate `p`.
@@ -5199,6 +5199,12 @@ object Types {
51995199
52005200 // ----- TypeMaps --------------------------------------------------------------------
52015201
5202+ /** Where a traversal should stop */
5203+ enum StopAt :
5204+ case None // traverse everything
5205+ case Package // stop at package references
5206+ case Static // stop at static references
5207+
52025208 /** Common base class of TypeMap and TypeAccumulator */
52035209 abstract class VariantTraversal :
52045210 protected [core] var variance : Int = 1
@@ -5211,7 +5217,7 @@ object Types {
52115217 res
52125218 }
52135219
5214- protected def stopAtStatic : Boolean = true
5220+ protected def stopAt : StopAt = StopAt . Static
52155221
52165222 /** Can the prefix of this static reference be omitted if the reference
52175223 * itself can be omitted? Overridden in TypeOps#avoid.
@@ -5220,7 +5226,11 @@ object Types {
52205226
52215227 protected def stopBecauseStaticOrLocal (tp : NamedType )(using Context ): Boolean =
52225228 (tp.prefix eq NoPrefix )
5223- || stopAtStatic && tp.currentSymbol.isStatic && isStaticPrefix(tp.prefix)
5229+ || {
5230+ val stop = stopAt
5231+ stop == StopAt .Static && tp.currentSymbol.isStatic && isStaticPrefix(tp.prefix)
5232+ || stop == StopAt .Package && tp.currentSymbol.is(Package )
5233+ }
52245234 end VariantTraversal
52255235
52265236 abstract class TypeMap (implicit protected var mapCtx : Context )
@@ -5409,7 +5419,7 @@ object Types {
54095419 derivedClassInfo(tp, this (tp.prefix))
54105420
54115421 def andThen (f : Type => Type ): TypeMap = new TypeMap {
5412- override def stopAtStatic = thisMap.stopAtStatic
5422+ override def stopAt = thisMap.stopAt
54135423 def apply (tp : Type ) = f(thisMap(tp))
54145424 }
54155425 }
@@ -5831,12 +5841,12 @@ object Types {
58315841
58325842 class ExistsAccumulator (
58335843 p : Type => Boolean ,
5834- override val stopAtStatic : Boolean ,
5844+ override val stopAt : StopAt ,
58355845 forceLazy : Boolean )(using Context ) extends TypeAccumulator [Boolean ]:
58365846 def apply (x : Boolean , tp : Type ): Boolean =
58375847 x || p(tp) || (forceLazy || ! tp.isInstanceOf [LazyRef ]) && foldOver(x, tp)
58385848
5839- class ForeachAccumulator (p : Type => Unit , override val stopAtStatic : Boolean )(using Context ) extends TypeAccumulator [Unit ] {
5849+ class ForeachAccumulator (p : Type => Unit , override val stopAt : StopAt )(using Context ) extends TypeAccumulator [Unit ] {
58405850 def apply (x : Unit , tp : Type ): Unit = foldOver(p(tp), tp)
58415851 }
58425852
0 commit comments