ocaml: phase 2+3 'when' guard in try/with (+3 tests, 467 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 27s

parse-try now consumes optional 'when GUARD-EXPR' before -> and emits
(:case-when PAT GUARD BODY). Eval try clause loop dispatches on case /
case-when and falls through on guard false — same semantics as match.

Examples:
  try raise (E 5) with | E n when n > 0 -> n | _ -> 0   = 5
  try raise (E (-3)) with | E n when n > 0 -> n | _ -> 0 = 0
  try raise (E 5) with | E n when n > 100 -> n | E n -> n + 1000  = 1005
This commit is contained in:
2026-05-08 20:36:02 +00:00
parent 029c1783f4
commit c7d8b7dd62
4 changed files with 49 additions and 11 deletions

View File

@@ -1148,6 +1148,14 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 4402)
(eval "(ocaml-run \"(function | n when n > 0 -> 1 | n when n < 0 -> -1 | _ -> 0) 0\")")
;; ── try/with `when` guard ─────────────────────────────────────
(epoch 4500)
(eval "(ocaml-run \"try raise (E 5) with | E n when n > 0 -> n | _ -> 0\")")
(epoch 4501)
(eval "(ocaml-run \"try raise (E (-3)) with | E n when n > 0 -> n | _ -> 0\")")
(epoch 4502)
(eval "(ocaml-run \"try raise (E 5) with | E n when n > 100 -> n | E n -> n + 1000\")")
EPOCHS
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
@@ -1818,6 +1826,11 @@ check 4400 "function when 5" '1'
check 4401 "function when -3" '0'
check 4402 "function sign 0" '0'
# ── try/with `when` guard ──────────────────────────────────────
check 4500 "try when guard fires" '5'
check 4501 "try when guard skips" '0'
check 4502 "try when fall through" '1005'
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"