@@ -319,7 +319,7 @@ class CheckCaptures extends Recheck, SymTransformer:
319
319
includeCallCaptures(tree.symbol, tree.srcPos)
320
320
else
321
321
markFree(tree.symbol, tree.srcPos)
322
- instantiateLocalRoots(tree.symbol, NoPrefix , pt):
322
+ instantiateLocalRoots(tree.symbol, NoPrefix , pt, tree.srcPos ):
323
323
super .recheckIdent(tree, pt)
324
324
325
325
/** A specialized implementation of the selection rule.
@@ -349,7 +349,7 @@ class CheckCaptures extends Recheck, SymTransformer:
349
349
350
350
val selType = recheckSelection(tree, qualType, name, disambiguate)
351
351
val selCs = selType.widen.captureSet
352
- instantiateLocalRoots(tree.symbol, qualType, pt):
352
+ instantiateLocalRoots(tree.symbol, qualType, pt, tree.srcPos ):
353
353
if selCs.isAlwaysEmpty || selType.widen.isBoxedCapturing || qualType.isBoxedCapturing then
354
354
selType
355
355
else
@@ -370,7 +370,7 @@ class CheckCaptures extends Recheck, SymTransformer:
370
370
* - `tp` is the type of a function that gets applied, either as a method
371
371
* or as a function value that gets applied.
372
372
*/
373
- def instantiateLocalRoots (sym : Symbol , pre : Type , pt : Type )(tp : Type )(using Context ): Type =
373
+ def instantiateLocalRoots (sym : Symbol , pre : Type , pt : Type , pos : SrcPos )(tp : Type )(using Context ): Type =
374
374
def canInstantiate =
375
375
sym.is(Method , butNot = Accessor )
376
376
|| sym.isTerm && defn.isFunctionType(sym.info) && pt == AnySelectionProto
@@ -379,6 +379,16 @@ class CheckCaptures extends Recheck, SymTransformer:
379
379
var tp1 = tpw
380
380
val rootVar = CaptureRoot .Var (ctx.owner, sym)
381
381
if sym.isLevelOwner then
382
+ val outerOwner = sym.skipConstructor.owner.levelOwner
383
+ if outerOwner.isClass then
384
+ val outerRoot = outerOwner.localRoot.termRef
385
+ outerRoot.asSeenFrom(pre, sym.owner) match
386
+ case outerLimit : CaptureRoot if outerLimit ne outerRoot =>
387
+ capt.println(i " constraining $rootVar of $sym by $outerLimit" )
388
+ if ! outerLimit.encloses(rootVar) then
389
+ // Should this be an assertion failure instead?
390
+ report.error(em " outer instance $outerLimit does not enclose local root $rootVar" , pos)
391
+ case _ =>
382
392
tp1 = mapRoots(sym.localRoot.termRef, rootVar)(tp1)
383
393
if tp1 ne tpw then
384
394
ccSetup.println(i " INST local $sym: $tp, ${sym.localRoot} = $tp1" )
0 commit comments