feat: replace Scope stack with Local array to fix variable shadowing in nested blocks
Replace the linked-list Scope structure with a flat Local array indexed by depth, enabling proper shadowing semantics where inner declarations correctly hide outer ones. Remove the PUSH_SCOPE/POP_SCOPE macros and the SymbolTable-based locals tracking, replacing them with a MAX_LOCALS (255) fixed-size array that stores variable name, length, and depth. Add four new test cases covering local/parameter collision, nested block scoping, global shadowing, and local shadowing to validate the new behavior.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
fn(a) {
|
||||
var a = "oops" // expect error
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
var a = "outer"
|
||||
{
|
||||
io.write(a) // expect: outer
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
var a = "global"
|
||||
{
|
||||
var a = "shadow"
|
||||
io.write(a) // expect: shadow
|
||||
}
|
||||
io.write(a) // expect: global
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
var a = "local"
|
||||
{
|
||||
var a = "shadow"
|
||||
io.write(a) // expect: shadow
|
||||
}
|
||||
io.write(a) // expect: local
|
||||
}
|
||||
Reference in New Issue
Block a user