Commit a046048
hir: prealloc closure-capture boxes for lets nested in Try/If (array destructuring) (#5859)
compute_prealloc_for_hoisted_closures collects the function-entry
prealloc-box set via collect_top_level_let_ids_stmt, which only matched
top-level `Stmt::Let`. But array-destructuring bindings
(`let [a, b] = expr`) lower through the iterator protocol wrapped in a
`Try` (iterator close), so their leaf `let`s live inside the Try body /
its `if`s — never at the statement top level. A hoisted function
declaration capturing such a binding was therefore omitted from the
prealloc set: the closure captured the un-boxed, not-yet-assigned slot
and read `undefined` instead of the current value (e.g.
`const [k, setK] = useState(0)` captured by a hoisted handler — the
handler saw k === undefined and took the wrong branch).
Recurse into `Stmt::Try` (body/catch/finally) and `Stmt::If` (then/else)
— the constructs the destructuring lowering emits — when collecting
hoisted-let ids. Loops are intentionally not recursed: a per-iteration
`let` needs a fresh box per iteration, not a single function-entry
prealloc.
cargo test -p perry-hir: 221 passed, 0 failed.
Co-authored-by: Ralph Küpper <ralph@skelpo.com>1 parent 071f651 commit a046048
1 file changed
Lines changed: 48 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1351 | 1351 | | |
1352 | 1352 | | |
1353 | 1353 | | |
1354 | | - | |
1355 | | - | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
1356 | 1402 | | |
1357 | 1403 | | |
1358 | 1404 | | |
| |||
0 commit comments