Skip to content

Commit ac4401c

Browse files
bensudnolen
authored andcommitted
CLJS-1451 Protocol impl do not support qualified method names
To solve the issue, the method's namespace is completely ignored, which makes methods with the right name but the wrong namespace legal.
1 parent 6e7541b commit ac4401c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/main/clojure/cljs/core.cljc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@
14031403
(ifn-invoke-methods type type-sym form))))
14041404

14051405
(core/defn- add-proto-methods* [pprefix type type-sym [f & meths :as form]]
1406-
(core/let [pf (core/str pprefix f)]
1406+
(core/let [pf (core/str pprefix (name f))]
14071407
(if (vector? (first meths))
14081408
;; single method case
14091409
(core/let [meth meths]
@@ -1435,9 +1435,10 @@
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)
14381439
[fname sigs] (if (core/vector? (second method))
1439-
[(first method) [(second method)]]
1440-
[(first method) (map first (rest method))])
1440+
[(->name method) [(second method)]]
1441+
[(->name method) (map first (rest method))])
14411442
decmeths (core/get minfo fname ::not-found)]
14421443
(core/when (= decmeths ::not-found)
14431444
(ana/warning :protocol-invalid-method env {:protocol p :fname fname :no-such-method true}))

src/test/cljs/cljs/core_test.cljs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2936,6 +2936,14 @@
29362936
(is (= (hash (.toString #uuid "0d1f9029-40fc-4728-8bdd-9862172d4370"))
29372937
(hash (.toString (UUID. "0d1f9029-40fc-4728-8bdd-9862172d4370" nil))))))
29382938

2939+
(defprotocol IFooBar
2940+
(a-method [t]))
2941+
2942+
(deftest test-cljs-1451
2943+
(is (= "foobar" (a-method (reify
2944+
IFooBar
2945+
(cljs.core-test/a-method [_] "foobar"))))))
2946+
29392947
(comment
29402948
;; ObjMap
29412949
;; (let [ks (map (partial str "foo") (range 500))

0 commit comments

Comments
 (0)