core: enforce fn arity in both modes (jolt-6xn); canonical seq-to-map-for-destructuring
Fixed arities now throw Clojure's ArityException shape — 'Wrong number of
args (N) passed to: name' — on any count mismatch; variadic arities on fewer
than their fixed params. The compiled path already enforced fixed arities via
janet's native fn check and multi-arity dispatch; this adds the check to the
interpreter's single-arity closures (the oracle was silently dropping extra
args and giving a raw tuple-index error for missing ones) and guards the
compiled single-variadic wrapper's minimum. Messages carry the fn name when
there is one. 16 spec rows; the update.cljc suite row flipped green (4703 ->
4704).
Enforcement exposed that seq-to-map-for-destructuring had drifted: the spec
row called the 1-arity fn with two args, and the body silently dropped a
trailing unpaired element. Replaced with the canonical Clojure 1.11 version
(even pairs build the map, a single trailing element passes through — so
(f {:b 2}) kwargs calls work — and an unpaired key throws).
Also: transients RFC notes tuple support from the seed-shrink rounds.
This commit is contained in:
parent
501c6bf9c9
commit
9e9fd19450
6 changed files with 66 additions and 12 deletions
|
|
@ -194,3 +194,24 @@
|
|||
["one extra" "'(2)" "((fn [a & r] r) 1 2)"]
|
||||
["rest destructure with no args" ":nil"
|
||||
"((fn [& [a]] (if a :truthy :nil)))"])
|
||||
|
||||
# Arity enforcement (jolt-6xn): fixed arities throw on any mismatch, variadic
|
||||
# arities on fewer than the fixed params — Clojure's ArityException, in both
|
||||
# the interpreter and the compiled path.
|
||||
(defspec "functions / arity enforcement"
|
||||
["fixed extra args" :throws "((fn [x] x) 1 2)"]
|
||||
["fixed missing args" :throws "((fn [x y] x) 1)"]
|
||||
["fixed zero of one" :throws "((fn [x] x))"]
|
||||
["named defn extra" :throws "(do (defn af1 [x] x) (af1 1 2))"]
|
||||
["overlay fn extra" :throws "(identity 1 2)"]
|
||||
["through apply" :throws "(apply (fn [x] x) [1 2])"]
|
||||
["through update" :throws "(update {:k 1} :k identity 1 2 3 4)"]
|
||||
["variadic below min" :throws "((fn [x & r] x))"]
|
||||
["variadic at min" "nil" "((fn [x & r] r) 1)"]
|
||||
["variadic above min" "(quote (2 3))" "((fn [x & r] r) 1 2 3)"]
|
||||
["multi-arity no match" :throws "((fn ([x] x) ([x y] y)) 1 2 3)"]
|
||||
["multi-arity variadic below min" :throws "((fn ([x] x) ([x y & r] r)))"]
|
||||
["destructured param counts as one" "3" "((fn [[a b] c] c) [1 2] 3)"]
|
||||
["destructured extra throws" :throws "((fn [[a b]] a) [1 2] [3 4])"]
|
||||
["hof exact arity ok" "[2 4]" "(mapv (fn [x] (* 2 x)) [1 2])"]
|
||||
["zero-arity fn ok" "7" "((fn [] 7))"])
|
||||
|
|
|
|||
|
|
@ -157,7 +157,10 @@
|
|||
["special-symbol? if" "true" "(special-symbol? (quote if))"]
|
||||
["special-symbol? fn name" "false" "(special-symbol? (quote foo))"]
|
||||
["destructure expands" "true" "(pos? (count (destructure (quote [[a b] x]))))"]
|
||||
["seq-to-map-for-destructuring" "{:a 1}" "(seq-to-map-for-destructuring (quote (:a 1)) nil)"]
|
||||
["seq-to-map-for-destructuring" "{:a 1}" "(seq-to-map-for-destructuring (quote (:a 1)))"]
|
||||
["s2m trailing map passes through" "{:b 2}" "(seq-to-map-for-destructuring (list {:b 2}))"]
|
||||
["s2m unpaired key throws" :throws "(seq-to-map-for-destructuring (quote (:a 1 :b)))"]
|
||||
["s2m kwargs trailing map call" "2" "((fn [& {:keys [b]}] b) {:b 2})"]
|
||||
["*clojure-version* major" "1" "(:major *clojure-version*)"]
|
||||
["*ns* user" "\"user\"" "(str *ns*)"]
|
||||
["*1 nil outside repl" "nil" "*1"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue