Skip to content

Commit 58cd6be

Browse files
mfikesdnolen
authored andcommitted
CLJS-620: Warnings are generated when using a macro in argument position
If the analyzer is about to emit a "use of undeclared Var" warning, first check to see if there is a macro present with the same name, and, in that case, change the emitted diagnostic to instead display a "can't take value of macro" warning.
1 parent db695a9 commit 58cd6be

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@
220220

221221
(defmethod error-message :undeclared-var
222222
[warning-type info]
223-
(str "Use of undeclared Var " (:prefix info) "/" (:suffix info)))
223+
(str (if (:macro-present? info)
224+
"Can't take value of macro "
225+
"Use of undeclared Var ")
226+
(:prefix info) "/" (:suffix info)))
224227

225228
(defmethod error-message :undeclared-ns
226229
[warning-type {:keys [ns-sym js-provide] :as info}]
@@ -599,9 +602,14 @@
599602
[env prefix suffix]
600603
(contains? implicit-nses prefix))
601604

605+
(declare get-expander)
606+
602607
(defn confirm-var-exist-warning [env prefix suffix]
603608
(fn [env prefix suffix]
604-
(warning :undeclared-var env {:prefix prefix :suffix suffix})))
609+
(warning :undeclared-var env
610+
{:prefix prefix
611+
:suffix suffix
612+
:macro-present? (not (nil? (get-expander (symbol (str prefix) (str suffix)) env)))})))
605613

606614
(defn loaded-js-ns?
607615
"Check if a JavaScript namespace has been loaded. JavaScript vars are
@@ -663,8 +671,6 @@
663671
#?(:clj (nil? (util/ns->source ns-sym))))
664672
(warning :undeclared-ns env {:ns-sym ns-sym})))
665673

666-
(declare get-expander)
667-
668674
(defn core-name?
669675
"Is sym visible from core in the current compilation namespace?"
670676
#?(:cljs {:tag boolean})

0 commit comments

Comments
 (0)