ClojureScript

Undeclared warning when defining protocols

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

Evaluate the following in a ./script/repl session

(require '[cljs.compiler :as comp])
(require '[cljs.analyzer :as ana])

;; This trickery seems to be the minimum logic to prepare a top level namespace
(def repl-env
  (binding [ana/*cljs-ns* 'cljs.user]
    (-> (ana/empty-env)
        (ana/analyze '(ns some-ns))
        :env
        (assoc :ns (ana/get-namespace ana/*cljs-ns*)))))

(defn analyze [form]
  (binding [ana/*cljs-warn-on-undeclared* true]
    (ana/analyze repl-env form)))

(-> '(defprotocol P
       (f [_ x]))
  analyze
  keys) ; keys is just so the output isn't huge

The first time you evaluate that last form, you get an error like this one:

WARNING: Use of undeclared Var some-ns/f at line 45

You'll get similar errors each time you rename f and re-evaluate the form.

Activity

People

Vote (0)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: