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

Hide
Gary Fredericks added a comment -

Should this be a warning or an exception? I don't know of any similar example of the compiler giving a warning, so I would expect the latter.

Show
Gary Fredericks added a comment - Should this be a warning or an exception? I don't know of any similar example of the compiler giving a warning, so I would expect the latter.
Hide
Gary Fredericks added a comment -

Added a patch that throws an exception when :or is not a map or its keys are not symbols. Also some tests.

Show
Gary Fredericks added a comment - Added a patch that throws an exception when :or is not a map or its keys are not symbols. Also some tests.
Hide
Phill Wolf added a comment -

Still an issue in 1.8 - which I hope may be addressed in the course of other destructuring enhancements in 1.9. How may I update the "versions" field?

Show
Phill Wolf added a comment - Still an issue in 1.8 - which I hope may be addressed in the course of other destructuring enhancements in 1.9. How may I update the "versions" field?
Hide
Alex Miller added a comment -

These are compile errors in Clojure 1.9 due to the new core specs on defn (and other let destructuring locations).

Show
Alex Miller added a comment - These are compile errors in Clojure 1.9 due to the new core specs on defn (and other let destructuring locations).

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated: