Skip to content

Bug: Fix scope issues #50

@PeterGriffinSr

Description

@PeterGriffinSr

Description:
Currently, variable shadowing within functions does not work correctly. A local variable that has the same name as an outer variable incorrectly overrides the outer variable across all scopes, rather than being limited to the inner block.

Example:

let x = 10 in

let add() {
    let x = 20 in
    x
}

print(add() + x)

Expected Behavior:
This should print 30 because:

  • add() returns the inner x (20).
  • The outer x remains 10.
  • Therefore, 20 + 10 = 30.

Actual Behavior:
Instead, it prints 40. The inner x (20) shadows the outer x everywhere, causing the calculation to become 20 + 20.

Impact:
This behavior breaks proper lexical scoping rules, making it impossible to reliably shadow variables without affecting the outer scopes.

Steps to Reproduce:

  1. Declare a variable in an outer scope.
  2. Create a function that contains a variable with the same name.
  3. Attempt to access both the inner and outer variables.
  4. Observe that the shadowed variable incorrectly affects the outer scope.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    Status

    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions