Skip to content

Fix None filtering, scope serialization, and Assignment RHS scoping#3

Merged
revarbat merged 3 commits intoscopingfrom
copilot/sub-pr-2
Mar 19, 2026
Merged

Fix None filtering, scope serialization, and Assignment RHS scoping#3
revarbat merged 3 commits intoscopingfrom
copilot/sub-pr-2

Conversation

Copy link

Copilot AI commented Mar 19, 2026

Three correctness issues identified in code review of the lexical scope feature.

Changes

  • builder.pyvisit_module_definition now skips None items when flattening children (via elif item is not None). visit_statement() can return None for empty nodes; those were propagating into ModuleDeclaration.children and crashing build_scope().

  • serialization.pyscope is now excluded from field serialization alongside position. After build_scopes() runs, node.scope is a Scope instance that _serialize_value() can't handle, causing TypeError in ast_to_dict/json/yaml.

  • nodes.pyAssignment.build_scope() now always passes parent_scope (the full scope) to the RHS expression. Function literal bodies are closures that resolve variables lazily at call time, so the full enclosing scope — including the variable being assigned — must be visible. This correctly handles both direct function literal assignments and expressions that contain function literals (e.g. a ternary whose branches are function literals):

fn = function(n) n == 0 ? 1 : fn(n-1);  // fn IS visible in body for recursion
a = b ? function(x, n) a(x+n, n-1) : function(x, n) a(x*n, n-1);  // a IS visible in both branches

📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

…on exclusion, Assignment RHS pre-assignment scope

Co-authored-by: revarbat <350001+revarbat@users.noreply.github.com>
Copilot AI changed the title [WIP] Add lexical scope support to AST nodes Fix None filtering, scope serialization, and Assignment RHS scoping Mar 19, 2026
Copilot AI requested a review from revarbat March 19, 2026 21:50
…tion literals are closures, lazy-evaluated)

Co-authored-by: revarbat <350001+revarbat@users.noreply.github.com>
Copilot AI requested a review from revarbat March 19, 2026 22:54
@revarbat revarbat marked this pull request as ready for review March 19, 2026 23:17
@revarbat revarbat merged commit 07974fb into scoping Mar 19, 2026
@revarbat revarbat deleted the copilot/sub-pr-2 branch March 19, 2026 23:33
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.

2 participants