<< Back to previous view

[CLJS-412] Undeclared warning when defining protocols Created: 29/Oct/12  Updated: 19/Nov/13  Resolved: 19/Nov/13

Status: Closed
Project: ClojureScript
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Brandon Bloom Assignee: Unassigned
Resolution: Completed Votes: 0
Labels: None


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))
        (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]))
  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.

Comment by Brandon Bloom [ 29/Oct/12 3:57 PM ]

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"))
Comment by Brandon Bloom [ 29/Oct/12 7:09 PM ]

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.

Comment by David Nolen [ 21/Dec/12 6:02 PM ]

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?

Comment by David Nolen [ 19/Nov/13 9:31 PM ]

As far as I know not relevant any more.

Generated at Tue Jan 23 08:23:19 CST 2018 using JIRA 4.4#649-r158309.