Browse files

CLJS-544: named fn self reference lexical scope issue

named fns were passing along raw names instead of the name var map
which includes shadowing information. this meant that during
emission the name of the fn would not match the name that would be
emitted inside for self reference.

We now construct the name var map and set the :name field of the
fn AST appropriately.
  • Loading branch information...
1 parent 409d42d commit 9ddf847b44ec82070e91038f4afbd8a2baec94ff @swannodette swannodette committed Jul 19, 2013
Showing with 4 additions and 2 deletions.
  1. +4 −2 src/clj/cljs/analyzer.clj
@@ -383,7 +383,9 @@
;;turn (fn [] ...) into (fn ([]...))
meths (if (vector? (first meths)) (list meths) meths)
locals (:locals env)
- locals (if (and locals name) (assoc locals name {:name name :shadow (locals name)}) locals)
+ name-var (if name
+ {:name name :shadow (locals name)})
+ locals (if (and locals name) (assoc locals name name-var) locals)
type (-> form meta ::type)
fields (-> form meta ::fields)
protocol-impl (-> form meta :protocol-impl)
@@ -421,7 +423,7 @@
(no-warn (doall (map #(analyze-fn-method menv locals % type) meths)))
;;todo - validate unique arities, at most one variadic, variadic takes max required args
- {:env env :op :fn :form form :name name :methods methods :variadic variadic
+ {:env env :op :fn :form form :name name-var :methods methods :variadic variadic
:recur-frames *recur-frames* :loop-lets *loop-lets*
:jsdoc [(when variadic "@param {...*} var_args")]
:max-fixed-arity max-fixed-arity

0 comments on commit 9ddf847

Please sign in to comment.