Commit 2ee58bc
committed
Fix infinite loop with my sub closures inside subroutines
The issue was that 'my sub' assignments were being executed at
compile-time (in a BEGIN block) instead of at runtime. This caused
lexical subroutines to capture closure variables from the first
call rather than fresh values on each invocation of the enclosing
subroutine.
The fix differentiates:
- state sub: Execute once at compile time (BEGIN block) - unchanged
- my sub: Execute at runtime, creating fresh closure each scope entry
Additionally, this fix properly handles 'my sub' with signatures by
not consuming (...) as a prototype when signatures feature is enabled,
letting parseSubroutineDefinition handle it as a proper signature.
Fixes the infinite loop where a 'my sub inner' inside 'sub process'
would incorrectly retain the $callback from the first call even
when process was called again with undef.1 parent 44ef95c commit 2ee58bc
File tree
2 files changed
+25
-9
lines changed- src/main/java/org/perlonjava/parser
2 files changed
+25
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
Lines changed: 23 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
279 | | - | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
280 | 283 | | |
281 | 284 | | |
282 | 285 | | |
283 | 286 | | |
284 | 287 | | |
285 | | - | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
286 | 292 | | |
287 | 293 | | |
288 | 294 | | |
| |||
315 | 321 | | |
316 | 322 | | |
317 | 323 | | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
325 | 339 | | |
326 | 340 | | |
327 | 341 | | |
| |||
0 commit comments