Welcome! Please see the About page for a little more info on how this works.

0 votes
in Spec by

I am trying to learn spec, and have come across the following behaviour.

My code:

(s/def ::foo (s/cat :first symbol?
                :rest (s/alt :simple vector?
                             :multi (s/cat :parts (s/* symbol?) :final vector?))))
(s/explain ::foo '(foo [blah] x))
(s/conform ::foo '(foo [blah] x))

What I find is that s/explain prints "Success!" while s/conform returns :s/invalid.
Have I stumbled on a bug, or have I not understood the functions?
Or is my spec invalid in the first place?
(I am using Clojure 1.11.1 & spec 0.3.218)

by
I have also found some cases like this:
```
(def test-data (rest '(defn l81!E!_P4.*333?1-_5j ([[:as !t!qI!B4.E4] & Np] nil) :kCMH6DT9E :!PM!:p "@o5Pb.y")))
=> #'cursive.extensions.specs/test-data
(s/conform :clojure.core.specs.alpha/defn-args test-data)
=> :clojure.spec.alpha/invalid
(s/explain-str :clojure.core.specs.alpha/defn-args test-data)
=> "Success!\n"
```
I'm inclined to think that conform is wrong here, since the data looks valid for defn to me.

Some more short cases that look valid:
```
(defn f+55_Uu+*5RmN.7.5J1 ([VWa.7Y4] :N0) :+_z7+:*)

(defn Y {} ([]) ([& []] _kP_2_A-*du1 "FI5") nil)

(defn I+ {} ([& [:as .]] :y:w?_ n :+:T*7*r-w2 nil " */") "" nil)
```

1 Answer

0 votes
by

Spec seems valid and I think I would expect this to be invalid - do you agree?

Definitely any time you have a case that disagrees in conform and explain is suspect and possibly a bug.

...