lua: loadstring wraps transpiled AST in (let () …) to contain local definitions
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-24 20:35:18 +00:00
parent f0a4dfbea8
commit 1d3a93b0ca
4 changed files with 41 additions and 38 deletions

View File

@@ -1484,7 +1484,9 @@
(define (define
lua-loadstring lua-loadstring
(fn (src) (fn (src)
(fn (&rest args) (lua-eval-ast src)))) (let ((compiled (lua-transpile src)))
(fn (&rest args)
(eval-expr (list (make-symbol "let") (list) compiled))))))
(define loadstring lua-loadstring) (define loadstring lua-loadstring)
(define load lua-loadstring) (define load lua-loadstring)

View File

@@ -11,7 +11,7 @@
"top_failure_modes": [ "top_failure_modes": [
[ [
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
12 11
], ],
[ [
"timeout", "timeout",
@@ -19,7 +19,7 @@
], ],
[ [
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
1 2
] ]
], ],
"results": [ "results": [
@@ -39,19 +39,19 @@
"name": "attrib.lua", "name": "attrib.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 5754 "ms": 7069
}, },
{ {
"name": "big.lua", "name": "big.lua",
"status": "timeout", "status": "timeout",
"reason": "per-test timeout", "reason": "per-test timeout",
"ms": 8008 "ms": 8007
}, },
{ {
"name": "calls.lua", "name": "calls.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 4651 "ms": 5059
}, },
{ {
"name": "checktable.lua", "name": "checktable.lua",
@@ -63,7 +63,7 @@
"name": "closure.lua", "name": "closure.lua",
"status": "timeout", "status": "timeout",
"reason": "per-test timeout", "reason": "per-test timeout",
"ms": 8006 "ms": 8008
}, },
{ {
"name": "code.lua", "name": "code.lua",
@@ -75,7 +75,7 @@
"name": "constructs.lua", "name": "constructs.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 4212 "ms": 4593
}, },
{ {
"name": "db.lua", "name": "db.lua",
@@ -87,13 +87,13 @@
"name": "errors.lua", "name": "errors.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 3006 "ms": 3390
}, },
{ {
"name": "events.lua", "name": "events.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 6900 "ms": 7477
}, },
{ {
"name": "files.lua", "name": "files.lua",
@@ -111,13 +111,13 @@
"name": "literals.lua", "name": "literals.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 1804 "ms": 1883
}, },
{ {
"name": "locals.lua", "name": "locals.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
"ms": 1596 "ms": 1642
}, },
{ {
"name": "main.lua", "name": "main.lua",
@@ -129,43 +129,43 @@
"name": "math.lua", "name": "math.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 3930 "ms": 4194
}, },
{ {
"name": "nextvar.lua", "name": "nextvar.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 6822 "ms": 6779
}, },
{ {
"name": "pm.lua", "name": "pm.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 5745 "ms": 5731
}, },
{ {
"name": "sort.lua", "name": "sort.lua",
"status": "timeout", "status": "timeout",
"reason": "per-test timeout", "reason": "per-test timeout",
"ms": 8007 "ms": 8008
}, },
{ {
"name": "strings.lua", "name": "strings.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 3814 "ms": 3935
}, },
{ {
"name": "vararg.lua", "name": "vararg.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 2140 "ms": 2273
}, },
{ {
"name": "verybig.lua", "name": "verybig.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
"ms": 558 "ms": 564
} }
] ]
} }

View File

@@ -5,9 +5,9 @@ fail=13 timeout=3 skip=8 total=24
## Top failure modes ## Top failure modes
- **12x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ - **11x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\
- **3x** timeout - **3x** timeout
- **1x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio - **2x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio
## Per-test results ## Per-test results
@@ -15,25 +15,25 @@ fail=13 timeout=3 skip=8 total=24
|---|---|---|---:| |---|---|---|---:|
| all.lua | skip | driver uses dofile to chain other tests | 0 | | all.lua | skip | driver uses dofile to chain other tests | 0 |
| api.lua | skip | requires testC (C debug library) | 0 | | api.lua | skip | requires testC (C debug library) | 0 |
| attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5754 | | attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7069 |
| big.lua | timeout | per-test timeout | 8008 | | big.lua | timeout | per-test timeout | 8007 |
| calls.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4651 | | calls.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5059 |
| checktable.lua | skip | internal debug helpers | 0 | | checktable.lua | skip | internal debug helpers | 0 |
| closure.lua | timeout | per-test timeout | 8006 | | closure.lua | timeout | per-test timeout | 8008 |
| code.lua | skip | bytecode inspection via debug library | 0 | | code.lua | skip | bytecode inspection via debug library | 0 |
| constructs.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4212 | | constructs.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4593 |
| db.lua | skip | debug library | 0 | | db.lua | skip | debug library | 0 |
| errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3006 | | errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3390 |
| events.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6900 | | events.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7477 |
| files.lua | skip | io library | 0 | | files.lua | skip | io library | 0 |
| gc.lua | skip | collectgarbage / finalisers | 0 | | gc.lua | skip | collectgarbage / finalisers | 0 |
| literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1804 | | literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1883 |
| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1596 | | locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1642 |
| main.lua | skip | standalone interpreter driver | 0 | | main.lua | skip | standalone interpreter driver | 0 |
| math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3930 | | math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4194 |
| nextvar.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6822 | | nextvar.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6779 |
| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5745 | | pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5731 |
| sort.lua | timeout | per-test timeout | 8007 | | sort.lua | timeout | per-test timeout | 8008 |
| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3814 | | strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3935 |
| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2140 | | vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2273 |
| verybig.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 558 | | verybig.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 564 |

View File

@@ -82,6 +82,7 @@ Each item: implement → tests → tick box → update progress log.
_Newest first. Agent appends on every commit._ _Newest first. Agent appends on every commit._
- 2026-04-24: lua: scoreboard iteration — **`loadstring` scoping**. Temporarily instrumented `lua-assert` with a counter, found `locals.lua` fails at assertion #5: `loadstring('local a = {}')() → assert(type(a) ~= 'table')`. The loadstring'd code's `local a` was leaking to outer scope because `lua-eval-ast` ran at top-level. Fixed by transpiling once and wrapping the AST in `(let () …)` before `eval-expr`.
- 2026-04-24: lua: scoreboard iteration — **`if`/`else`/`elseif` body scoping** (latent bug). `else local x = 99` was leaking to enclosing scope. Wrap all three branches in `(let () …)` via `lua-tx-if-body`. 358 tests. - 2026-04-24: lua: scoreboard iteration — **`if`/`else`/`elseif` body scoping** (latent bug). `else local x = 99` was leaking to enclosing scope. Wrap all three branches in `(let () …)` via `lua-tx-if-body`. 358 tests.
- 2026-04-24: lua: scoreboard iteration — **`do`-block proper scoping**. Was transpiling `do ... end` to a raw `lua-tx` pass-through, so `define`s inside leaked to the enclosing scope (`do local i = 100 end` overwrote outer `i`). Now wraps in `(let () body)` for proper lexical isolation. 355 tests, +2 scoping tests. - 2026-04-24: lua: scoreboard iteration — **`do`-block proper scoping**. Was transpiling `do ... end` to a raw `lua-tx` pass-through, so `define`s inside leaked to the enclosing scope (`do local i = 100 end` overwrote outer `i`). Now wraps in `(let () body)` for proper lexical isolation. 355 tests, +2 scoping tests.
- 2026-04-24: lua: scoreboard iteration — `lua-to-number` trims whitespace before `parse-number` (Lua coerces `" 3e0 "` in arithmetic). math.lua moved past the arith-type error to deeper assertion-land. 12× asserts / 3× timeouts / 1× call-non-fn. - 2026-04-24: lua: scoreboard iteration — `lua-to-number` trims whitespace before `parse-number` (Lua coerces `" 3e0 "` in arithmetic). math.lua moved past the arith-type error to deeper assertion-land. 12× asserts / 3× timeouts / 1× call-non-fn.