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

0 votes
in Spec by
edited by
clj
Clojure 1.10.1
user=> (defmulti valid? (fn [x] (odd? x)))
#'user/valid?
user=> (defmethod valid? true [x] true)
#object[clojure.lang.MultiFn 0x184545fe "clojure.lang.MultiFn@184545fe"]
user=> (require '[clojure.spec.alpha :as s])
nil
user=> (s/def ::foo (s/and int? valid?))
:user/foo
user=> (s/conform ::foo 5)
5
user=> (s/unform ::foo 5)
Execution error (NullPointerException) at java.util.regex.Matcher/getTextLength (Matcher.java:1770).
null
user=> (pst *e)
NullPointerException
java.util.regex.Matcher.getTextLength (Matcher.java:1770)
java.util.regex.Matcher.reset (Matcher.java:416)
java.util.regex.Matcher.<init> (Matcher.java:253)
java.util.regex.Pattern.matcher (Pattern.java:1134)
clojure.lang.Compiler.demunge (Compiler.java:2936)
clojure.spec.alpha/fn-sym (alpha.clj:128)
clojure.spec.alpha/fn-sym (alpha.clj:124)
clojure.spec.alpha/fn--1809 (alpha.clj:145)
clojure.spec.alpha/fn--1809 (alpha.clj:130)
clojure.spec.alpha/fn--1782/G--1777--1791 (alpha.clj:121)
clojure.spec.alpha/specize (alpha.clj:152)
clojure.spec.alpha/specize (alpha.clj:151)

1 Answer

+1 vote
by
selected by
 
Best answer

Yes, that's definitely a bug in spec with not checking that a function object class name conforms to the expected pattern (all multimethods will just report clojure.lang.MultiFn).

This is fixed in spec 2 (by relying solely on symbolic specs and not trying to interpret function objects like this at all).

...