Skip to content

Commit a0fff5a

Browse files
committed
Sure
1 parent be2448a commit a0fff5a

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
@@ -7010,7 +7010,7 @@
70107010
(dissoc! m k)))
70117011
(transient (.- self -proxy-mappings)))
70127012
(persistent!))]
7013-
(set! (.- self -proxy-mappings) updated-mappings)
7013+
(. self (_set_proxy_mappings updated-mappings))
70147014
nil))
70157015
"_proxy_mappings" nil}
70167016

@@ -7102,7 +7102,6 @@
71027102
(. proxy (_update-proxy-mappings mappings))
71037103
proxy)))
71047104

7105-
;; TODO: kwargs on supertypes
71067105
;; TODO: check interface/superclass method membership
71077106
(defmacro proxy
71087107
"Create a new proxy class instance.
@@ -7131,26 +7130,39 @@
71317130
([arg1] ...)
71327131
([arg1 & others] ...))
71337132

7133+
.. note::
7134+
7135+
Proxy override methods can be defined with Python keyword argument support since
7136+
they are just standard Basilisp functions. See :ref:`basilisp_functions_with_kwargs`
7137+
for more information.
7138+
71347139
.. warning::
71357140

71367141
The ``proxy`` macro does not verify that the provided override implementations
71377142
arities match those of the method being overridden."
71387143
[class-and-interfaces args & fs]
71397144
(let [formatted-single (fn [method-name [arg-vec & body]]
7140-
[(munge method-name)
7141-
(apply list 'fn method-name (vec (concat ['this] arg-vec)) body)])
7145+
(apply list
7146+
'fn
7147+
method-name
7148+
(with-meta (vec (concat ['this] arg-vec)) (meta arg-vec))
7149+
body))
71427150
formatted-multi (fn [method-name & arities]
7143-
[(munge method-name)
7144-
(apply list
7145-
'fn
7146-
method-name
7147-
(map (fn [[arg-vec & body]]
7148-
(apply list (vec (concat ['this] arg-vec)) body))
7149-
arities))])
7150-
methods (map (fn [[method-name & body]]
7151-
(if (vector? (first body))
7152-
(formatted-single method-name body)
7153-
(apply formatted-multi method-name body)))
7151+
(apply list
7152+
'fn
7153+
method-name
7154+
(map (fn [[arg-vec & body]]
7155+
(apply list
7156+
(with-meta (vec (concat ['this] arg-vec)) (meta arg-vec))
7157+
body))
7158+
arities)))
7159+
methods (map (fn [[method-name & body :as form]]
7160+
[(munge method-name)
7161+
(with-meta
7162+
(if (vector? (first body))
7163+
(formatted-single method-name body)
7164+
(apply formatted-multi method-name body))
7165+
(meta form))])
71547166
fs)
71557167
method-map (reduce* (fn [m [method-name method]]
71567168
(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)