@@ -543,7 +543,8 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
543
543
end postProcess
544
544
end setupTraverser
545
545
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 = {
547
548
tp.dealiasKeepAnnots match
548
549
case CapturingType (_, refs) =>
549
550
! refs.isAlwaysEmpty
@@ -552,20 +553,21 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
552
553
case tp : (TypeRef | AppliedType ) =>
553
554
val sym = tp.typeSymbol
554
555
if sym.isClass then
555
- sym == defn.AnyClass || ! sym.isPureClass
556
+ sym == defn.AnyClass
556
557
// we assume Any is a shorthand of {cap} Any, so if Any is an upper
557
558
// bound, the type is taken to be impure.
559
+ || ! sym.isPureClass
558
560
else
559
- sym != defn.Caps_Cap && superTypeIsImpure (tp.superType)
561
+ sym != defn.Caps_Cap && instanceCanBeImpure (tp.superType)
560
562
case tp : (RefinedOrRecType | MatchType ) =>
561
- superTypeIsImpure (tp.underlying)
563
+ instanceCanBeImpure (tp.underlying)
562
564
case tp : AndType =>
563
- superTypeIsImpure (tp.tp1) || superTypeIsImpure (tp.tp2)
565
+ instanceCanBeImpure (tp.tp1) || instanceCanBeImpure (tp.tp2)
564
566
case tp : OrType =>
565
- superTypeIsImpure (tp.tp1) && superTypeIsImpure (tp.tp2)
567
+ instanceCanBeImpure (tp.tp1) && instanceCanBeImpure (tp.tp2)
566
568
case _ =>
567
569
false
568
- }.showing(i " super type is impure $tp = $result" , capt)
570
+ }.showing(i " instance can be impure $tp = $result" , capt)
569
571
570
572
/** Should a capture set variable be added on type `tp`? */
571
573
def needsVariable (tp : Type )(using Context ): Boolean = {
@@ -577,7 +579,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
577
579
else
578
580
val tp1 = tp.dealiasKeepAnnots
579
581
if tp1 ne tp then needsVariable(tp1)
580
- else superTypeIsImpure (tp1)
582
+ else instanceCanBeImpure (tp1)
581
583
case tp : (RefinedOrRecType | MatchType ) =>
582
584
needsVariable(tp.underlying)
583
585
case tp : AndType =>
0 commit comments