<< Back to previous view

[CLJ-1067] Fix error message inconsistencies in Symbol and Keyword Created: 14/Sep/12  Updated: 01/Mar/13  Resolved: 17/Sep/12

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

Type: Enhancement Priority: Trivial
Reporter: Christoffer Sawicki Assignee: Unassigned
Resolution: Declined Votes: 0
Labels: None

Attachments: Text File Make-Keyword-extend-AFn-just-like-Symbol.patch    

 Description   

1. There are some ugly and unnecessary – but harmless – inconsistencies between Symbol and Keyword:

(.run 'foo);    => ArityException Wrong number of args (0) passed to: Symbol  clojure.lang.AFn.throwArity (AFn.java:437)
(.run :foo);    => UnsupportedOperationException   clojure.lang.Keyword.run (Keyword.java:97)
(.call 'foo);   => ArityException Wrong number of args (0) passed to: Symbol  clojure.lang.AFn.throwArity (AFn.java:437)
(.call :foo);   => IllegalArgumentException Wrong number of args passed to keyword: :foo  clojure.lang.Keyword.throwArity (Keyword.java:88)
(.invoke 'foo); => ArityException Wrong number of args (0) passed to: Symbol  clojure.lang.AFn.throwArity (AFn.java:437)
(.invoke :foo); => IllegalArgumentException Wrong number of args passed to keyword: :foo  clojure.lang.Keyword.throwArity (Keyword.java:88)

2. Keyword.java contains a lot of code that has already been factored out to AFn.java.

I propose that Keyword is modified to extend AFn to resolve the above issues.



 Comments   
Comment by Stuart Halloway [ 17/Sep/12 7:03 AM ]

At first glance, it appears that there could be some code sharing here. But the attached patch changes the semantics of run, which is a non-starter.

Comment by Christoffer Sawicki [ 17/Sep/12 7:19 AM ]

The only thing that changes is the type of thrown exception.

Current call tree:

Keyword.run() -> throw new UnsupportedOperationException()

Call tree with patch applied:

Keyword.run() -> AFn.run() -> AFn.invoke() -> AFn.throwArity(0) -> throw new ArityException(...)

(I.e. Keyword.run() always throws an exception, with and without my patch.)

Generated at Tue Sep 23 13:39:17 CDT 2014 using JIRA 4.4#649-r158309.