Clojure

[core.specs] Destructuring spec is overly restrictive in namespaced :keys

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: Release 1.10
  • Fix Version/s: Release 1.11
  • Component/s: None
  • Patch:
    Code
  • Approval:
    Vetted

Description

Namespaced :keys destructuring (see CLJ-1919) supports any kind of ident in a `::foo/keys` or `::foo/syms`, but the core spec says only `simple-symbol?` is allowed.

Example:

user=> (let [{::keys [:foo]} {::foo 1}] foo)
Syntax error macroexpanding clojure.core/let at (REPL:1:1).
...bunch of spec problems

Expected:

user=> (let [{::keys [:foo]} {::foo 1}] foo)
1

Proposed: Widen spec for this case from `simple-symbol?` to `ident?` (which the code supports).
Patch: clj-2473.patch

Activity

Hide
Thomas Heller added a comment -

ident? accepts namespaced keywords (and symbols) which probably should not be allowed given that the current implementation will ignore the namespace and use the namespace used by "keys" instead. To avoid confusion the spec should, in my opinion, be restricted to simple-keyword? or simple-symbol? in the namespaced "keys" case and only accept ident? for non-namespaced :keys.

(let [{:foo/keys [:other/bar]} {}])
(let [{:foo/keys [other/bar]} {}])
Show
Thomas Heller added a comment - ident? accepts namespaced keywords (and symbols) which probably should not be allowed given that the current implementation will ignore the namespace and use the namespace used by "keys" instead. To avoid confusion the spec should, in my opinion, be restricted to simple-keyword? or simple-symbol? in the namespaced "keys" case and only accept ident? for non-namespaced :keys.
(let [{:foo/keys [:other/bar]} {}])
(let [{:foo/keys [other/bar]} {}])
Hide
Alex Miller added a comment -

I considered that and decided to match the code. There is also consistency with :keys.

Show
Alex Miller added a comment - I considered that and decided to match the code. There is also consistency with :keys.

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated: