Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalArgumentException: Unable to resolve classname: IPersistentMap #24

Closed
nicksieger opened this issue Jun 16, 2015 · 2 comments
Closed

Comments

@nicksieger
Copy link

Here's a failing testcase for map_test.clj:

(deftest read-direct
  (let [s (ordered-map 1 2, 3 4, 5 6, 1 9, 7 8)
        t #ordered/map ([1 9] [3 4] [5 6] [7 8])]
    (is (= s t))))

This blows up with the error message in the issue title.

If I change code in map.clj to fully-qualify all instances of IPersistentMap, then the error message changes to "java.lang.IllegalArgumentException: No matching field found: backing-map for class flatland.ordered.map.OrderedMap".

My clojure-fu is not skillful enough to unwind your delegating-deftype macro, so I thought I'd ask here and see if you know what's going on.

Thanks!

@amalloy
Copy link
Contributor

amalloy commented Jun 16, 2015

You're not really supposed to use data readers to embed foreign objects in your source code. Most of your test case is just distracting fluff: it's easily reproduced with the simple expression

    #ordered/map ([1 2])

I don't know the details of how the compiler tries to understand map objects embedded in code, which make it come up with this exception, but basically it is just something you're not supposed to do. The tagged syntax is for transporting stuff across the wire, or persisting it to disk. That is,

    (read-string "#ordered/map ([1 2])")

works fine, and that's what the feature is supposed to do. What you're doing is the same as

    (eval (read-string "#ordered/map ([1 2])"))

which fails for a lot of reader-tagged objects. Do you have some compelling reason that you need this to work? I have trouble imagining a way in which the answer could be yes.

@nicksieger
Copy link
Author

I understand now that use of reader-tagged objects in bare code is not something that you want to do typically. I encountered this error in code that embedded an ordered map in metadata while passing through a couple layers of macros. Switching away from an ordered map to a regular map made the issue go away. My best guess after finding out that I could trigger the error with #ordered/map ([1 2]) was that somewhere through the layers of macros the ordered map was being rendered by print-method. I didn't find the exact culprit unfortunately (dense code), so it was still a guess at best.

I was able to fix this issue by fully-qualifying interfaces and protocols in map.clj and changing the backing-map field name to backing_map (to avoid getting munged by the compiler). (Why fully-qualifying was necessary is beyond my comprehension of clojure's evaluator.) If you are interested in those changes I can put up a PR, but at any rate I agree with you that I don't think this is an issue that needs to be solved in your library.

@amalloy amalloy closed this as completed Jul 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants