Clojurians
#cljs-dev
<
2018-11-16
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

slipset10:11:11

I would imagine that’s working as intended or somehting

slipset10:11:31

There might just be some trickery with clojure.core being aliased to cljs.core

slipset10:11:51

or some macro trickery involving + which sometimes is a macro in Clojurescript.

borkdude10:11:18

there never was an fdef to instrument, so unstrument should always return empty

borkdude10:11:49

is there a macro fdef for + in cljs? hmm, that could explain it

mhuebert15:11:35

I think I’ve found a bug with instrumenting args, at least on my machine

(defn defx [key & [doc]])

(s/fdef defx
        :args (s/cat :key keyword?
                     :doc (s/? string?)))

(st/instrument)

(defx :a "")
;; => not thrown - expected

(defx 1)
; => throws - expected

(defx 1 1)
;; => not thrown - bug

(defx 1 1 1 1)
;; => not thrown - bug

(defx :a "" 1)
;; => not thrown - bug

mhuebert15:11:22

it seems to validate the length of the sequence in some cases but not the members

alexmiller15:11:39

that spec is wrong btw

alexmiller15:11:59

or your def is wrong, hard to tell

alexmiller15:11:36

well, I guess maybe it’s not wrong, just hard to tell what you’re expecting

alexmiller15:11:21

but there is a known issue with conformed values of trailing optional elements and you may be running into that

borkdude15:11:51

I’ve tried something like: (s/fdef defx :args (s/cat :key keyword? :opts (s/spec (s/? string?)))), that works.

borkdude15:11:56

btw, (defx 1 1 1 1) does throw on clj with the old spec. I’ll try on cljs next

alexmiller15:11:28

you don’t need the s/spec - & is automatically creating a sequence and there is no nested collection here

alexmiller15:11:05

it’s weird in that the def allows N args but the spec constrains to 1 or 2

mhuebert15:11:38

The spec I intend is that it should accept 1 optional string arg

alexmiller15:11:10

I can see that the problem reporting is failing though which I think is the bug I mentioned above

mhuebert15:11:11

I did call instrument, and calling with 1 Arg throws

borkdude15:11:28

what version of cljs are you on?

mhuebert15:11:35

It was throwing in my clj repl as expected

mhuebert15:11:40

Latest cljs

mhuebert15:11:00

Earlier versions have a different bug with varargs which was recently patched

mhuebert15:11:12

Ach I've got to run, be back in an hour or so

borkdude15:11:29

can you make a repro? this repro does work:

$ clj -Srepro -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.439"} org.clojure/test.check {:mvn/version "RELEASE"}}}' -m cljs.main -re node -r

ClojureScript 1.10.439
cljs.user=> (require '[clojure.spec.test.alpha :as stest])
nil
cljs.user=> (require '[clojure.spec.alpha :as s])
nil
(s/fdef defx
       #_=>         :args (s/cat :key keyword?
       #_=>                      :doc (s/? string?)))
cljs.user/defx
cljs.user=> (defn defx [key & [doc]])
#'cljs.user/defx
cljs.user=>  (stest/instrument)
[cljs.user/defx]
cljs.user=>  (defx 1 1 1 1)
Error: Call to #'cljs.user/defx did not conform to spec.

borkdude15:11:01

(btw Alex, making repros like this is fantastic with tools.deps)

mhuebert16:11:19

ok, am working on a repro

mhuebert16:11:26

might be something with my test.check version

mhuebert16:11:39

Can repro - the issue occurs when :static-fns compiler option is true

mhuebert17:11:28

well. I haven’t been able to repro with the cljs.main repl

mhuebert17:11:41

but in my build I can toggle the behaviour by toggling :static-fns

mhuebert17:11:14

still trying to figure out if i am passing the options correctly to clj

mhuebert17:11:38

ok, got it. start repl with :static-fns true:

clj -Srepro -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.439"} org.clojure/test.check {:mvn/version "RELEASE"}}}' -m cljs.main -co '{:static-fns true}' -re node -r 
then run:
(require '[clojure.spec.alpha :as s])
   (require '[clojure.spec.test.alpha :as st])
   
   (defn defk [key & [doc]]
     key)

   (s/fdef defk
           :args (s/cat :key keyword?
                        :doc (s/? string?)))

   (st/instrument)

   (defk 1 1)

mhuebert17:11:10

the last line should throw, but doesn’t with :static-fns enabled

borkdude17:11:45

what happens if you make defk a multi-arity function? just curious

mhuebert17:11:23

i wouldn’t be surprised if it works, the other bug linked above only affected varargs. but let me check

mhuebert17:11:57

yeah, it works as expected with a multi-arity function

borkdude17:11:50

at this point I’d say JIRA, but maybe @mfikes or @dnolen has something sensible to say

mhuebert17:11:17

i’ve added a comment to the related issue

mhuebert17:11:33

though I apparently do not know how to get jira to format code :man-shrugging::skin-tone-2:

mfikes17:11:06

This unfortunately appears to also be a regression relative to 1.10.339

borkdude17:11:55

@mhuebert replace backquotes by {{ ... }} and triple-backquotes by {code} ... {code}