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

Hide
David Nolen added a comment -

As far as I know not relevant any more.

Show
David Nolen added a comment - As far as I know not relevant any more.
Hide
David Nolen added a comment -

Your first comment isn't valid code so I'm not sure what you mean. When I enter it correctly into the REPL I get no warnings. I also get no warnings when defining at a protocol at the REPL. Do you have a specific minimal CLJS project that exhibits the issue?

Show
David Nolen added a comment - Your first comment isn't valid code so I'm not sure what you mean. When I enter it correctly into the REPL I get no warnings. I also get no warnings when defining at a protocol at the REPL. Do you have a specific minimal CLJS project that exhibits the issue?
Hide
Brandon Bloom added a comment - - edited

The more I study this, the more I'm convinced that cljs-warn-on-undeclared is broken badly. Recursive functions (not using recur) generate this warning. As do certain parameters, locals, or other variable references that are actually defined. The issue seems to stem from a conflation between symbol definition and resolution. resolve-var, resolve-existing-var, and (parse 'def ...) are all tangled in a crazy mutually recursive way. A lot of that stems from a recursive analyze call to yield init-expr and ultimately fn-var? inside of the def parse code.

Show
Brandon Bloom added a comment - - edited The more I study this, the more I'm convinced that cljs-warn-on-undeclared is broken badly. Recursive functions (not using recur) generate this warning. As do certain parameters, locals, or other variable references that are actually defined. The issue seems to stem from a conflation between symbol definition and resolution. resolve-var, resolve-existing-var, and (parse 'def ...) are all tangled in a crazy mutually recursive way. A lot of that stems from a recursive analyze call to yield init-expr and ultimately fn-var? inside of the def parse code.
Hide
Brandon Bloom added a comment -

Seems like the underlying issue is referring to a var while it is being defined. This form exhibits the same issue:

(def f [x] (aget f "prototype"))
Show
Brandon Bloom added a comment - Seems like the underlying issue is referring to a var while it is being defined. This form exhibits the same issue:
(def f [x] (aget f "prototype"))

People

Vote (0)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: