Skip to content

Commit 267893a

Browse files
author
dnolen
committed
CLJS-2940: Can't define nilable spec on undefined pred
need to delay calls to the spec same as Clojure
1 parent 6353a9b commit 267893a

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/main/cljs/cljs/spec/alpha.cljs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,37 +1368,37 @@
13681368
"takes a spec and returns a spec that has the same properties except
13691369
'conform' returns the original (not the conformed) value. Note, will specize regex ops."
13701370
[spec]
1371-
(let [spec (specize spec)]
1371+
(let [spec (delay (specize spec))]
13721372
(reify
13731373
Specize
13741374
(specize* [s] s)
13751375
(specize* [s _] s)
13761376

13771377
Spec
1378-
(conform* [_ x] (let [ret (conform* spec x)]
1378+
(conform* [_ x] (let [ret (conform* @spec x)]
13791379
(if (invalid? ret)
13801380
::invalid
13811381
x)))
1382-
(unform* [_ x] (unform* spec x))
1383-
(explain* [_ path via in x] (explain* spec path via in x))
1384-
(gen* [_ overrides path rmap] (gen* spec overrides path rmap))
1385-
(with-gen* [_ gfn] (nonconforming (with-gen* spec gfn)))
1386-
(describe* [_] `(nonconforming ~(describe* spec))))))
1382+
(unform* [_ x] (unform* @spec x))
1383+
(explain* [_ path via in x] (explain* @spec path via in x))
1384+
(gen* [_ overrides path rmap] (gen* @spec overrides path rmap))
1385+
(with-gen* [_ gfn] (nonconforming (with-gen* @spec gfn)))
1386+
(describe* [_] `(nonconforming ~(describe* @spec))))))
13871387

13881388
(defn ^:skip-wiki nilable-impl
13891389
"Do not call this directly, use 'nilable'"
13901390
[form pred gfn]
1391-
(let [spec (specize pred form)]
1391+
(let [spec (delay (specize pred form))]
13921392
(reify
13931393
Specize
13941394
(specize* [s] s)
13951395
(specize* [s _] s)
13961396

13971397
Spec
1398-
(conform* [_ x] (if (nil? x) nil (conform* spec x)))
1399-
(unform* [_ x] (if (nil? x) nil (unform* spec x)))
1398+
(conform* [_ x] (if (nil? x) nil (conform* @spec x)))
1399+
(unform* [_ x] (if (nil? x) nil (unform* @spec x)))
14001400
(explain* [_ path via in x]
1401-
(when-not (c/or (pvalid? spec x) (nil? x))
1401+
(when-not (c/or (pvalid? @spec x) (nil? x))
14021402
(conj
14031403
(explain-1 form pred (conj path ::pred) via in x)
14041404
{:path (conj path ::nil) :pred 'nil? :val x :via via :in in})))

src/test/cljs/cljs/spec_test.cljs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@
415415
(is (nil? (baz-2793 1)))
416416
(is (nil? (quux-2793))))
417417

418+
(s/def ::cljs-2940-foo (s/cat :bar (s/nilable ::cljs-2940-foo)))
419+
418420
(comment
419421

420422
(run-tests)

0 commit comments

Comments
 (0)