@@ -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,18 @@ 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
556
- // we assume Any is a shorthand of {cap} Any, so if Any is an upper
557
- // bound, the type is taken to be impure.
556
+ ! sym.isPureClass
558
557
else
559
- sym != defn.Caps_Cap && superTypeIsImpure (tp.superType)
558
+ sym != defn.Caps_Cap && instanceCanBeImpure (tp.superType)
560
559
case tp : (RefinedOrRecType | MatchType ) =>
561
- superTypeIsImpure (tp.underlying)
560
+ instanceCanBeImpure (tp.underlying)
562
561
case tp : AndType =>
563
- superTypeIsImpure (tp.tp1) || superTypeIsImpure (tp.tp2)
562
+ instanceCanBeImpure (tp.tp1) || instanceCanBeImpure (tp.tp2)
564
563
case tp : OrType =>
565
- superTypeIsImpure (tp.tp1) && superTypeIsImpure (tp.tp2)
564
+ instanceCanBeImpure (tp.tp1) && instanceCanBeImpure (tp.tp2)
566
565
case _ =>
567
566
false
568
- }.showing(i " super type is impure $tp = $result" , capt)
567
+ }.showing(i " instance can be impure $tp = $result" , capt)
569
568
570
569
/** Should a capture set variable be added on type `tp`? */
571
570
def needsVariable (tp : Type )(using Context ): Boolean = {
@@ -577,7 +576,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
577
576
else
578
577
val tp1 = tp.dealiasKeepAnnots
579
578
if tp1 ne tp then needsVariable(tp1)
580
- else superTypeIsImpure (tp1)
579
+ else instanceCanBeImpure (tp1)
581
580
case tp : (RefinedOrRecType | MatchType ) =>
582
581
needsVariable(tp.underlying)
583
582
case tp : AndType =>
@@ -708,4 +707,4 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
708
707
def postCheck ()(using Context ): Unit =
709
708
for chk <- todoAtPostCheck do chk(ctx)
710
709
todoAtPostCheck.clear()
711
- end Setup
710
+ end Setup
0 commit comments