Clojure

Map-destructuring :or fumble needs compiler warning

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: Release 1.5, Release 1.8
  • Fix Version/s: None
  • Component/s: None
  • Patch:
    Code and Test

Description

Here is a map-destructuring blunder that I wish the compiler warned about:

(defn server
  [{servlet ::servlet type ::type :or {::type :jetty} :as service-map}])

It would be splendid to get a warning that :or keys that are not symbols being bound have no effect.

The incomplete code snippet above comes from Pedestal.service 0.1.0.

Here is a complete one-line example with the coding error:

user> (defn picnic [{botulism :botulism :or {:botulism 6}}] botulism) 
#'user/picnic 
user> (picnic {}) 
nil 
user> ;; I intended 6.

Activity

Gary Fredericks made changes -
Field Original Value New Value
Attachment CLJ-1189-p1.patch [ 12014 ]
Andy Fingerhut made changes -
Patch Code and Test [ 10002 ]
Alex Miller made changes -
Labels errormsgs
Alex Miller made changes -
Issue Type Defect [ 1 ] Enhancement [ 4 ]
Alex Miller made changes -
Labels errormsgs destructuring errormsgs
Alex Miller made changes -
Description Here is a map-destructuring blunder that I wish the compiler warned about:

(defn server
  [{servlet ::servlet
    type ::type
    :or {::type :jetty}
    :as service-map}]

It would be splendid to get a warning that :or keys that are not symbols being bound have no effect.

The incomplete code snippet above comes from Pedestal.service 0.1.0.

Here is a complete one-line example with the coding error:

user> (defn picnic [{botulism :botulism :or {:botulism 6}}] botulism)
#'user/picnic
user> (picnic {})
nil
user> ;; I intended 6.
Here is a map-destructuring blunder that I wish the compiler warned about:

{code}
(defn server
  [{servlet ::servlet type ::type :or {::type :jetty} :as service-map}])
{code}

It would be splendid to get a warning that :or keys that are not symbols being bound have no effect.

The incomplete code snippet above comes from Pedestal.service 0.1.0.

Here is a complete one-line example with the coding error:

{code}
user> (defn picnic [{botulism :botulism :or {:botulism 6}}] botulism)
#'user/picnic
user> (picnic {})
nil
user> ;; I intended 6.
{code}

Affects Version/s Release 1.8 [ 10254 ]

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated: