Registry Mirror
Skip to content

Conversation

@siegfriedpammer

Copy link
Copy Markdown
Member

Fixes #3714.

A local function nested in a lambda can capture closures at two depths: csc emits it as an instance method on the enclosing method's display class that takes the lambda's display class as a parameter. Combining those two capture scopes with FindCommonAncestorInstruction picked the enclosing method, moving the function out of the lambda that owns the deeper closure; the variables captured there were then unreachable and the display-class parameter survived into the output as an undeclared identifier:

return outer;
void Local(int d)
{
    P_1.inner += d;   // P_1: undeclared, uncompilable
    outer += d;
}

Nested capture scopes now resolve to the innermost instead, which a local function can always see - it reaches the outer closure through the display class it is declared on.

🤖 Generated with Claude Code

A local function nested in a lambda can capture closures at two depths:
csc emits it as an instance method on the enclosing method's display
class that takes the lambda's display class as a parameter. Combining
those two capture scopes with FindCommonAncestorInstruction picked the
enclosing method, moving the function out of the lambda that owns the
deeper closure; the variables captured there were then unreachable and
the display-class parameter survived into the output as an undeclared
identifier. Nested capture scopes resolve to the innermost instead,
which a local function can always see - it reaches the outer closure
through the display class it is declared on.

Assisted-by: Claude:claude-fable-5:Claude Code
@siegfriedpammer
siegfriedpammer force-pushed the fix-3714-local-function-scope branch from eb4dfe4 to e0aee1b Compare August 30, 2026 09:48
@siegfriedpammer
siegfriedpammer merged commit 48bf055 into master Aug 30, 2026
15 checks passed
@siegfriedpammer
siegfriedpammer deleted the fix-3714-local-function-scope branch August 30, 2026 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Local function issue

1 participant