-
Notifications
You must be signed in to change notification settings - Fork 42
Description
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.