@@ -21,6 +21,7 @@ import compiletime.uninitialized
2121import Capabilities .*
2222import Names .Name
2323import NameKinds .CapsetName
24+ import StdNames .nme
2425
2526/** A class for capture sets. Capture sets can be constants or variables.
2627 * Capture sets support inclusion constraints <:< where <:< is subcapturing.
@@ -1678,6 +1679,8 @@ object CaptureSet:
16781679 // might happen during construction of lambdas, assume `{cap}` in this case so that
16791680 // `ref` will not seem subsumed by other capabilities in a `++`.
16801681 universal
1682+ case c : TermRef if isAssumedPure(c) =>
1683+ CaptureSet .empty
16811684 case c : CoreCapability =>
16821685 ofType(c.underlying, followResult = ccConfig.useSpanCapset)
16831686
@@ -1723,7 +1726,7 @@ object CaptureSet:
17231726 /** The deep capture set of a type is the union of all covariant occurrences of
17241727 * capture sets. Nested existential sets are approximated with `cap`.
17251728 */
1726- def ofTypeDeeply (tp : Type , includeTypevars : Boolean = false , includeBoxed : Boolean = true )(using Context ): CaptureSet =
1729+ def ofTypeDeeply (tp : Type , includeTypevars : Boolean = false , includeBoxed : Boolean = true )(using Context ): CaptureSet = {
17271730 val collect = new DeepTypeAccumulator [CaptureSet ]:
17281731
17291732 def capturingCase (acc : CaptureSet , parent : Type , refs : CaptureSet , boxed : Boolean ) =
@@ -1736,6 +1739,15 @@ object CaptureSet:
17361739 else this (acc, upperBound)
17371740
17381741 collect(CaptureSet .empty, tp)
1742+ }
1743+
1744+ /** Is `ref` assumed to be pure even though it would have a non-empty capture
1745+ * set by the normal rules?
1746+ */
1747+ def isAssumedPure (ref : TermRef )(using Context ): Boolean =
1748+ ref.name == nme.DOLLAR_VALUES // ref is an enum $values array, which for backwards
1749+ && ref.symbol.owner.is(Module ) // compatible reasons is an array, but should really be an IArray.
1750+ && ref.symbol.owner.companionClass.is(Enum )
17391751
17401752 type AssumedContains = immutable.Map [TypeRef , SimpleIdentitySet [Capability ]]
17411753 val AssumedContains : Property .Key [AssumedContains ] = Property .Key ()
0 commit comments