Skip to content

Commit 2f012ce

Browse files
author
dnolen
committed
CLJS-1663: Calling instrumented multi-arity function causes exception
when instrumenting we set! the var to the spec verifying fn but this meant that arity references for correct dispatching would be missing link the arities from the original function object to the spec verifying fn via goog.object/extend
1 parent a4d9ccc commit 2f012ce

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/main/cljs/cljs/spec.cljs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
(:refer-clojure :exclude [+ * and or cat def keys])
1111
(:require-macros [cljs.core :as c]
1212
[cljs.spec :as s])
13-
(:require [cljs.core :as c]
13+
(:require [goog.object :as gobj]
14+
[cljs.core :as c]
1415
[clojure.walk :as walk]
1516
[cljs.spec.impl.gen :as gen]
1617
[clojure.string :as str]))
@@ -280,19 +281,21 @@
280281
(str "Call to " v " did not conform to spec:\n" (with-out-str (explain-out ed)))
281282
ed)))
282283
conformed)))]
283-
(c/fn
284-
[& args]
285-
(if *instrument-enabled*
286-
(s/with-instrument-disabled
287-
(let [specs (fn-specs v)]
288-
(let [cargs (when (:args specs) (conform! v :args (:args specs) args args))
289-
ret (binding [*instrument-enabled* true]
290-
(apply f args))
291-
cret (when (:ret specs) (conform! v :ret (:ret specs) ret args))]
292-
(when (c/and (:args specs) (:ret specs) (:fn specs))
293-
(conform! v :fn (:fn specs) {:args cargs :ret cret} args))
294-
ret)))
295-
(apply f args)))))
284+
(doto
285+
(c/fn
286+
[& args]
287+
(if *instrument-enabled*
288+
(s/with-instrument-disabled
289+
(let [specs (fn-specs v)]
290+
(let [cargs (when (:args specs) (conform! v :args (:args specs) args args))
291+
ret (binding [*instrument-enabled* true]
292+
(apply f args))
293+
cret (when (:ret specs) (conform! v :ret (:ret specs) ret args))]
294+
(when (c/and (:args specs) (:ret specs) (:fn specs))
295+
(conform! v :fn (:fn specs) {:args cargs :ret cret} args))
296+
ret)))
297+
(apply f args)))
298+
(gobj/extend f))))
296299

297300
;(defn- macroexpand-check
298301
; [v args]

0 commit comments

Comments
 (0)