Skip to content

Commit

Permalink
[#440] Aliases in protocol functions should work
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Nov 10, 2020
1 parent 31acbf0 commit c7c223a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/sci/impl/protocols.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
`(do ~@(map (fn [[type & meths]]
`(do
~@(map (fn [meth]
`(defmethod ~(fq-meth-name (str (first meth)))
`(defmethod ~(fq-meth-name (name (first meth)))
~type
~(second meth) ~@(nnext meth)))
meths)))
Expand Down Expand Up @@ -101,7 +101,7 @@
fq-meth-name #(symbol pns %)]
`(do
~@(map (fn [meth]
`(defmethod ~(fq-meth-name (str (first meth)))
`(defmethod ~(fq-meth-name (name (first meth)))
~type ~(second meth) ~@(nnext meth)))
meths)))) proto+meths))))

Expand Down
35 changes: 34 additions & 1 deletion test/sci/protocols_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,40 @@
(str/replace "String" "js/String")))]
(is (true? (tu/eval* prog #?(:clj {}
:cljs {:classes {:allow :all
'js #js {:String js/String}}}))))))
'js #js {:String js/String}}})))))
(testing "Aliases are allowed and ignored"
(let [prog "
(ns foo) (defprotocol Foo (foo [this]))
(ns bar (:require [foo :as f]))
(extend-type String
f/Foo
(f/foo [this] (subs this 0 1)))
(= \"f\" (f/foo \"foo\"))
"
prog #?(:clj prog
:cljs (-> prog
(str/replace "String" "js/String")))]
(is (true? (tu/eval* prog #?(:clj {}
:cljs {:classes {:allow :all
'js #js {:String js/String}}})))))
(let [prog "
(ns foo) (defprotocol Foo (foo [this]))
(ns bar (:require [foo :as f]))
(extend-protocol f/Foo
String
(f/foo [this] (subs this 0 1)))
(= \"f\" (f/foo \"foo\"))
"
prog #?(:clj prog
:cljs (-> prog
(str/replace "String" "js/String")))]
(is (true? (tu/eval* prog #?(:clj {}
:cljs {:classes {:allow :all
'js #js {:String js/String}}})))))))

(deftest extend-via-metadata-test
(let [prog "
Expand Down

0 comments on commit c7c223a

Please sign in to comment.