Skip to content

Commit

Permalink
🪲 Add support for local scopes in the lookup table (#5793)
Browse files Browse the repository at this point in the history
This PR adds introduces support for local scopes. It is a naive implementation that relies on the fact that we cannot nest functions. Thus, every line of code can either be in one local scope of in the global scope. Functions are the only exception - they must be accessible in the global scope and their own local scope (because we have support for recursion).

Fixes #5728

**How to test**
Execute programs in level 12 that introduce a clash between local and global scope, e.g. a variable only defined in local scope is used in the global, or a global and a local variables with the same name but only one of them is used should generate an unused var warning for the right variable. Here are some scenarios:
```
define add
    x is 1
    print x
call add
print x
# must produce an error on line 5
```

```
define add
    print x
x is 5
call add
# must produce an error on line 2
```

```
x is 5
define add
    print x
call add
# must correctly print 5 because the part of the global scope is provided in the closure
```

```
define add
    x is 5
x is 10
print x
call add
# must produce a warning for line 2
```


```
define add
    x is 5
    print x
x is 10
call add
# must produce a warning for line 4
```
  • Loading branch information
boryanagoncharenko authored Sep 24, 2024
1 parent b593adb commit ade35ba
Show file tree
Hide file tree
Showing 2 changed files with 282 additions and 77 deletions.
Loading

0 comments on commit ade35ba

Please sign in to comment.