Skip to content

Commit 3ac37d5

Browse files
committed
CLJS-2491: Inference warnings are not reported
Fix a mistake from last year - we cannot blindly rebind *cljs-warning* at a lower level than analyze-file. Add test case for `set! *warn-on-infer*` idiom
1 parent 1e06283 commit 3ac37d5

2 files changed

Lines changed: 8 additions & 13 deletions

File tree

src/main/clojure/cljs/analyzer.cljc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3595,11 +3595,6 @@
35953595
ast (analyze-form env form name opts)]
35963596
(reduce (fn [ast pass] (pass env ast opts)) ast passes)))
35973597

3598-
(defn- warnings-for [form]
3599-
(if (analyzed? form)
3600-
(zipmap (keys *cljs-warnings*) (repeat false))
3601-
*cljs-warnings*))
3602-
36033598
(defn analyze
36043599
"Given an environment, a map containing {:locals (mapping of names to bindings), :context
36053600
(one of :statement, :expr, :return), :ns (a symbol naming the
@@ -3615,9 +3610,10 @@
36153610
([env form name opts]
36163611
(ensure
36173612
(wrapping-errors env
3618-
(binding [*cljs-warnings* (warnings-for form)
3619-
reader/*alias-map* (or reader/*alias-map* {})]
3620-
(analyze* env form name opts))))))
3613+
(binding [reader/*alias-map* (or reader/*alias-map* {})]
3614+
(if (analyzed? form)
3615+
(no-warn (analyze* env form name opts))
3616+
(analyze* env form name opts)))))))
36213617

36223618
(defn add-consts
36233619
"Given a compiler state and a map from fully qualified symbols to constant

src/test/clojure/cljs/analyzer_tests.clj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -971,8 +971,7 @@
971971
(first @ws)
972972
"Adding extern to Object for property Component"))))
973973

974-
(comment
975-
974+
(deftest test-set-warn-on-infer
976975
(let [ws (atom [])
977976
res (infer-test-helper
978977
{:forms '[(ns warn-on-infer-test.app)
@@ -982,6 +981,6 @@
982981
:externs ["src/test/externs/test.js"]
983982
:warnings ws
984983
:warn false})]
985-
(println (pr-str res) @ws))
986-
987-
)
984+
(is (string/blank? res))
985+
(is (= 1 (count @ws)))
986+
(is (string/starts-with? (first @ws) "Cannot infer target type"))))

0 commit comments

Comments
 (0)