Skip to content

Commit 83a1da8

Browse files
committed
CLJS-3134: Thread predicate-induced inference through and
1 parent 76be2c0 commit 83a1da8

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3483,13 +3483,23 @@
34833483
(contains? t 'js)
34843484
(some array-types t))))))
34853485

3486+
(defn- analyze-js-star-args [js-op env args]
3487+
(first (reduce
3488+
(fn [[argexprs env] arg]
3489+
[(conj argexprs (analyze env arg))
3490+
(if (= js-op 'cljs.core/and)
3491+
(set-test-induced-tags env arg)
3492+
env)])
3493+
[[] env]
3494+
args)))
3495+
34863496
(defn analyze-js-star* [env jsform args form]
34873497
(let [enve (assoc env :context :expr)
3488-
argexprs (vec (map #(analyze enve %) args))
34893498
form-meta (meta form)
34903499
segs (js-star-seg jsform)
34913500
tag (get-js-tag form)
34923501
js-op (:js-op form-meta)
3502+
argexprs (analyze-js-star-args js-op enve args)
34933503
numeric (:numeric form-meta)
34943504
validate (fn [warning-type valid-types?]
34953505
(let [types (map #(infer-tag env %) argexprs)]

src/main/clojure/cljs/core.cljc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,13 +874,19 @@
874874
([x] x)
875875
([x & next]
876876
(core/let [forms (concat [x] next)]
877-
(if (every? #(simple-test-expr? &env %)
878-
(map #(cljs.analyzer/no-warn (cljs.analyzer/analyze &env %)) forms))
877+
(core/cond
878+
(every? #(simple-test-expr? &env %)
879+
(map #(cljs.analyzer/no-warn (cljs.analyzer/analyze &env %)) forms))
879880
(core/let [and-str (core/->> (repeat (count forms) "(~{})")
880881
(interpose " && ")
881882
(#(concat ["("] % [")"]))
882883
(apply core/str))]
883884
(bool-expr `(~'js* ~and-str ~@forms)))
885+
886+
(typed-expr? &env x '#{boolean})
887+
`(if ~x (and ~@next) false)
888+
889+
:else
884890
`(let [and# ~x]
885891
(if and# (and ~@next) and#))))))
886892

0 commit comments

Comments
 (0)