ocaml: phase 1+3 'when' guard in 'function | pat -> body' (+3 tests, 464 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 26s

parse-function now consumes optional 'when GUARD-EXPR' before -> and
emits (:case-when PAT GUARD BODY) — same handling as match clauses.
function-style sign extraction now works:
  (function | n when n > 0 -> 1 | n when n < 0 -> -1 | _ -> 0)
This commit is contained in:
2026-05-08 20:26:28 +00:00
parent b92a98fb45
commit 029c1783f4
3 changed files with 26 additions and 3 deletions

View File

@@ -1140,6 +1140,14 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 4306)
(eval "(ocaml-run \"Char.is_lower \\\"a\\\"\")")
;; ── function with `when` guard ────────────────────────────────
(epoch 4400)
(eval "(ocaml-run \"(function | n when n > 0 -> 1 | _ -> 0) 5\")")
(epoch 4401)
(eval "(ocaml-run \"(function | n when n > 0 -> 1 | _ -> 0) (-3)\")")
(epoch 4402)
(eval "(ocaml-run \"(function | n when n > 0 -> 1 | n when n < 0 -> -1 | _ -> 0) 0\")")
EPOCHS
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
@@ -1805,6 +1813,11 @@ check 4304 "Char.is_whitespace ' '" 'true'
check 4305 "Char.is_upper A" 'true'
check 4306 "Char.is_lower a" 'true'
# ── function with `when` guard ─────────────────────────────────
check 4400 "function when 5" '1'
check 4401 "function when -3" '0'
check 4402 "function sign 0" '0'
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"