Fork me on GitHub
#clojure-spec
<
2020-04-27
>
arnaud_bos02:04:10

There's an example in spec-alpha2's wiki to illustrate select from a literal schema with unqualified keys:

(gen/sample (s/gen (s/select {:a int? :b keyword?} [:a])) 5)
;;=> ({:b :C, :a -1}
;;    {:b :f_/s!, :a -1}
;;    {:b :J8.M+/+88, :a -1}
;;    {:a -2}
;;    {:b :IEcw.l?/X, :a -1})
But at the REPL this is what I get:
(gen/sample (s/gen (s/select {:a int? :b keyword?} [:a])) 5)
Error printing return value (ExceptionInfo) at clojure.test.check.generators/fn (generators.cljc:435).
Couldn't satisfy such-that predicate after 100 tries.
I'm on 8498f9cb352135579b6d3a0a5d15c40e5c2647ce , which seems to be the latest commit on master. Sorry if it's already been reported before. I don't really know where to look for stuff like this.

Alex Miller (Clojure team)02:04:53

yeah, there's a bug in this area

👌 4
dspiteself14:04:16

I am sure you have already seen this, but unqualified keys are not being looked at for closed specs in spec-alpha2

8498f9cb352135579b6d3a0a5d15c40e5c2647ce
(s/register
  :blah/name2
  (s/resolve-spec 'clojure.core/string?))
(s/register
  :blah/Object2
  (s/resolve-spec
    `(s/schema {:name :blah/name2})))
(s/explain :blah/Object2 {:name "hi"} )
;-> Success!
(s/explain :blah/Object2 {:name "hi"} {:closed #{:blah/Object2}})
;-> {:name "hi"} - failed: (subset? (set (keys %)) #{}) spec: :blah/Object2
https://github.com/clojure/spec-alpha2/blob/master/src/main/clojure/clojure/alpha/spec/impl.clj#L452

dspiteself14:04:16

Creating Specs Programmatically is so pleasant. I have really been enjoying spec-alpha2.

Alex Miller (Clojure team)14:04:48

I'm sure there are any number of bugs in the newer stuff right now, it's not done

dspiteself14:04:37

yep I was just checking if it would be valuable to report it. Thanks for the awesome work.