Uploaded image for project: 'ClojureScript'
  1. CLJS-3029

Fail fast for s/with-gen on undefined spec

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects versions: None
    • Fix versions: None
    • Labels:

      Description

      Observe what happens in Clojure if you attempt to use s/with-gen on an undefined spec:

      Clojure 1.10.0
      user=> (require '[clojure.spec.alpha :as s])
      nil
      user=> (s/def ::foo (s/with-gen ::bar #(s/gen #{:a})))
      Syntax error (IllegalArgumentException) compiling at (REPL:1:14).
      No implementation of method: :specize* of protocol: #'clojure.spec.alpha/Specize found for class: nil
      

      In ClojureScript, on the other hand, things don't fail fast, and when they fail later the error can be somewhat cryptic to developers:

      $ clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.439"}}}' -m cljs.main
      ClojureScript 1.10.439
      cljs.user=> (require '[clojure.spec.alpha :as s])
      nil
      cljs.user=> (s/def ::foo (s/with-gen ::bar #(s/gen #{:a})))
      :cljs.user/foo
      cljs.user=> (s/valid? ::foo 10)
      TypeError: null is not an object (evaluating 'self__.pred.call')
      	 cljs$spec$alpha$Spec$conform_STAR_$arity$2 (cljs/spec/alpha.cljs:526:35)
      	 cljs.spec.alpha/conform* (cljs/spec/alpha.cljs:40:14)
      	 cljs$core$IFn$_invoke$arity$2 (cljs/spec/alpha.cljs:375:22)
      	 cljs$spec$alpha$valid_QMARK_ (cljs/spec/alpha.cljs:371:1)
      cljs.user=>
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              mfikes Mike Fikes
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: