Invalid defrecord results in exception attributed to namespace that imports namespace with defrecord

Description

I was introducing a namespace that included a defrecord.

My defrecord was wrong; it used a keyword to define a field, not a symbol. Minimal test case:

However, the exception was perplexing:

The error was attributed to app.clj (useclj16.app), a namespace which requires useclj16.init, the namespace containing the defrecord.

No indication that this concerned a defrecord, or even what namespace contained the error, was present in the exception.

Patch: clj-1261-5.diff

Approach: Check explicitly that the fields are all symbols, for both defrecord and deftype, and throw a CompilerException with file, line, and column number if not. Example of exception after patch is applied, in the case give above:

Screened by: Alex Miller

Environment

None

Attachments

4

Activity

Alex Miller 
May 14, 2014 at 5:54 AM

seemed pretty clear

Andy Fingerhut 
May 14, 2014 at 5:40 AM

Thanks for the catch on that typo in the tests. You changed it to what I had intended.

Alex Miller 
May 14, 2014 at 4:41 AM

same as -4 but changed final defrecord to deftype in test (seemed like a typo)

Andy Fingerhut 
May 11, 2014 at 12:43 AM

Patch clj-1261-4.diff is identical to clj-1261-3.diff except that it adds a couple of unit tests verifying that an exception of the desired type and with an appropriate message is thrown when keywords are used as defrecord or deftype fields.

Alex Miller 
May 5, 2014 at 9:56 PM

I think you should be able to test the right error message here by just invoking the defrecord form.

Otherwise, maybe https://github.com/clojure/clojure/blob/master/test/clojure/test_clojure/ns_libs.clj#L87 ?

Completed

Details

Assignee

Reporter

Approval

Patch

Priority

Affects versions

Fix versions

Created September 12, 2013 at 9:42 PM
Updated August 29, 2014 at 3:24 PM
Resolved August 29, 2014 at 3:24 PM