@@ -543,7 +543,8 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
543543 end postProcess
544544 end setupTraverser
545545
546- private def superTypeIsImpure (tp : Type )(using Context ): Boolean = {
546+ /** Checks whether an abstract type could be impure. See also: [[needsVariable ]]. */
547+ private def instanceCanBeImpure (tp : Type )(using Context ): Boolean = {
547548 tp.dealiasKeepAnnots match
548549 case CapturingType (_, refs) =>
549550 ! refs.isAlwaysEmpty
@@ -552,20 +553,21 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
552553 case tp : (TypeRef | AppliedType ) =>
553554 val sym = tp.typeSymbol
554555 if sym.isClass then
555- sym == defn.AnyClass || ! sym.isPureClass
556+ sym == defn.AnyClass
556557 // we assume Any is a shorthand of {cap} Any, so if Any is an upper
557558 // bound, the type is taken to be impure.
559+ || ! sym.isPureClass
558560 else
559- sym != defn.Caps_Cap && superTypeIsImpure (tp.superType)
561+ sym != defn.Caps_Cap && instanceCanBeImpure (tp.superType)
560562 case tp : (RefinedOrRecType | MatchType ) =>
561- superTypeIsImpure (tp.underlying)
563+ instanceCanBeImpure (tp.underlying)
562564 case tp : AndType =>
563- superTypeIsImpure (tp.tp1) || superTypeIsImpure (tp.tp2)
565+ instanceCanBeImpure (tp.tp1) || instanceCanBeImpure (tp.tp2)
564566 case tp : OrType =>
565- superTypeIsImpure (tp.tp1) && superTypeIsImpure (tp.tp2)
567+ instanceCanBeImpure (tp.tp1) && instanceCanBeImpure (tp.tp2)
566568 case _ =>
567569 false
568- }.showing(i " super type is impure $tp = $result" , capt)
570+ }.showing(i " instance can be impure $tp = $result" , capt)
569571
570572 /** Should a capture set variable be added on type `tp`? */
571573 def needsVariable (tp : Type )(using Context ): Boolean = {
@@ -577,7 +579,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
577579 else
578580 val tp1 = tp.dealiasKeepAnnots
579581 if tp1 ne tp then needsVariable(tp1)
580- else superTypeIsImpure (tp1)
582+ else instanceCanBeImpure (tp1)
581583 case tp : (RefinedOrRecType | MatchType ) =>
582584 needsVariable(tp.underlying)
583585 case tp : AndType =>
0 commit comments