<< Back to previous view

[CLJ-397] better error message when calling macros with arity Created: 07/Jul/10  Updated: 05/Nov/10  Resolved: 05/Nov/10

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: None
Fix Version/s: Release 1.3

Type: Enhancement Priority: Blocker
Reporter: Assembla Importer Assignee: Rich Hickey
Resolution: Completed Votes: 0
Labels: None

Attachments: Text File 0397-arity-unwrapped.patch    
Patch: Code and Test
Approval: Ok

 Description   

The two magic arguments to macros lead to weird error messages:

(defmacro foo [a b] a)
(foo)
java.lang.IllegalArgumentException: Wrong number of args (2) passed to: user$foo (NO_SOURCE_FILE:)0


 Comments   
Comment by Assembla Importer [ 18/Oct/10 11:07 PM ]

Converted from http://www.assembla.com/spaces/clojure/tickets/397
Attachments:
mh-397-arity.patch - https://www.assembla.com/spaces/clojure/documents/atduak20Cr35rOeJe5cbLA/download/atduak20Cr35rOeJe5cbLA

Comment by Assembla Importer [ 18/Oct/10 11:07 PM ]

stu said: Updating tickets (#427, #426, #421, #420, #397)

Comment by Assembla Importer [ 18/Oct/10 11:07 PM ]

stu said: The choke point here is line 5286 of Compiler.java. At this point, we know we are in macro, but we don't know we if we have an arity problem. When the arity problem is throw, it is a plain old IllegalArgumentException. Some choices:

(1) Hack: parse the exception, pull out the number, subtract 2. Yuck.

(2) Make the exception smarter (subclass the exception as ArityException or some such, catch that here, subtract 2.

(3) Make AFunction smarter, so that it knows if it is a macro or not (also requires change to defmacro). Then throwArity can do the right thing at the point of the problem.

Option #2 feels smaller than #3, but maybe knowing when an AFunction is AMacro will be useful elsewhere.

Comment by Assembla Importer [ 18/Oct/10 11:07 PM ]

richhickey said: #2 please

Comment by Assembla Importer [ 18/Oct/10 11:07 PM ]

fogus said: I agree with #2 also, but in general I think in creating a (reasonable) set of exception subclasses we could start down the path of making error reporting and handling more friendly.

Comment by Assembla Importer [ 18/Oct/10 11:07 PM ]

stu said: Updating tickets (#429, #437, #397, #420)

Comment by Assembla Importer [ 18/Oct/10 11:07 PM ]

mikehinchey said: [file:atduak20Cr35rOeJe5cbLA]: fixes using Stuart's #2 choice

Comment by Stuart Halloway [ 29/Oct/10 10:26 AM ]

Second patch (arity-unwrapped) subsumes first, and does not return a wrapped exception. Wrapped exception would defeat the purpose of the patch, by giving REPL root-cause consumers an incorrect message.

Generated at Mon Dec 22 18:10:20 CST 2014 using JIRA 4.4#649-r158309.