ClojureScript

Warning on use of undeclared var when creating recursive definition

Details

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

Description

If you create a definition that recursively refers to itself, a warning is issued. This is simply a warning; the generated code still works. The same code works without such a warning in Clojure.

Here is an example:

(ns foo.bar)

(def fib-seq (lazy-cat [0 1] (map + (rest fib-seq) fib-seq)))

This generates the following warning:

Compiling "js/main.js" from ["src/cljs" "src/clj"]...
WARNING: Use of undeclared Var foo.bar/fib-seq at line 3 src/cljs/foo/bar.cljs
WARNING: Use of undeclared Var foo.bar/fib-seq at line 3 src/cljs/foo/bar.cljs
Successfully compiled "js/main.js" in 5.819 seconds.

Activity

Hide
Mike Fikes added a comment -

Thanks David. Let me know if the patch could use further work. Glad to revise as necessary.

Show
Mike Fikes added a comment - Thanks David. Let me know if the patch could use further work. Glad to revise as necessary.
Hide
David Nolen added a comment -

The patch initially looks OK will give a closer look tomorrow. Thanks!

Show
David Nolen added a comment - The patch initially looks OK will give a closer look tomorrow. Thanks!
Hide
Mike Fikes added a comment -

Patch attached.

Note that I'm a new contributor (I signed the online CLA), but I have no experience with the ClojureScript compiler codebase. In other words, increased review for this patch is appropriate IMHO.

Show
Mike Fikes added a comment - Patch attached. Note that I'm a new contributor (I signed the online CLA), but I have no experience with the ClojureScript compiler codebase. In other words, increased review for this patch is appropriate IMHO.
Hide
David Nolen added a comment -

Would be happy to take a patch that propagates the def'ed var so that the initializer expression has it during analysis.

Show
David Nolen added a comment - Would be happy to take a patch that propagates the def'ed var so that the initializer expression has it during analysis.
Hide
Mike Fikes added a comment -

An easy workaround is to forward declare. For the example given in the description,

(declare fib-seq)

suffices.

Show
Mike Fikes added a comment - An easy workaround is to forward declare. For the example given in the description, (declare fib-seq) suffices.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: