Skip to content

Commit

Permalink
CLJS-2139: Undeclared var regression in fn bodies
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mfikes authored and swannodette committed Jun 30, 2017
1 parent b1b09bb commit 3fa4283
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/clojure/cljs/analyzer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,7 @@
(doall (map #(analyze-fn-method menv locals % type true) meths)))

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

(defmethod parse 'fn*
[op env [_ & args :as form] name _]
Expand Down
9 changes: 9 additions & 0 deletions src/test/clojure/cljs/analyzer_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,15 @@
;; The previous def must be analyzed for subsequent var special to succeed
(def ~'x33 (var ~'x32)))]))))

(deftest test-cljs-2139
(let [ws (atom [])]
(try
(a/with-warning-handlers [(collecting-warning-handler ws)]
(a/analyze (a/empty-env)
'(defn foo [] x)))
(catch Exception _))
(is (= ["Use of undeclared Var cljs.user/x"] @ws))))

(comment
(binding [a/*cljs-ns* a/*cljs-ns*]
(a/no-warn
Expand Down

0 comments on commit 3fa4283

Please sign in to comment.