Skip to content

Commit a5f22b7

Browse files
committed
Sure
1 parent 99fab72 commit a5f22b7

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

src/basilisp/core.lpy

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6870,7 +6870,7 @@
68706870
(dissoc! m k)))
68716871
(transient (.- self -proxy-mappings)))
68726872
(persistent!))]
6873-
(set! (.- self -proxy-mappings) updated-mappings)
6873+
(. self (_set_proxy_mappings updated-mappings))
68746874
nil))
68756875
"_proxy_mappings" nil}
68766876

@@ -6962,7 +6962,6 @@
69626962
(. proxy (_update-proxy-mappings mappings))
69636963
proxy)))
69646964

6965-
;; TODO: kwargs on supertypes
69666965
;; TODO: check interface/superclass method membership
69676966
(defmacro proxy
69686967
"Create a new proxy class instance.
@@ -6991,26 +6990,39 @@
69916990
([arg1] ...)
69926991
([arg1 & others] ...))
69936992

6993+
.. note::
6994+
6995+
Proxy override methods can be defined with Python keyword argument support since
6996+
they are just standard Basilisp functions. See :ref:`basilisp_functions_with_kwargs`
6997+
for more information.
6998+
69946999
.. warning::
69957000

69967001
The ``proxy`` macro does not verify that the provided override implementations
69977002
arities match those of the method being overridden."
69987003
[class-and-interfaces args & fs]
69997004
(let [formatted-single (fn [method-name [arg-vec & body]]
7000-
[(munge method-name)
7001-
(apply list 'fn method-name (vec (concat ['this] arg-vec)) body)])
7005+
(apply list
7006+
'fn
7007+
method-name
7008+
(with-meta (vec (concat ['this] arg-vec)) (meta arg-vec))
7009+
body))
70027010
formatted-multi (fn [method-name & arities]
7003-
[(munge method-name)
7004-
(apply list
7005-
'fn
7006-
method-name
7007-
(map (fn [[arg-vec & body]]
7008-
(apply list (vec (concat ['this] arg-vec)) body))
7009-
arities))])
7010-
methods (map (fn [[method-name & body]]
7011-
(if (vector? (first body))
7012-
(formatted-single method-name body)
7013-
(apply formatted-multi method-name body)))
7011+
(apply list
7012+
'fn
7013+
method-name
7014+
(map (fn [[arg-vec & body]]
7015+
(apply list
7016+
(with-meta (vec (concat ['this] arg-vec)) (meta arg-vec))
7017+
body))
7018+
arities)))
7019+
methods (map (fn [[method-name & body :as form]]
7020+
[(munge method-name)
7021+
(with-meta
7022+
(if (vector? (first body))
7023+
(formatted-single method-name body)
7024+
(apply formatted-multi method-name body))
7025+
(meta form))])
70147026
fs)
70157027
method-map (reduce* (fn [m [method-name method]]
70167028
(if-let [existing-method (get m method-name)]

tests/basilisp/test_proxies.lpy

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@
3737

3838
(deftest proxy-test
3939
(testing "disallows duplicate method overrides"
40-
(proxy [Describable] []
41-
(describe-me [] "I'm a proxy")
42-
(describe-me [] "Proxy")))
40+
(is (thrown? basilisp.lang.compiler/CompilerException
41+
(eval '(proxy [Describable] []
42+
(describe-me [] "I'm a proxy")
43+
(describe-me [] "Proxy"))))))
4344

4445
(testing "multi-arity interface methods"
4546
(let [p (proxy [ConcreteToString] [1]

0 commit comments

Comments
 (0)