Skip to content

Commit 1c1eef9

Browse files
Ensure defn metadata are always preserved as a map (#1187)
Hi, can you please review patch to merge the `attr-map?` and the metadata in `defn` using a `loop` rather than `conj`. It addresses #1186. The previous `conj` operation was return in a list rather than a map. This also appears to be the likely cause why the `:decorators` meta key didn't work when passed in as `defn` metadata in `defasync`. I've updated the test suite for the same. Thanks Co-authored-by: ikappaki <[email protected]> Co-authored-by: Chris Rink <[email protected]>
1 parent f81b7b6 commit 1c1eef9

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Changed
99
* `import` now returns nil instead of the last module's string representation (#1174)
1010

11+
### Fixed
12+
* Fix a bug in `defn` where the `attr-map?` and function metdata were merged into a seq instead of a map, causing `macroexpand` to fail in some cases (#1186)
13+
1114
## [v0.3.5]
1215
### Changed
1316
* `alter-var-root` now returns the new value to align with Clojure behavior. Updated the docstring to highlight side effects of direct linking optimization (#1166)

src/basilisp/core.lpy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@
383383
(first body)
384384
nil)
385385
fname (if fmeta
386-
(vary-meta name conj fmeta)
386+
(vary-meta name #(conj {} %1 %2) fmeta)
387387
name)
388388
fname (if doc
389389
(vary-meta fname assoc :doc doc)

tests/basilisp/test_core_macros.lpy

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,24 @@
7979
(is (= 'f8 (:name vmeta)))
8080
(is (= '([] [a]) (:arglists vmeta)))
8181
(is (= "0.1" (:added vmeta)))
82-
(is (= "another multi-arity docstring" (:doc vmeta)))))))
82+
(is (= "another multi-arity docstring" (:doc vmeta))))))
83+
84+
(testing "meta"
85+
(let [fvar (defn ^{:abc 9} f9 [] :kw)
86+
vmeta (meta fvar)]
87+
(is (= 'f9 (:name vmeta)))
88+
(is (= '([]) (:arglists vmeta)))
89+
(is (= 9 (:abc vmeta)))))
90+
91+
(testing "attr-map? and meta"
92+
(let [fvar (defn ^{:abc 9 :lmn 15} f10 {:abc 10 :xyz 11} [] :kw)
93+
vmeta (meta fvar)]
94+
(is (= 'f10 (:name vmeta)))
95+
(is (= '([]) (:arglists vmeta)))
96+
(is (= {:abc 10 :lmn 15 :xyz 11} (select-keys vmeta [:abc :lmn :xyz])))))
97+
98+
(testing "macroexpand with attr-map?"
99+
(is (macroexpand '(defn fx {:abc 10} [] :kw)))))
83100

84101
(deftest defasync-test
85102
(testing "single arity defasync"

0 commit comments

Comments
 (0)