From f22cae3278e8ea5f3f4a39ce7bd4081c594eaf80 Mon Sep 17 00:00:00 2001 From: Michael Blume Date: Sat, 1 Apr 2017 16:39:50 -0700 Subject: [PATCH] Require that defhelper arglist has two elements one for the map and one for varargs Add & to metadata arglists, make them correct --- src/honeysql/helpers.cljc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/honeysql/helpers.cljc b/src/honeysql/helpers.cljc index 1d3b517..c89726d 100644 --- a/src/honeysql/helpers.cljc +++ b/src/honeysql/helpers.cljc @@ -15,9 +15,14 @@ #?(:clj (defmacro defhelper [helper arglist & more] - (let [kw (keyword (name helper))] + (when-not (vector? arglist) + (throw (IllegalArgumentException. "arglist must be a vector"))) + (when-not (= (count arglist) 2) + (throw (IllegalArgumentException. "arglist must have two entries, map and varargs"))) + (let [kw (keyword (name helper)) + [m-arg varargs] arglist] `(do - (defmethod build-clause ~kw ~(into ['_] arglist) ~@more) + (defmethod build-clause ~kw ~['_ m-arg varargs] ~@more) (defn ~helper [& args#] (let [[m# args#] (if (plain-map? (first args#)) [(first args#) (rest args#)] @@ -30,8 +35,8 @@ (var ~helper) assoc :arglists - '(~(into [] (rest arglist)) - ~(into [(first arglist)] (rest arglist)))))))) + '(~['& varargs] + ~[m-arg '& varargs])))))) (defn collify [x] (if (coll? x) x [x]))