[CLJ-5] Unintuitive error response in clojure 1.0 Created: 17/Jun/09 Updated: 28/Apr/12 |
|
| Status: | Open |
| Project: | Clojure |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | Backlog |
| Type: | Enhancement | Priority: | Minor |
| Reporter: | Assembla Importer | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Attachments: |
|
| Patch: | Code and Test |
| Approval: | Incomplete |
| Description |
|
The following broken code: (let [[x y] {}] x) provides the following stack trace: Exception in thread "main" java.lang.UnsupportedOperationException: nth not supported on this type: PersistentArrayMap (test.clj:0) The message "nth not supported on this type" while correct doesn't make the cause of the error very clear. Better error messages when destructuring would be very helpful. |
| Comments |
| Comment by Assembla Importer [ 24/Aug/10 10:44 AM ] |
|
Converted from http://www.assembla.com/spaces/clojure/tickets/5 |
| Comment by Eugene Koontz [ 11/Nov/11 7:36 PM ] |
|
Please see the attached patch which produces a (hopefully more clear) error message as shown below (given the broken code shown in the original bug report): Clojure 1.4.0-master-SNAPSHOT
user=> (let [x 42 y 43] (+ x y))
85
user=> (let [[x y] {}] x)
UnsupportedOperationException left side of binding must be a symbol (found a PersistentVector instead). clojure.lang.Compiler.checkLet (Compiler.java:6545)
user=>
In addition, this patch checks the argument of (let) as shown below: user=> (let 42) UnsupportedOperationException argument to (let) must be a vector (found a Long instead). clojure.lang.Compiler.checkLet (Compiler.java:6553) |
| Comment by Eugene Koontz [ 11/Nov/11 7:38 PM ] |
|
Patch produced by doing git diff against commit ba930d95fc (master branch). |
| Comment by Eugene Koontz [ 13/Nov/11 11:24 PM ] |
|
Sorry, this patch is wrong: it assumes that the left side of the binding is wrong - the [x y] in : (let [[x y] {}] x)
because [x y] is a vector, when in fact, the left side is fine (per http://clojure.org/special_forms#let : "Clojure supports abstract structural binding, often called destructuring, in let binding lists".) So it's the right side (the {}) that needs to be checked and flagged as erroneous, not the [x y]. |
| Comment by Carin Meier [ 30/Nov/11 12:15 PM ] |
|
Add patch better-error-for-let-vector-map-binding This produces the following: (let [[x y] {}] x)
Exception map binding to vector is not supported
There are other cases that are not handled by this though — like binding vector to a set user=> (let [[x y] #{}] x)
UnsupportedOperationException nth not supported on this type: PersistentHashSet
Wondering if it might be better to try convert the map to a seq to support? Although this might be another issue. Thoughts? |
| Comment by Aaron Bedra [ 30/Nov/11 7:12 PM ] |
|
This seems too specific. Is this issue indicative of a larger problem that should be addressed? Even if this is the only case where bindings produce poor error messages, all the cases described above should be addressed in the patch. |
| Comment by Carin Meier [ 16/Dec/11 7:47 AM ] |
|
Unfortunately, realized that this still does not cover the nested destructuring cases. Coming to the conclusion, that my approach above is not going to work for this. |
| Comment by Carin Meier [ 28/Apr/12 10:46 PM ] |
|
File: clj-5-destructure-error.diff Added support for nested destructuring errors let [[[x1 y1][x2 y2]] [[1 2] {}]]
;=> UnsupportedOperationException let cannot destructure class clojure.lang.PersistentArrayMap.
|