Commit 7e68645
committed
Fix misplaced pop in execute_block and add exec_if_block for conditional block execution
Fixes a scoping bug in execute_block where pop() was applied to the wrong environment.
Previously, in function `exec`:
- The environment `env` was cloned into a variable `new_env`.
- In the `Statement::Block` match arm, the returned environment was actually wrapped inside
the variable `result`, of type `Computation`.
- However, `pop()` was mistakenly called on `new_env`, which was discarded afterward.
- As a result, the environment inside `result` — the one that was actually returned —
remained unmodified, and the pushed scope was never popped.
This commit fixes the issue by:
- Moving the push/pop operations into the `execute_block` function itself,
so that scope management is handled consistently before wrapping the result in a `Computation`.
Additionally, it introduces the `exec_if_block` function:
- A simplified version of `execute_block` that executes a list of statements without
pushing or popping a new scope.
- Intended for use in the body of `if` clauses
These changes improve correctness and modularity in the interpreter's handling of scope and control flow.1 parent d488d84 commit 7e68645
1 file changed
Lines changed: 39 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
| 87 | + | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
100 | 105 | | |
101 | 106 | | |
102 | 107 | | |
| |||
201 | 206 | | |
202 | 207 | | |
203 | 208 | | |
| 209 | + | |
204 | 210 | | |
205 | 211 | | |
206 | 212 | | |
207 | 213 | | |
208 | | - | |
209 | | - | |
210 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
211 | 243 | | |
212 | 244 | | |
213 | 245 | | |
| |||
0 commit comments