Skip to content

Commit 7a0ec41

Browse files
committed
CLJS-3257: satisfies? produces an inference warning when given an unhinted argument
We're checking protocol methods so mark the symbol as such. Add test case.
1 parent 946348d commit 7a0ec41

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/main/clojure/cljs/core.cljc

+4-2
Original file line numberDiff line numberDiff line change
@@ -2212,15 +2212,17 @@
22122212
`(let [~xsym ~x]
22132213
(if-not (nil? ~xsym)
22142214
(if (or ~(if bit `(unsafe-bit-and (. ~xsym ~msym) ~bit) false)
2215-
(identical? cljs.core/PROTOCOL_SENTINEL (. ~xsym ~(symbol (core/str "-" prefix)))))
2215+
(identical? cljs.core/PROTOCOL_SENTINEL
2216+
(. ~xsym ~(with-meta (symbol (core/str "-" prefix)) {:protocol-method true}))))
22162217
true
22172218
(if (coercive-not (. ~xsym ~msym))
22182219
(cljs.core/native-satisfies? ~psym ~xsym)
22192220
false))
22202221
(cljs.core/native-satisfies? ~psym ~xsym)))
22212222
`(if-not (nil? ~x)
22222223
(if (or ~(if bit `(unsafe-bit-and (. ~x ~msym) ~bit) false)
2223-
(identical? cljs.core/PROTOCOL_SENTINEL (. ~x ~(symbol (core/str "-" prefix)))))
2224+
(identical? cljs.core/PROTOCOL_SENTINEL
2225+
(. ~x ~(with-meta (symbol (core/str "-" prefix)) {:protocol-method true}))))
22242226
true
22252227
(if (coercive-not (. ~x ~msym))
22262228
(cljs.core/native-satisfies? ~psym ~x)

src/test/clojure/cljs/externs_infer_tests.clj

+15
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,21 @@
398398
:with-core? true}))]
399399
(is (empty? @ws))))
400400

401+
(deftest test-cljs-3257
402+
(let [ws (atom [])
403+
res (binding [ana/*cljs-static-fns* true]
404+
(infer-test-helper
405+
{:forms '[(ns app.core)
406+
(set! *warn-on-infer* true)
407+
(defprotocol IFoo
408+
(bar [this]))
409+
(defn not-ok? [v]
410+
(satisfies? IFoo v))]
411+
:warnings ws
412+
:warn true
413+
:with-core? true}))]
414+
(is (empty? @ws))))
415+
401416
(comment
402417
(binding [ana/*cljs-ns* ana/*cljs-ns*]
403418
(ana/no-warn

0 commit comments

Comments
 (0)