Clojure

defrecord doesn't work with certain field names

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: Release 1.2
  • Component/s: None
  • Labels:
    None
  • Approval:
    Ok

Description

When a field name in a defrecord coincides with an argument name in one of the method implementations, strange things happen:

(defrecord Foo [o])
java.lang.RuntimeException: java.lang.IllegalArgumentException: Unable to resolve classname: Foo
at clojure.lang.Compiler.maybePrimitiveType(Compiler.java:1118)
at clojure.lang.Compiler$MethodExpr.emitTypedArgs(Compiler.java:1142)
...

(defrecord Foo [this that])
(let [a-foo (new Foo :a :b)]
(with-meta a-foo {:foo :bar}))
java.lang.StackOverflowError

The attached patch introduces gensyms for all the critical method argument names, such that clashes are no longer possible.

In Clojure-Dev: http://groups.google.com/group/clojure-dev/browse_thread/thread/9e4c1956d75588b8/8261a8d112f1eadf?lnk=gst&q=defrecord#8261a8d112f1eadf

Activity

Hide
Assembla Importer added a comment -

stu said: This patch seems to work fine, but I have two questions for Rich:

  • Should the outer let gensym a symbol for all the thises, i.e. is there any memory/perf benefit to not generating a different autogensym for every method? Assuming no, but thought I would check.
  • Do I need to go back in git history and compare this to the point where defrecord worked like this originally, if it ever did? If so, can you point me to the commit?
Show
Assembla Importer added a comment - stu said: This patch seems to work fine, but I have two questions for Rich:
  • Should the outer let gensym a symbol for all the thises, i.e. is there any memory/perf benefit to not generating a different autogensym for every method? Assuming no, but thought I would check.
  • Do I need to go back in git history and compare this to the point where defrecord worked like this originally, if it ever did? If so, can you point me to the commit?
Hide
Assembla Importer added a comment -

stu said: Updating tickets (#256, #257, #367, #358)

Show
Assembla Importer added a comment - stu said: Updating tickets (#256, #257, #367, #358)

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: