lua: proper early-return via guard+raise sentinel; fixes if-then-return-end-rest +3 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-24 21:46:23 +00:00
parent b1bed8e0e5
commit 68b0a279f8
6 changed files with 104 additions and 60 deletions

View File

@@ -936,6 +936,14 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 1842)
(eval "(lua-eval-ast \"if -2^2 == -4 then return 1 else return 0 end\")")
;; ── Early-return inside nested block (guard+raise sentinel) ──
(epoch 1850)
(eval "(lua-eval-ast \"local function f(n) if n < 0 then return -1 end return n * 2 end return f(-5)\")")
(epoch 1851)
(eval "(lua-eval-ast \"local function f(n) if n < 0 then return -1 end return n * 2 end return f(7)\")")
(epoch 1852)
(eval "(lua-eval-ast \"function f(i) if type(i) ~= \\\"number\\\" then return i, \\\"jojo\\\" end if i > 0 then return i, f(i-1) end end local a, b = f(3) return a\")")
EPOCHS
OUTPUT=$(timeout 60 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
@@ -1414,6 +1422,11 @@ check 1840 "-2^2 = -4" '-4'
check 1841 "2^3^2 = 512 (right-assoc)" '512'
check 1842 "-2^2 == -4 true" '1'
# ── Early-return inside nested block ─────────────────────────
check 1850 "early return negative path" '-1'
check 1851 "non-early return path" '14'
check 1852 "nested early-return recursion" '3'
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL Lua-on-SX tests passed"