ocaml: phase 1+3 record patterns { f = pat } (+4 tests, 386 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 48s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 48s
Parser: { f1 = pat; f2 = pat; ... } in pattern position emits
(:precord (FIELDNAME PAT)...). Mixed with the existing { in
expression position via the at-pattern-atom? whitelist.
Eval: :precord matches against a dict; required fields must be present
and each pat must match the field's value. Can mix literal+var:
'match { x = 1; y = y } with | { x = 1; y = y } -> y' matches only
when x is 1.
This commit is contained in:
@@ -946,6 +946,16 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 2503)
|
||||
(eval "(ocaml-run \"match \`Pair (1, 2) with | \`Pair (a, b) -> a + b\")")
|
||||
|
||||
;; ── Record patterns ───────────────────────────────────────────
|
||||
(epoch 2600)
|
||||
(eval "(ocaml-run \"match { x = 1; y = 2 } with | { x = a; y = b } -> a + b\")")
|
||||
(epoch 2601)
|
||||
(eval "(ocaml-run \"match { name = \\\"Bob\\\"; age = 30 } with | { name = n; age = a } -> a\")")
|
||||
(epoch 2602)
|
||||
(eval "(ocaml-run \"match { x = 1; y = 2 } with | { x = 1; y = y } -> y | _ -> 0\")")
|
||||
(epoch 2603)
|
||||
(eval "(ocaml-run \"match { x = 5; y = 2 } with | { x = 1; y = y } -> y | _ -> 0\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -1496,6 +1506,12 @@ check 2501 "polyvar Some 42" '("Some" 42)'
|
||||
check 2502 "polyvar match" '1'
|
||||
check 2503 "polyvar Pair (a,b)" '3'
|
||||
|
||||
# ── Record patterns ────────────────────────────────────────────
|
||||
check 2600 "match record bind both" '3'
|
||||
check 2601 "match record name+age" '30'
|
||||
check 2602 "match record literal x=1" '2'
|
||||
check 2603 "match record literal fail" '0'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user