You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Parsing a map literal that has a splicing reader conditional in it throws an exception.
repro
$ deps-try borkdude/edamame 1.3.22
[Rebel readline] Type :repl/help for online help info
user=> (require '[edamame.core :as e])
nil
user=> (e/parse-string-all "(def example {:a 1 #?@(:clj [:b 2 :c 3])})" {:read-cond :allow})
[(def example {:a 1})]
user=> (e/parse-string-all "(def example {:a 1 #?@(:clj [:b 2 :c 3])})" {:read-cond :preserve})
Execution error (ExceptionInfo) at edamame.impl.parser/throw-reader (parser.cljc:44).
The map literal starting with :a contains 3 form(s). Map literals must contain an even number of forms.
user=> (e/parse-string-all "(def example {:a 1 #?@(:clj [:b 2 :c 3])})" {:read-cond (fn [obj] (list 'read-cond obj))})
Execution error (ExceptionInfo) at edamame.impl.parser/throw-reader (parser.cljc:44).
The map literal starting with :a contains 3 form(s). Map literals must contain an even number of forms.
expected behavior
I'm honestly not sure how to handle it. Unlike clj-kondo (cf clj-kondo #2049), edamame doesn't produce multiple versions of a given string/file so it's not really feasible to expand in the same way.
Maybe an edamame keyword to vector that contains each splicing reader conditional? This would work with :allow, :preserve, and the function option.
{:a 1 #?@(:clj [:b 2 :c 3]) #?@(:clj [:d 4 :e 5])} read in as {:a 1 :edamame.impl.parser/read-cond [(:clj [:b 2 :c 3]) (:clj [:d 4 :e 5])]}. That doesn't warn when one of them will produce an incorrect map (odd number of entries in the spliced vector), but that feels outside of edamame's scope.
The above problem is the same with Clojure's own reader:
$ clj
Clojure 1.11.0
user=> (read-string {:read-cond :preserve} "(def example {:a 1 #?@(:clj [:b 2 :c 3])})")
Execution error at user/eval1 (REPL:1).
Map literal must contain an even number of forms
How clj-kondo does this: it first parses the file using the first reader conditional feature, then lints that and then does the same for the second reader conditional.
version
1.3.22
platform
Ubuntu
problem
Parsing a map literal that has a splicing reader conditional in it throws an exception.
repro
expected behavior
I'm honestly not sure how to handle it. Unlike clj-kondo (cf clj-kondo #2049), edamame doesn't produce multiple versions of a given string/file so it's not really feasible to expand in the same way.
Maybe an edamame keyword to vector that contains each splicing reader conditional? This would work with
:allow
,:preserve
, and the function option.{:a 1 #?@(:clj [:b 2 :c 3]) #?@(:clj [:d 4 :e 5])}
read in as{:a 1 :edamame.impl.parser/read-cond [(:clj [:b 2 :c 3]) (:clj [:d 4 :e 5])]}
. That doesn't warn when one of them will produce an incorrect map (odd number of entries in the spliced vector), but that feels outside of edamame's scope.full stack trace
The text was updated successfully, but these errors were encountered: