@@ -365,6 +365,12 @@ class CheckCaptures extends Recheck, SymTransformer:
365
365
else
366
366
i " \n of the enclosing ${owner.showLocated}"
367
367
368
+ def isOfNestedMethod (env : Env | Null )(using Context ) =
369
+ env != null
370
+ && env.owner.is(Method )
371
+ && env.owner.owner.isTerm
372
+ && ! env.owner.isAnonymousFunction
373
+
368
374
/** Include `sym` in the capture sets of all enclosing environments nested in the
369
375
* the environment in which `sym` is defined.
370
376
*/
@@ -377,7 +383,8 @@ class CheckCaptures extends Recheck, SymTransformer:
377
383
if env.isOpen && env.owner != sym.enclosure then
378
384
capt.println(i " Mark $sym with cs ${ref.captureSet} free in ${env.owner}" )
379
385
checkElem(ref, env.captured, pos, provenance(env))
380
- recur(nextEnvToCharge(env, _.owner != sym.enclosure))
386
+ if ! isOfNestedMethod(env) then
387
+ recur(nextEnvToCharge(env, _.owner != sym.enclosure))
381
388
recur(curEnv)
382
389
383
390
/** Make sure (projected) `cs` is a subset of the capture sets of all enclosing
@@ -438,7 +445,8 @@ class CheckCaptures extends Recheck, SymTransformer:
438
445
isVisible
439
446
checkSubset(included, env.captured, pos, provenance(env))
440
447
capt.println(i " Include call or box capture $included from $cs in ${env.owner} --> ${env.captured}" )
441
- recur(included, nextEnvToCharge(env, ! _.owner.isStaticOwner))
448
+ if ! isOfNestedMethod(env) then
449
+ recur(included, nextEnvToCharge(env, ! _.owner.isStaticOwner))
442
450
recur(cs, curEnv)
443
451
end markFree
444
452
0 commit comments