ClojureScript

better error message when calling macros with arity

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: 1.7.145
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Patch:
    Code

Description

This ticket is a copy of CLJ-397 but for ClojureScript.

If you invoke a macro supplying an incorrect number of arguments the arity exception includes the &env and &form special variables in the count (thus making it look like the argument count is 2 greater than that in the code the user wrote).

An example is (while) which indicates

clojure.lang.ExceptionInfo: Wrong number of args (2) passed to: core/while at line 1 <cljs repl> {:file "<cljs repl>", :line 1, :column 1, :tag :cljs/analysis-error}

while the same generates the following in Clojure:

ArityException Wrong number of args (0) passed to: core/while  clojure.lang.Compiler.macroexpand1 (Compiler.java:6636)

A quick experiment shows that it is indeed possible to imitate the solution employed in Clojure (catch the ArityException and re-throw a new one with a decremented argument count). A more generalized approach may be needed to not use Java classes when in bootstrapped.

Activity

Hide
Mike Fikes added a comment -

With CLJS-1516.patch, in regular ClojureScript:

cljs.user=> (if-not true)
clojure.lang.ExceptionInfo: Wrong number of args (1) passed to: core/if-not at line 1 <cljs repl> {:file "<cljs repl>", :line 1, :column 1, :tag :cljs/analysis-error}
	at clojure.core$ex_info.invoke(core.clj:4593)
...

and in bootstrap:

cljs.user=> (if-not true)
Invalid arity: 1 at line 1 
	 cljs$core$ExceptionInfo (cljs/core.cljs:9891:11)
...

whereas without the patch you get a diagnostic indicating an argument count of 3.

Show
Mike Fikes added a comment - With CLJS-1516.patch, in regular ClojureScript:
cljs.user=> (if-not true)
clojure.lang.ExceptionInfo: Wrong number of args (1) passed to: core/if-not at line 1 <cljs repl> {:file "<cljs repl>", :line 1, :column 1, :tag :cljs/analysis-error}
	at clojure.core$ex_info.invoke(core.clj:4593)
...
and in bootstrap:
cljs.user=> (if-not true)
Invalid arity: 1 at line 1 
	 cljs$core$ExceptionInfo (cljs/core.cljs:9891:11)
...
whereas without the patch you get a diagnostic indicating an argument count of 3.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: