|
270 | 270 | [name doc-string? attr-map? ([params*] prepost-map? body)+ attr-map?]) |
271 | 271 | :added "1.0"} |
272 | 272 | defn (fn defn [&form &env name & fdecl] |
| 273 | + ;; Note: Cannot delegate this check to def because of the call to (with-meta name ..) |
| 274 | + (if (instance? clojure.lang.Symbol name) |
| 275 | + nil |
| 276 | + (throw (IllegalArgumentException. "First argument to defn must be a symbol"))) |
273 | 277 | (let [m (if (string? (first fdecl)) |
274 | 278 | {:doc (first fdecl)} |
275 | 279 | {}) |
|
4031 | 4035 | [& sigs] |
4032 | 4036 | (let [name (if (symbol? (first sigs)) (first sigs) nil) |
4033 | 4037 | sigs (if name (next sigs) sigs) |
4034 | | - sigs (if (vector? (first sigs)) (list sigs) sigs) |
| 4038 | + sigs (if (vector? (first sigs)) |
| 4039 | + (list sigs) |
| 4040 | + (if (seq? (first sigs)) |
| 4041 | + sigs |
| 4042 | + ;; Assume single arity syntax |
| 4043 | + (throw (IllegalArgumentException. |
| 4044 | + (if (seq sigs) |
| 4045 | + (str "Parameter declaration " |
| 4046 | + (first sigs) |
| 4047 | + " should be a vector") |
| 4048 | + (str "Parameter declaration missing")))))) |
4035 | 4049 | psig (fn* [sig] |
| 4050 | + ;; Ensure correct type before destructuring sig |
| 4051 | + (when (not (seq? sig)) |
| 4052 | + (throw (IllegalArgumentException. |
| 4053 | + (str "Invalid signature " sig |
| 4054 | + " should be a list")))) |
4036 | 4055 | (let [[params & body] sig |
| 4056 | + _ (when (not (vector? params)) |
| 4057 | + (throw (IllegalArgumentException. |
| 4058 | + (if (seq? (first sigs)) |
| 4059 | + (str "Parameter declaration " params |
| 4060 | + " should be a vector") |
| 4061 | + (str "Invalid signature " sig |
| 4062 | + " should be a list"))))) |
4037 | 4063 | conds (when (and (next body) (map? (first body))) |
4038 | 4064 | (first body)) |
4039 | 4065 | body (if conds (next body) body) |
|
6622 | 6648 | (defn- ^{:dynamic true} assert-valid-fdecl |
6623 | 6649 | "A good fdecl looks like (([a] ...) ([a b] ...)) near the end of defn." |
6624 | 6650 | [fdecl] |
6625 | | - (if-let [bad-args (seq (remove #(vector? %) (map first fdecl)))] |
6626 | | - (throw (IllegalArgumentException. (str "Parameter declaration " (first bad-args) " should be a vector"))))) |
| 6651 | + (when (empty? fdecl) (throw (IllegalArgumentException. |
| 6652 | + "Parameter declaration missing"))) |
| 6653 | + (let [argdecls (map |
| 6654 | + #(if (seq? %) |
| 6655 | + (first %) |
| 6656 | + (throw (IllegalArgumentException. |
| 6657 | + (if (seq? (first fdecl)) |
| 6658 | + (str "Invalid signature " |
| 6659 | + % |
| 6660 | + " should be a list") |
| 6661 | + (str "Parameter declaration " |
| 6662 | + % |
| 6663 | + " should be a vector"))))) |
| 6664 | + fdecl) |
| 6665 | + bad-args (seq (remove #(vector? %) argdecls))] |
| 6666 | + (when bad-args |
| 6667 | + (throw (IllegalArgumentException. (str "Parameter declaration " (first bad-args) |
| 6668 | + " should be a vector")))))) |
6627 | 6669 |
|
6628 | 6670 | (defn with-redefs-fn |
6629 | 6671 | "Temporarily redefines Vars during a call to func. Each val of |
|
0 commit comments