(apologies for the resend; this didn't reach the web interface the first
time around)

When I have a function whose arguments I have spec'ed with an fdef, and
that function is used in the construction of a lazy seq, it's easy to
stumble into situations where the arguments are not actually checked even
when the function is instrumented.

Here's a contrived example: (using [org.clojure/clojure "1.9.0-RC1"]
[org.clojure/spec.alpha "0.1.143"])

    (require '[clojure.spec.alpha :as s])
    (require '[clojure.spec.test.alpha :as st])

    (s/fdef add1 :args (s/cat :x int?))
    (defn add1 [x]
      (+ x 1))

    (st/instrument [`add1])
    (add1 1) ;; => 2
    (add1 "1") ;; => spec error for args to add1


    (s/fdef print-coll-with-banner
            :args (s/cat :banner string?
                         :xs (s/coll-of any?)))

    (defn print-coll-with-banner [banner c]
      (println banner)
      (println c))


    (print-coll-with-banner "hello adding world" (map add1 [1 2 3]))
    ;; => prints some stuff

    (print-coll-with-banner "hello adding world" (map add1 [1 2 "3"]))
    ;; => spec error for args to add1

    (st/instrument [`print-coll-with-banner])
    (print-coll-with-banner "hello adding world" (map add1 [1 2 "3"]))
    ;; => ClassCastException inside of add1

This appears to be happening because the lazy sequence is actually realized
*by* spec when instrumentation is on, but at that point checking is
actually disabled with the st/with-instrument-disabled macro.

A few questions:

* Is this the intended behavior?
* The code in question has been there as far back as I can trace it in git.
What is this check trying to guard against?
* Does the fact that I got into this situation indicate that I'm doing
something wrong? (The above code is clearly contrived, but I did run into
this in a real program)

- Russell

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to