Details
-
Type:
Enhancement
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Declined
-
Affects Version/s: Release 1.4
-
Fix Version/s: Release 1.5
-
Component/s: None
-
Labels:
-
Patch:Code
-
Approval:Not Approved
Description
The compiler accepts this:
(deftype foo []
clojure.lang.IFn
(invoke [this & xs]))
However calling ((foo.) :bar) will throw an AbstractMethodError. Wouldn't some checking be desirable?
First of all, clojure.lang.IFn is no protocol but an interface. And it does not declare a
method. It has an `invoke` method with 20 Object parameters followed by an Object... parameter, but to give an implementation for that, you have to specify every parameter separately, and the last Object... arg is just a normal argument that must be an Object[]. That's because Java-varags Type... parameters are just Java syntax sugar, but in the byte-code its simply a Type-array.
What your example does is provide an `invoke` implementation for the 2-args version, where the first parameter happens to be named `&`, which has no special meaning here. Take that example:
(deftype MyFoo [] clojure.lang.IFn (invoke [this & xs] [& xs])) ((MyFoo.) 1 2) => [1 2]But you are right in that `deftype`, `defrecord`, `defprotocol`, and `definferface` probably should error if user's seem to try to use varargs or destructuring.
(deftype MyFoo [] clojure.lang.IFn (invoke [this & xs] [& xs])) ((MyFoo.) 1 2) => [1 2]