diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jvm/clojure/lang/AFn.java | 3 | ||||
-rw-r--r-- | src/jvm/clojure/lang/ArityException.java | 32 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Compiler.java | 10 |
3 files changed, 42 insertions, 3 deletions
diff --git a/src/jvm/clojure/lang/AFn.java b/src/jvm/clojure/lang/AFn.java index a93cd7ed..26d2a56f 100644 --- a/src/jvm/clojure/lang/AFn.java +++ b/src/jvm/clojure/lang/AFn.java @@ -436,7 +436,6 @@ static public Object applyToHelper(IFn ifn, ISeq arglist) throws Exception{ public Object throwArity(int n){ String name = getClass().getSimpleName(); int suffix = name.lastIndexOf("__"); - throw new IllegalArgumentException("Wrong number of args (" + n + ") passed to: " - + (suffix == -1 ? name : name.substring(0, suffix)).replace('_', '-')); + throw new ArityException(n, (suffix == -1 ? name : name.substring(0, suffix)).replace('_', '-')); } } diff --git a/src/jvm/clojure/lang/ArityException.java b/src/jvm/clojure/lang/ArityException.java new file mode 100644 index 00000000..71041ee3 --- /dev/null +++ b/src/jvm/clojure/lang/ArityException.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) Rich Hickey. All rights reserved. + * The use and distribution terms for this software are covered by the + * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) + * which can be found in the file epl-v10.html at the root of this distribution. + * By using this software in any fashion, you are agreeing to be bound by + * the terms of this license. + * You must not remove this notice, or any other, from this software. + **/ + +package clojure.lang; + +/** + * @since 1.3 + */ +public class ArityException extends IllegalArgumentException { + + final public int actual; + + final public String name; + + public ArityException(int actual, String name) { + this(actual, name, null); + } + + public ArityException(int actual, String name, Throwable cause) { + super("Wrong number of args (" + actual + ") passed to: " + name, cause); + this.actual = actual; + this.name = name; + } + +} diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/Compiler.java index d38d25e8..34d46783 100644 --- a/src/jvm/clojure/lang/Compiler.java +++ b/src/jvm/clojure/lang/Compiler.java @@ -6027,7 +6027,15 @@ public static Object macroexpand1(Object x) throws Exception{ Var v = isMacro(op); if(v != null) { - return v.applyTo(RT.cons(form,RT.cons(LOCAL_ENV.get(),form.next()))); + try + { + return v.applyTo(RT.cons(form,RT.cons(LOCAL_ENV.get(),form.next()))); + } + catch(ArityException e) + { + // hide the 2 extra params for a macro + throw new ArityException(e.actual - 2, e.name, e); + } } else { |