Skip to content

Incorrect Scope Handling in Function Declarations #44

@rbonifacio

Description

@rbonifacio

The current scope implementation does not correctly model lexical scoping. Specifically, we should maintain a stack of scopes—one for each active function or block—to ensure proper variable resolution.

Currently, the implementation iterates over all existing scopes when resolving variable declarations. This can lead to incorrect behavior where a function declared in the top-level scope incorrectly accesses variables declared inside another function that is lower on the execution stack. This violates standard scoping rules and may result in subtle, hard-to-detect bugs.

Proposed Fix:
We should revise the implementation to use a stack-based scope model where each function introduces a new scope. Variable lookups should be restricted to the current scope and its lexical parents, in order.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions