Skip to content

Commit c7c223a

Browse files
committed
[#440] Aliases in protocol functions should work
1 parent 31acbf0 commit c7c223a

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

src/sci/impl/protocols.cljc

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
`(do ~@(map (fn [[type & meths]]
6363
`(do
6464
~@(map (fn [meth]
65-
`(defmethod ~(fq-meth-name (str (first meth)))
65+
`(defmethod ~(fq-meth-name (name (first meth)))
6666
~type
6767
~(second meth) ~@(nnext meth)))
6868
meths)))
@@ -101,7 +101,7 @@
101101
fq-meth-name #(symbol pns %)]
102102
`(do
103103
~@(map (fn [meth]
104-
`(defmethod ~(fq-meth-name (str (first meth)))
104+
`(defmethod ~(fq-meth-name (name (first meth)))
105105
~type ~(second meth) ~@(nnext meth)))
106106
meths)))) proto+meths))))
107107

test/sci/protocols_test.cljc

+34-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,40 @@
9191
(str/replace "String" "js/String")))]
9292
(is (true? (tu/eval* prog #?(:clj {}
9393
:cljs {:classes {:allow :all
94-
'js #js {:String js/String}}}))))))
94+
'js #js {:String js/String}}})))))
95+
(testing "Aliases are allowed and ignored"
96+
(let [prog "
97+
(ns foo) (defprotocol Foo (foo [this]))
98+
(ns bar (:require [foo :as f]))
99+
100+
(extend-type String
101+
f/Foo
102+
(f/foo [this] (subs this 0 1)))
103+
104+
(= \"f\" (f/foo \"foo\"))
105+
"
106+
prog #?(:clj prog
107+
:cljs (-> prog
108+
(str/replace "String" "js/String")))]
109+
(is (true? (tu/eval* prog #?(:clj {}
110+
:cljs {:classes {:allow :all
111+
'js #js {:String js/String}}})))))
112+
(let [prog "
113+
(ns foo) (defprotocol Foo (foo [this]))
114+
(ns bar (:require [foo :as f]))
115+
116+
(extend-protocol f/Foo
117+
String
118+
(f/foo [this] (subs this 0 1)))
119+
120+
(= \"f\" (f/foo \"foo\"))
121+
"
122+
prog #?(:clj prog
123+
:cljs (-> prog
124+
(str/replace "String" "js/String")))]
125+
(is (true? (tu/eval* prog #?(:clj {}
126+
:cljs {:classes {:allow :all
127+
'js #js {:String js/String}}})))))))
95128

96129
(deftest extend-via-metadata-test
97130
(let [prog "

0 commit comments

Comments
 (0)