Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed varargs bug identified at http://ianrumford.github.com/blog/201…

…2/11/17/first-take-on-contracts-in-clojure/ but using more robust strategy to preserve callsite semantics.
  • Loading branch information...
commit 2d59ae5a95163ac5c7a0f0477b4c9053306087b5 1 parent 5cec374
@fogus fogus authored
Showing with 25 additions and 10 deletions.
  1. +25 −10 src/main/clojure/clojure/core/contracts/impl/transformers.clj
View
35 src/main/clojure/clojure/core/contracts/impl/transformers.clj
@@ -53,17 +53,32 @@
(defn- build-contract-body
[[args cnstr descr :as V]]
- (unify/subst
- '(?PARMS
- (let [ret ?PRE-CHECK]
- ?POST-CHECK))
+ (let [vargs? #{'&}
+ prep-args (if (some vargs? args)
+ (with-meta
+ (->> args (remove vargs?) vec)
+ {::vargs true})
+ args)
+ callsite (if (::vargs (meta prep-args))
+ (list* `apply '?F prep-args)
+ '(apply ?F ?ARGS))]
+ (unify/subst
+ '(?PARMS
+ (let [ret ?PRE-CHECK]
+ ?POST-CHECK))
- {'?ARGS args
- '?F 'f
- '?PARMS (vec (list* 'f args))
- '?MSG descr
- '?PRE-CHECK (build-condition-body {:pre (:pre cnstr)} '(apply ?F ?ARGS) "Pre-condition failure: ")
- '?POST-CHECK (build-condition-body {:post (:post cnstr)} 'ret "Post-condition failure: ")}))
+ {'?ARGS prep-args
+ '?F 'f
+ '?PARMS (vec (list* 'f args))
+ '?MSG descr
+ '?PRE-CHECK (build-condition-body
+ {:pre (:pre cnstr)}
+ callsite
+ "Pre-condition failure: ")
+ '?POST-CHECK (build-condition-body
+ {:post (:post cnstr)}
+ 'ret
+ "Post-condition failure: ")})))
(defn- build-contract-bodies
[constraint-descriptions]
Please sign in to comment.
Something went wrong with that request. Please try again.