<< Back to previous view

[CCONTRACTS-4] provide macro fails for multiple constraints Created: 28/Jan/14  Updated: 28/Jan/14

Status: Open
Project: core.contracts
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: joerupen Assignee: Fogus
Resolution: Unresolved Votes: 0
Labels: None

clojure 1.5
core.contracts 0.5


The following code shows 2 ways for defining a function with constraints.

=> it works as expected using the with-constraints macro
=> it fails on the second contract using the provide macro

(require '[clojure.core.contracts :as ccc])

;; because the provide macro alters the var-root, let's keep two separate identical functions for the test.

(defn qux [x] x)
(defn bar [x] x)

;; define 2 contracts
(def c1 (ccc/contract c1-cx "should be odd"
[(odd? x)]))

(def c2 (ccc/contract c2-cx "should have one digit"
[(= 1 (count (str x)))]))

;; using the provide macro => c1 is asserted, c2 never. When we swap around c2 c1, then c2 is asserted, c1 never
(ccc/provide [qux "qux" c1 c2])

;; on the other hand, using with-constraints works as expected.
(def qux-g
(ccc/with-constraints bar c1 c2))

(qux 2) ;; expected assertion "should be odd"
(qux 3) ;; expected 3
(qux 23) ;; expected assertion "only one digit", but we get 23

(qux-g 2) ;; should be odd
(qux-g 3) ;; OK
(qux-g 23) ;; should be positive

Generated at Tue Mar 28 01:32:28 CDT 2017 using JIRA 4.4#649-r158309.