Skip to content

Commit 1c294ef

Browse files
committed
Change owner of computed capture set for constructor applications
1 parent f065d75 commit 1c294ef

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,11 @@ sealed abstract class CaptureSet extends Showable:
274274
else Const(elems.filter(p))
275275
else Filtered(asVar, p)
276276

277+
/** This set with a new owner and therefore also a new levelLimit */
278+
def changeOwner(newOwner: Symbol)(using Context): CaptureSet =
279+
if this.isConst then this
280+
else ChangedOwner(asVar, newOwner)
281+
277282
/** Capture set obtained by applying `tm` to all elements of the current capture set
278283
* and joining the results. If the current capture set is a variable, the same
279284
* transformation is applied to all future additions of new elements.
@@ -752,6 +757,10 @@ object CaptureSet:
752757
override def toString = s"BiMapped$id($source, elems = $elems)"
753758
end BiMapped
754759

760+
/** Same as `source` but with a new directOwner */
761+
class ChangedOwner private[CaptureSet](val source: Var, newOwner: Symbol)(using @constructorOnly ctx: Context)
762+
extends DerivedVar(newOwner, source.elems)
763+
755764
/** A variable with elements given at any time as { x <- source.elems | p(x) } */
756765
class Filtered private[CaptureSet]
757766
(val source: Var, p: Context ?=> CaptureRef => Boolean)(using @constructorOnly ctx: Context)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ class CheckCaptures extends Recheck, SymTransformer:
509509
augmentConstructorType(parent, initCs ++ refs)
510510
case _ =>
511511
val (refined, cs) = addParamArgRefinements(core, initCs)
512-
refined.capturing(cs)
512+
refined.capturing(cs.changeOwner(ctx.owner))
513513

514514
augmentConstructorType(ownType, capturedVars(cls) ++ capturedVars(sym))
515515
.showing(i"constr type $mt with $argTypes%, % in $cls = $result", capt)

0 commit comments

Comments
 (0)