Skip to content

Commit 8e8c776

Browse files
committed
CLJS-3158: Improperly widened cross-param loop/recur inference
1 parent e1857b4 commit 8e8c776

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2404,7 +2404,11 @@
24042404
(reset! (:flag frame) true)
24052405
(swap! (:tags frame) (fn [tags]
24062406
(mapv (fn [tag expr]
2407-
(add-types tag (:tag expr)))
2407+
;; Widen by adding the type of the recur expression, except when recurring with a
2408+
;; loop local: Since its final widened type is unknown, conservatively assume 'any.
2409+
(if (= :loop (:local expr))
2410+
'any
2411+
(add-types tag (:tag expr))))
24082412
tags exprs)))
24092413
(assoc {:env env :op :recur :form form}
24102414
:frame frame

src/test/clojure/cljs/analyzer_tests.clj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,3 +2101,12 @@
21012101
(env/with-compiler-env test-cenv
21022102
(:tag (ana/analyze test-env '(let [x ^any []] (if (implements? ICounted x) x nil))))))
21032103
'#{cljs.core/ICounted clj-nil})))
2104+
2105+
(deftest test-cljs-3158
2106+
(is (= (ana/no-warn
2107+
(env/with-compiler-env test-cenv
2108+
(:tag (analyze test-env '(loop [a "x" b "y"]
2109+
(if (= a 1)
2110+
a
2111+
(recur b 1)))))))
2112+
'any)))

0 commit comments

Comments
 (0)