<< Back to previous view

[CLJS-360] Analyzer incorrectly merges metadata when redefining vars Created: 26/Aug/12  Updated: 27/Jul/13  Resolved: 31/Aug/12

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: patch, patch,

Attachments: Text File redef-meta-2.patch     Text File redef-meta.patch    
Patch: Code

 Description   

I'm experimenting with using the analyzer for some more sophisticated macros, including a CPS transform and control constructs. During interactive development, I discovered that the analyzer is incorrectly merging metadata on vars when redefining them. This patch changes redef's to replace, rather than merge, existing var metadata.

The patch does not include a test, since the tests don't currently muck with the analyzer directly. Here's some code you can play with in your repl:

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

(def env (ana/empty-env))

(defn show-foo [form]
  (ana/analyze env form)
  (-> @ana/namespaces (get 'cljs.user) :defs (get 'x) :foo))

(show-foo '(def ^{:foo 1} x 1))

(show-foo '(def ^{:foo 2} x 1))

(show-foo '(def x 1))  ; before patch, this returns 2. After patch, nil.


 Comments   
Comment by Brandon Bloom [ 26/Aug/12 6:27 PM ]

Also, the patch makes the behavior match JVM Clojure:

user=> (def ^:foo x)
#'user/x
user=> (:foo (meta #'x))
true
user=> (def x)
#'user/x
user=> (:foo (meta #'x))
nil

Comment by David Nolen [ 31/Aug/12 9:29 AM ]

Can we get a patch without whitespace changes? Thanks!

Comment by Brandon Bloom [ 31/Aug/12 11:22 AM ]

Updated patch: no longer changes indent/whitespace and resolves conflict with change that happened to master since original patch.

Comment by David Nolen [ 31/Aug/12 11:29 AM ]

fixed, http://github.com/clojure/clojurescript/commit/8355d1eacff667b77551bb60699d5c85b2f15298

Generated at Tue Sep 02 02:53:01 CDT 2014 using JIRA 4.4#649-r158309.