[CLJ-1189] Map-destructuring :or fumble needs compiler warning Created: 31/Mar/13  Updated: 10/Jan/18  Resolved: 10/Jan/18

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: Release 1.5, Release 1.8
Fix Version/s: None

Type: Enhancement Priority: Minor
Reporter: Phill Wolf Assignee: Unassigned
Resolution: Completed Votes: 1
Labels: destructuring, errormsgs

Attachments: Text File CLJ-1189-p1.patch    
Patch: Code and Test


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> ;; I intended 6.

Comment by Gary Fredericks [ 26/May/13 8:25 AM ]

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.

Comment by Gary Fredericks [ 26/May/13 9:54 AM ]

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

Comment by Phill Wolf [ 16/Jul/17 8:51 AM ]

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?

Comment by Alex Miller [ 16/Jul/17 3:54 PM ]

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

Comment by Andy Fingerhut [ 10/Jan/18 8:12 PM ]

Perhaps this ticket can be closed as resolved now that Clojure 1.9.0 is released, and catches these errors?

Generated at Tue Mar 26 15:43:07 CDT 2019 using JIRA 4.4#649-r158309.