Skip to content

Commit 89b1a31

Browse files
bensudnolen
authored andcommitted
Warn if protocol impl methods do not match its protocol
Check if the provided method names exist and belong to the associated protocol.
1 parent ac4401c commit 89b1a31

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/main/clojure/cljs/core.cljc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,13 +1435,20 @@
14351435
(core/when-not (= p 'Object)
14361436
(core/let [var (ana/resolve-var (dissoc env :locals) p)
14371437
minfo (core/-> var :protocol-info :methods)
1438-
->name (comp symbol name first)
1438+
method-name (first method)
1439+
->name (comp symbol name)
14391440
[fname sigs] (if (core/vector? (second method))
1440-
[(->name method) [(second method)]]
1441-
[(->name method) (map first (rest method))])
1441+
[(->name method-name) [(second method)]]
1442+
[(->name method-name) (map first (rest method))])
14421443
decmeths (core/get minfo fname ::not-found)]
14431444
(core/when (= decmeths ::not-found)
14441445
(ana/warning :protocol-invalid-method env {:protocol p :fname fname :no-such-method true}))
1446+
(core/when (namespace method-name)
1447+
(core/let [method-var (ana/resolve-var (dissoc env :locals) method-name
1448+
ana/confirm-var-exist-warning)]
1449+
(core/when-not (= (:name var) (:protocol method-var))
1450+
(ana/warning :protocol-invalid-method env
1451+
{:protocol p :fname method-name :no-such-method true}))))
14451452
(core/loop [sigs sigs seen #{}]
14461453
(core/when (seq sigs)
14471454
(core/let [sig (first sigs)

0 commit comments

Comments
 (0)