ocaml: phase 3 type declarations (+5 tests, 300 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 52s

Parser: type [PARAMS] NAME = | Ctor [of T1 [* T2]*] | ...
- PARAMS: optional 'a or ('a, 'b) tyvar list
- AST: (:type-def NAME PARAMS CTORS) with each CTOR (NAME ARG-SOURCES)
- Argument types captured as raw source strings (treated opaquely at
  runtime since ctor dispatch is dynamic)

Runtime is a no-op — constructors and pattern matching already work
dynamically. Phase 5 will use these decls to register ctor types for
HM checking.
This commit is contained in:
2026-05-08 12:32:39 +00:00
parent 851e0585cf
commit d8f6250962
4 changed files with 110 additions and 3 deletions

View File

@@ -742,6 +742,18 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 1205)
(eval "(ocaml-run \"match (Some 3) with | None -> 0 | Some x when x > 5 -> x * 10 | Some x -> x\")")
;; ── type declarations (parser + runtime) ──────────────────────
(epoch 1300)
(eval "(ocaml-parse-program \"type color = Red | Green | Blue\")")
(epoch 1301)
(eval "(ocaml-parse-program \"type shape = Circle of int | Rect of int | Square of int\")")
(epoch 1302)
(eval "(ocaml-run-program \"type color = Red | Green | Blue ;; match Red with | Red -> 1 | Green -> 2 | Blue -> 3\")")
(epoch 1303)
(eval "(ocaml-run-program \"type color = Red | Green | Blue ;; match Blue with | Red -> 1 | Green -> 2 | Blue -> 3\")")
(epoch 1304)
(eval "(ocaml-run-program \"type shape = Circle of int | Square of int ;; match Circle 5 with | Circle r -> r | Square s -> s\")")
EPOCHS
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
@@ -1175,6 +1187,13 @@ check 1203 "when sign 0" '0'
check 1204 "when guard fires" '70'
check 1205 "when guard skips" '3'
# ── type declarations ───────────────────────────────────────────
check 1300 "type color enum" '("type-def" "color" () (("Red") ("Green") ("Blue")))'
check 1301 "type shape with-args" '("type-def" "shape"'
check 1302 "type-decl + match Red" '1'
check 1303 "type-decl + match Blue" '3'
check 1304 "type-decl + Circle r" '5'
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"