Skip to content

Commit 52be0d3

Browse files
committed
Add fewer parameter refinements.
Only enrich classes with capture refinements for a parameter if the deep capture set of the parameter's type is nonempty.
1 parent bd732ba commit 52be0d3

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

compiler/src/dotty/tools/dotc/cc/Setup.scala

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,20 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
5757
private val toBeUpdated = new mutable.HashSet[Symbol]
5858

5959
private def newFlagsFor(symd: SymDenotation)(using Context): FlagSet =
60-
if symd.isAllOf(PrivateParamAccessor) && symd.owner.is(CaptureChecked) && !symd.hasAnnotation(defn.ConstructorOnlyAnnot)
60+
61+
object containsCovarRetains extends TypeAccumulator[Boolean]:
62+
def apply(x: Boolean, tp: Type): Boolean =
63+
if x then true
64+
else if tp.derivesFromCapability && variance >= 0 then true
65+
else tp match
66+
case AnnotatedType(_, ann) if ann.symbol.isRetains && variance >= 0 => true
67+
case _ => foldOver(x, tp)
68+
def apply(tp: Type): Boolean = apply(false, tp)
69+
70+
if symd.isAllOf(PrivateParamAccessor)
71+
&& symd.owner.is(CaptureChecked)
72+
&& !symd.hasAnnotation(defn.ConstructorOnlyAnnot)
73+
//&& containsCovarRetains(symd.symbol.originDenotation.info)
6174
then symd.flags &~ Private | Recheck.ResetPrivate
6275
else symd.flags
6376

0 commit comments

Comments
 (0)