fix: def supports the 3-arg docstring form (def name doc value) in compile mode (jolt-6ym)
The analyzer always took (nth items 2) as the value, so (def x "doc" 42) bound x to the docstring and dropped 42. Now it mirrors the interpreter: when there are 4+ items and item 2 is a string, item 2 is the docstring (attached as :doc meta) and item 3 is the value. Conformance 335/335 x3.
This commit is contained in:
parent
19505a5944
commit
9813186ef9
1 changed files with 9 additions and 2 deletions
|
|
@ -159,9 +159,16 @@
|
|||
(when (< (count items) 3)
|
||||
(uncompilable "def with no init"))
|
||||
(let [nm (form-sym-name name-sym)
|
||||
cur (compile-ns ctx)]
|
||||
cur (compile-ns ctx)
|
||||
;; (def name docstring value): docstring is form 2, value form 3.
|
||||
;; Matches the interpreter; without this the docstring was taken
|
||||
;; as the value and the real init dropped (jolt-6ym).
|
||||
has-doc (and (> (count items) 3) (string? (nth items 2)))
|
||||
val-form (nth items (if has-doc 3 2))
|
||||
base-meta (or (form-sym-meta name-sym) {})
|
||||
node-meta (if has-doc (assoc base-meta :doc (nth items 2)) base-meta)]
|
||||
(host-intern! ctx cur nm)
|
||||
(def-node cur nm (analyze ctx (nth items 2) env) (form-sym-meta name-sym))))
|
||||
(def-node cur nm (analyze ctx val-form env) node-meta)))
|
||||
"let*" (let [bvec (vec (form-vec-items (nth items 1)))
|
||||
r (analyze-bindings ctx bvec env)]
|
||||
(let-node (first r) (analyze-seq ctx (drop 2 items) (second r))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue