File tree Expand file tree Collapse file tree 3 files changed +43
-16
lines changed Expand file tree Collapse file tree 3 files changed +43
-16
lines changed Original file line number Diff line number Diff line change @@ -288,16 +288,22 @@ spec itself will have an ::s/failure value in ex-data:
288
288
(fn [sym]
289
289
(do `(check-1 '~sym nil nil ~opts-sym)))))]))))
290
290
291
- (defmacro ^:private maybe-setup-static-dispatch [f ret arity]
291
+ (defmacro ^:private maybe-setup-static-dispatch [f ret conform! arity]
292
292
(let [arity-accessor (symbol (str " .-cljs$core$IFn$_invoke$arity$" arity))
293
293
argv (mapv #(symbol (str " arg" %)) (range arity))]
294
- `(when ( some? (~arity-accessor ~f))
294
+ `(when- some [ac# (~arity-accessor ~f)]
295
295
(set! (~arity-accessor ~ret)
296
- (fn ~argv
297
- (apply ~ret ~argv))))))
298
-
299
- (defmacro ^:private setup-static-dispatches [f ret max-arity]
296
+ (fn ~argv
297
+ (if *instrument-enabled*
298
+ (with-instrument-disabled
299
+ (~conform! ~argv)
300
+ (binding [*instrument-enabled* true ]
301
+ (ac# ~@argv)))
302
+ (ac# ~@argv)))))))
303
+
304
+ (defmacro ^:private setup-static-dispatches [f ret conform! max-arity]
305
+ ; ; ret is for when we don't have arity info
300
306
`(do
301
307
~@(mapv (fn [arity]
302
- `(maybe-setup-static-dispatch ~f ~ret ~arity))
308
+ `(maybe-setup-static-dispatch ~f ~ret ~conform! ~ arity))
303
309
(range (inc max-arity)))))
Original file line number Diff line number Diff line change 87
87
(defn- spec-checking-fn
88
88
[v f fn-spec]
89
89
(let [fn-spec (@#'s/maybe-spec fn-spec)
90
+ args-spec (:args fn-spec)
90
91
conform! (fn [v role spec data args]
91
92
(let [conformed (s/conform spec data)]
92
93
(if (= ::s/invalid conformed)
112
113
pure-variadic?)
113
114
(.cljs$core$IFn$_invoke$arity$variadic f)
114
115
(apply f args)))
115
- ret (fn [& args]
116
- (if *instrument-enabled*
117
- (with-instrument-disabled
118
- (when (:args fn-spec) (conform! v :args (:args fn-spec) args args))
119
- (binding [*instrument-enabled* true ]
120
- (apply' f args)))
121
- (apply' f args)))]
122
- (when-not pure-variadic?
123
- (setup-static-dispatches f ret 20 )
116
+ conform!* #(conform! v :args args-spec % %)
117
+ ret (if args-spec
118
+ (fn [& args]
119
+ (if *instrument-enabled*
120
+ (with-instrument-disabled
121
+ (conform!* args)
122
+ (binding [*instrument-enabled* true ]
123
+ (apply' f args)))
124
+ (apply' f args)))
125
+ f)]
126
+ (when (and (not pure-variadic?) args-spec)
127
+ (setup-static-dispatches f ret conform!* 20 )
124
128
(when-some [variadic (.-cljs$core$IFn$_invoke$arity$variadic f)]
125
129
(set! (.-cljs$core$IFn$_invoke$arity$variadic ret)
126
130
(fn [& args]
Original file line number Diff line number Diff line change 117
117
(testing " instrument and unstrument return empty coll when no fdef exists"
118
118
(is (empty? (stest/instrument `fn-2975)))
119
119
(is (empty? (stest/unstrument `fn-2975)))))
120
+
121
+ (defn fn-2995
122
+ ([] (fn-2995 0 ))
123
+ ([a] (fn-2995 a 1 ))
124
+ ([a b] [a b]))
125
+
126
+ (s/fdef fn-2995
127
+ :args (s/cat :a (s/? number?)
128
+ :b (s/? number?)))
129
+
130
+ (deftest test-2995
131
+ (stest/instrument `fn-2995)
132
+ (testing " instrumented self-calling multi-arity function works"
133
+ (is (= [0 1 ] (fn-2995 0 1 )))
134
+ (is (= [0 1 ] (fn-2995 0 )))
135
+ (is (= [0 1 ] (fn-2995 0 )))
136
+ (is (thrown? js/Error (fn-2995 " not a number" )))))
You can’t perform that action at this time.
0 commit comments