lua: skip top-level guard when chunk has no top-level return; loadstring sees user globals
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-25 00:14:15 +00:00
parent abc98b7665
commit d170d5fbae
4 changed files with 68 additions and 45 deletions

View File

@@ -1,8 +1,8 @@
{ {
"totals": { "totals": {
"pass": 1, "pass": 1,
"fail": 12, "fail": 11,
"timeout": 3, "timeout": 4,
"skip": 8, "skip": 8,
"total": 24, "total": 24,
"runnable": 16, "runnable": 16,
@@ -15,16 +15,12 @@
], ],
[ [
"timeout", "timeout",
3 4
], ],
[ [
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
2 2
], ],
[
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: module 'C' not found\\\\\\\"\\",
1
],
[ [
"undefined symbol: fat\\", "undefined symbol: fat\\",
1 1
@@ -49,9 +45,9 @@
}, },
{ {
"name": "attrib.lua", "name": "attrib.lua",
"status": "fail", "status": "timeout",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: module 'C' not found\\\\\\\"\\", "reason": "per-test timeout",
"ms": 6525 "ms": 8008
}, },
{ {
"name": "big.lua", "name": "big.lua",
@@ -63,7 +59,7 @@
"name": "calls.lua", "name": "calls.lua",
"status": "fail", "status": "fail",
"reason": "undefined symbol: fat\\", "reason": "undefined symbol: fat\\",
"ms": 5092 "ms": 6184
}, },
{ {
"name": "checktable.lua", "name": "checktable.lua",
@@ -75,7 +71,7 @@
"name": "closure.lua", "name": "closure.lua",
"status": "timeout", "status": "timeout",
"reason": "per-test timeout", "reason": "per-test timeout",
"ms": 8006 "ms": 8001
}, },
{ {
"name": "code.lua", "name": "code.lua",
@@ -87,7 +83,7 @@
"name": "constructs.lua", "name": "constructs.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to compare incompat", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to compare incompat",
"ms": 6780 "ms": 7870
}, },
{ {
"name": "db.lua", "name": "db.lua",
@@ -99,13 +95,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": 3208 "ms": 3808
}, },
{ {
"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": 7307 "ms": 7990
}, },
{ {
"name": "files.lua", "name": "files.lua",
@@ -123,13 +119,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": 1816 "ms": 2085
}, },
{ {
"name": "locals.lua", "name": "locals.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": 1627 "ms": 1811
}, },
{ {
"name": "main.lua", "name": "main.lua",
@@ -141,43 +137,43 @@
"name": "math.lua", "name": "math.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": 4156 "ms": 4436
}, },
{ {
"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": 7064 "ms": 7759
}, },
{ {
"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": 5813 "ms": 6473
}, },
{ {
"name": "sort.lua", "name": "sort.lua",
"status": "timeout", "status": "timeout",
"reason": "per-test timeout", "reason": "per-test timeout",
"ms": 8008 "ms": 8007
}, },
{ {
"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": 3987 "ms": 4366
}, },
{ {
"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": 2243 "ms": 2422
}, },
{ {
"name": "verybig.lua", "name": "verybig.lua",
"status": "pass", "status": "pass",
"reason": "", "reason": "",
"ms": 1085 "ms": 1077
} }
] ]
} }

View File

@@ -1,14 +1,13 @@
# Lua-on-SX conformance scoreboard # Lua-on-SX conformance scoreboard
**Pass rate:** 1/16 runnable (6.2%) **Pass rate:** 1/16 runnable (6.2%)
fail=12 timeout=3 skip=8 total=24 fail=11 timeout=4 skip=8 total=24
## Top failure modes ## Top failure modes
- **7x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ - **7x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\
- **3x** timeout - **4x** timeout
- **2x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio - **2x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio
- **1x** other: Unhandled exception: \"Unhandled exception: \\\"lua: module 'C' not found\\\"\
- **1x** undefined symbol: fat\ - **1x** undefined symbol: fat\
- **1x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to compare incompat - **1x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to compare incompat
@@ -18,25 +17,25 @@ fail=12 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: \\\"lua: module 'C' not found\\\"\ | 6525 | | attrib.lua | timeout | per-test timeout | 8008 |
| big.lua | timeout | per-test timeout | 8007 | | big.lua | timeout | per-test timeout | 8007 |
| calls.lua | fail | undefined symbol: fat\ | 5092 | | calls.lua | fail | undefined symbol: fat\ | 6184 |
| 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 | 8001 |
| 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: \\\"lua: attempt to compare incompat | 6780 | | constructs.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to compare incompat | 7870 |
| db.lua | skip | debug library | 0 | | db.lua | skip | debug library | 0 |
| errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3208 | | errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3808 |
| events.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7307 | | events.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7990 |
| 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!\\\"\ | 1816 | | literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2085 |
| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1627 | | locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1811 |
| main.lua | skip | standalone interpreter driver | 0 | | main.lua | skip | standalone interpreter driver | 0 |
| math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 4156 | | math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 4436 |
| nextvar.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7064 | | nextvar.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7759 |
| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5813 | | pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6473 |
| sort.lua | timeout | per-test timeout | 8008 | | sort.lua | timeout | per-test timeout | 8007 |
| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3987 | | strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4366 |
| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2243 | | vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2422 |
| verybig.lua | pass | - | 1085 | | verybig.lua | pass | - | 1077 |

View File

@@ -568,12 +568,39 @@
(else sx))))))) (else sx)))))))
(else sx)))) (else sx))))
(define
lua-has-top-return?
(fn (node)
(cond
((not (= (type-of node) "list")) false)
((= (len node) 0) false)
((= (first node) (quote lua-return)) true)
((or (= (first node) (quote lua-function))
(= (first node) (quote lua-local-function))
(= (first node) (quote lua-function-decl)))
false)
(else
(lua-has-top-return-children? (rest node) 0)))))
(define
lua-has-top-return-children?
(fn (children i)
(cond
((>= i (len children)) false)
((lua-has-top-return? (nth children i)) true)
(else (lua-has-top-return-children? children (+ i 1))))))
(define (define
lua-eval-ast lua-eval-ast
(fn (src) (fn (src)
(let ((sx (lua-transpile src))) (let ((parsed (lua-parse src)))
(let ((sx2 (lua-unwrap-final-return sx))) (let ((sx (lua-tx parsed)))
(eval-expr (lua-tx-function-guard sx2)))))) (let ((sx2 (lua-unwrap-final-return sx)))
(cond
((lua-has-top-return? parsed)
(eval-expr (lua-tx-function-guard sx2)))
(else
(eval-expr sx2))))))))
(define (define
lua-tx-multi-args lua-tx-multi-args

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-25: lua: scoreboard iteration — `lua-eval-ast` now SKIPS the top-level guard when the parsed chunk has no top-level `return` (recursive AST walk via `lua-has-top-return?` that descends through control-flow but stops at function-body boundaries). Without the guard, top-level user defines leak to the SX top env, and `loadstring`-captured closures can find them. Verified: `function fat(x)...loadstring("return fat(...)")...end; x=fat(5)` works (was undefined). Most PUC-Rio tests still have top-level returns elsewhere, so they still need the guard. Scoreboard unchanged at 1/16 but unblocks future work.
- 2026-04-25: lua: scoreboard iteration — math fns now error on bad/missing args (was silently returning 0). New `lua-math-num "name" x` validator wraps `abs`/`ceil`/`floor`/`sqrt`/`exp`/`sin`/`cos`/`tan`/`asin`/`acos`/`atan`/`atan2`/`pow`. errors.lua moves past assert #4 (`pcall(math.sin)` now returns false+err as expected). - 2026-04-25: lua: scoreboard iteration — math fns now error on bad/missing args (was silently returning 0). New `lua-math-num "name" x` validator wraps `abs`/`ceil`/`floor`/`sqrt`/`exp`/`sin`/`cos`/`tan`/`asin`/`acos`/`atan`/`atan2`/`pow`. errors.lua moves past assert #4 (`pcall(math.sin)` now returns false+err as expected).
- 2026-04-24: lua: scoreboard iteration — **pattern character sets** `[...]` and `[^...]`. New `lua-pat-set-end`/`lua-pat-set-match` helpers handle ranges (`[a-z]`), classes inside sets (`[%d%a]`), negation (`[^abc]`), and `[]...]`/`[^]...]` (literal `]` as first char). Asserts 6→4, but timeouts 3→7 — many tests now reach loop-heavy code. 387/387 green (+3 charset tests). - 2026-04-24: lua: scoreboard iteration — **pattern character sets** `[...]` and `[^...]`. New `lua-pat-set-end`/`lua-pat-set-match` helpers handle ranges (`[a-z]`), classes inside sets (`[%d%a]`), negation (`[^abc]`), and `[]...]`/`[^]...]` (literal `]` as first char). Asserts 6→4, but timeouts 3→7 — many tests now reach loop-heavy code. 387/387 green (+3 charset tests).
- 2026-04-24: lua: scoreboard iteration — `tonumber(s, base)` for bases 2-36. Validates digit ranges per base, supports leading `+`/`-`, trims whitespace. `math.lua` past assert #21. Asserts 8→6, timeouts 3→4. 384/384 green. - 2026-04-24: lua: scoreboard iteration — `tonumber(s, base)` for bases 2-36. Validates digit ranges per base, supports leading `+`/`-`, trims whitespace. `math.lua` past assert #21. Asserts 8→6, timeouts 3→4. 384/384 green.