nbb icon indicating copy to clipboard operation
nbb copied to clipboard

Keyword argument fns don't accept map arguments

Open logseq-cldwalker opened this issue 2 years ago • 2 comments

Hi @borkdude. With cljs 1.11, keyword arg fns can accept maps. This seems to work in bb but not in nbb. This is not an urgent bug but it could be nice to be at 1.11 parity at some point


version

0.5.103

platform

osx and node 16.13.1

problem

Define a fn that takes keyword args and pass it a map. See the call fail

repro

Create the following file example.cljc:

(ns example
  (:require
   [clojure.test :as t :refer [deftest is]]))

(defn destr [& {:keys [a b] :as opts}]
  [a b opts])

(deftest keyword-arg
  (is (= [1 nil {:a 1}]
         (destr :a 1)))

  (is (= [1 2 {:a 1 :b 2}]
         (destr {:a 1 :b 2}))))

(defn run-tests []
  (t/run-tests 'example))

Run the test:

$ nbb -m example/run-tests

Testing example

ERROR in (keyword-arg) (:12:7)
expected: (= [1 2 {:a 1, :b 2}] (destr {:a 1, :b 2}))
  actual: #object[Error Error: No value supplied for key: {:a 1, :b 2}]

Ran 1 tests containing 2 assertions.
0 failures, 1 errors.

Running this with bb does pass: bb -cp . -m example/run-tests

expected behavior

Expected this to pass

logseq-cldwalker avatar May 17 '22 20:05 logseq-cldwalker

@logseq-cldwalker Thanks. If you want to look into this a bit before I get to it, related logic in SCI is here: https://github.com/babashka/sci/blob/bb3031eaabd0b1b30fdb9a2d5969a48dba959cc6/src/sci/impl/namespaces.cljc#L798

borkdude avatar May 17 '22 21:05 borkdude

The full commit that made it work for SCI on Clojure 1.11: https://github.com/babashka/sci/commit/b6ab05d5e4b0d6df594a6e03a5849caf82caecb3

borkdude avatar May 17 '22 21:05 borkdude

Fixed in 1.2.164

borkdude avatar Feb 24 '23 11:02 borkdude

Thanks! Works great

cldwalker avatar Feb 25 '23 19:02 cldwalker