Fork me on GitHub
#clojure-spec
<
2017-09-04
>
mpenet12:09:32

seems like I hit an interesting bug: direct-linking breaking a multispec : [...] foo is not a fn, expected predicate fn

mpenet12:09:03

still trying to understand the why/how

mpenet12:09:15

:at [clojure.spec.alpha$dt invokeStatic alpha.clj 756]}]

Alex Miller (Clojure team)12:09:22

and you can’t reproduce without direct linking?

mpenet12:09:30

the bug goes away without dl yes

Alex Miller (Clojure team)12:09:56

well would be good to see a jira on that if you can build a reproducible case

mpenet12:09:06

the code is quite involved I ll try to create a minimal repro

Alex Miller (Clojure team)12:09:24

I don’t think multimethod calls are direct linked

Alex Miller (Clojure team)12:09:56

the line you have above is part of regex specs, not multispec

mpenet12:09:32

but it mentions a fn that's used as first arg to a multi-spec

mpenet12:09:07

(it's a multimethod to be more precise)

Alex Miller (Clojure team)12:09:14

sorry, just guessing from too little info

gklijs19:09:50

managed to get spec working on clojurescript also after some searching/trying, but did not find any direct help on the internet. I’n now using a cljc file starting with `(ns m-venue.spec (:require [#?(:clj clojure.spec.alpha :cljs cljs.spec.alpha :default clojure.spec.alpha) :as s]))` and on clojure I only need to source path, for clojurescript i need to put it in the source paths and require it. Now I can use the same spec front and back-end 🙂.

Alex Miller (Clojure team)22:09:52

cljs automatically rewrites the clojure namespace as the cljs one, so you shouldn’t actually need any of this afaik - just require the clojure ns

plins20:09:40

hi everyone, im trying to use :pre and :post to produce a more detailed error in run time

(defn person-name
  [person]
  {:pre  [(if-not (s/valid? ::person person)
            (throw (IllegalArgumentException. (s/explain ::person person)))
            true)]
   :post [(if-not (s/valid? string? %)
            (throw (Exception. (s/valid? string? %)))
            true)]}
  (str (::first-name person) " " (::last-name person)))



(person-name 42)
;;=> CompilerException java.lang.IllegalArgumentException
val: 42 fails spec: :payment-gateway.util/person predicate: map?
:clojure.spec.alpha/spec  :payment-gateway.util/person
:clojure.spec.alpha/value  42

;; works fine, s/explains works properly

(person-name {::first-name "Elon" ::last-name "Musk" ::email ""})
CompilerException java.lang.AssertionError: Assert failed: (if-not (s/valid? string? %) (throw (Exception. (s/valid? string? %))) false), compiling:(/Users/l/payment-gateway/src/payment_gateway/util.clj:31:1) 


no explain data is printed :(

souenzzo02:09:42

missing # ?

plins20:09:25

why this works for :pre but not for :post?

Alex Miller (Clojure team)22:09:23

shouldn’t both of those pre and post be functions? I think they’re both getting evaluated at compilation time, not runtime