Skip to content

Commit 3fa4283

Browse files
mfikesswannodette
authored andcommitted
CLJS-2139: Undeclared var regression in fn bodies
With CLJS-2066, a change was made to skip analyzing named fn method bodies on the first analysis pass, deferring this analyis to the second, richer pass dedicated to optmizing self calls. Since the second pass has all warnings suppressed, this introduces a subtle regression in that no warnings would be emitted for issues found in named function bodies. This fixes the issue by turning off the blanket no-warn for the second pass. Since warnings can only be emitted when analyzing method bodies (the analysis of parameters doesn't lead to warnings), this is sufficient to solve the problem.
1 parent b1b09bb commit 3fa4283

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/main/clojure/cljs/analyzer.cljc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@
15701570
(doall (map #(analyze-fn-method menv locals % type true) meths)))
15711571

15721572
(defn analyze-fn-methods-pass2 [menv locals type meths]
1573-
(no-warn (analyze-fn-methods-pass2* menv locals type meths)))
1573+
(analyze-fn-methods-pass2* menv locals type meths))
15741574

15751575
(defmethod parse 'fn*
15761576
[op env [_ & args :as form] name _]

src/test/clojure/cljs/analyzer_tests.clj

+9
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,15 @@
733733
;; The previous def must be analyzed for subsequent var special to succeed
734734
(def ~'x33 (var ~'x32)))]))))
735735

736+
(deftest test-cljs-2139
737+
(let [ws (atom [])]
738+
(try
739+
(a/with-warning-handlers [(collecting-warning-handler ws)]
740+
(a/analyze (a/empty-env)
741+
'(defn foo [] x)))
742+
(catch Exception _))
743+
(is (= ["Use of undeclared Var cljs.user/x"] @ws))))
744+
736745
(comment
737746
(binding [a/*cljs-ns* a/*cljs-ns*]
738747
(a/no-warn

0 commit comments

Comments
 (0)