Closed ikappaki closed 4 days ago
Thanks for filing and for providing the examples above. I'm working on a PR to fix this.
I did notice something interesting from your examples:
(let [{:keys [a]} 5]
a)
;; => Syntax error (UnsupportedOperationException) compiling at (src\destr.clj:20:1).
;; Can't type hint a primitive local with a different type
(let [{:keys [a]} 5.3]
a)
;; => Syntax error (UnsupportedOperationException) compiling at (src\destr.clj:25:1).
;; Can't type hint a primitive local with a different type
(let [{:keys [a]} (Integer. 5)]
a)
;; => nil
(let [{:keys [a]} 5N]
a)
;; => nil
Notice how when we coerce the value to boxed and/or non-primitive values in the last examples Clojure returns nil
rather than throwing the syntax exception. Those exceptions you showed may just be a peculiarity of the JVM and primitive types.
Notice how when we coerce the value to boxed and/or non-primitive values in the last examples Clojure returns
nil
rather than throwing the syntax exception. Those exceptions you showed may just be a peculiarity of the JVM and primitive types.
Thanks for looking into it. Good catch regarding primitive types. I couldn’t find a pattern, so I assumed the it was undefined behavior.
Hi,
attempting to desctructure a vector to map keys produces an error message/stack trace that does not reflect the cause of the error
To reproduce, Open up the REPL and try to destructure a vector to map keys. A stacktrace/error message is produced "pvector indices must be integers" that is hard to link to the actual cause
Although this is a simple example, the error message does not directly reflect the root cause which might take some time for a user to decipher. Even more, the error is reported at "line 2," where the variable a is referenced, rather than at "line 1," where the destructuring actually happens
In a large program where the destructuring happens over a variable that we can't really tell what its value is by just looking at it, the cause of the error is hard to trace.
I expect that, from a user's experience point of view, either a better error message should be thrown indicating that the destructuring is the issue, or
nil
should be used for the destructured key bindings.I couldn't find something in Clojure documentation to indicate what the correct behavior should be for trying to destructuring non-map values. I believe is undefined behavior. However I did a survey of
what Clojure does
and what
Basilisp
currently doesNotice in the above how collection are gracefully handled in Clojure, even though it throws an example on numerical values.
Thanks