We're updating the issue view to help you get more done. 

Code allowed to re-define referred var

Description

If you refer a var from another namespace, then you can def a new value for that var, and the def will mutate the other namespace, and other things will go wrong as illustrated in the example below.

FWIW, Clojure disallows this, and refuses to allow you to evaluate a def involving a referred var, and emits an error diagnostic like:

1 CompilerException java.lang.IllegalStateException: foo already refers to: #'some.name.space/foo in namespace: user, compiling:(NO_SOURCE_PATH:2:1)

Here is a complete example illustrating the issues:

Given:

1 2 3 4 (ns foo.core) (defn square [x] (* x x))

then do this in a REPL:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 cljs.user=> (require '[foo.core :refer [square]]) nil cljs.user=> (var square) #'foo.core/square cljs.user=> (square 3) 9 cljs.user=> (ns-interns 'cljs.user) {} cljs.user=> (defn square [x] (+ x x)) WARNING: square already refers to: foo.core/square being replaced by: cljs.user/square at line 1 <cljs repl> #'foo.core/square cljs.user=> (square 3) 6 cljs.user=> (var square) #'foo.core/square cljs.user=> (in-ns 'foo.core) nil foo.core=> (square 3) 6 foo.core=> (in-ns 'cljs.user) nil cljs.user=> (ns-interns 'cljs.user) {square #'cljs.user/square} cljs.user=> (cljs.user/square 3) TypeError: Cannot read property 'call' of undefined at repl:1:105 at repl:9:3 at repl:14:4 at Object.exports.runInThisContext (vm.js:54:17) at Domain.<anonymous> ([stdin]:41:34) at Domain.run (domain.js:221:14) at Socket.<anonymous> ([stdin]:40:25) at emitOne (events.js:77:13) at Socket.emit (events.js:169:7) at readableAddChunk (_stream_readable.js:146:16) cljs.user=> #'cljs.user/square #'cljs.user/square cljs.user=> @#'cljs.user/square nil

Environment

None

Status

Assignee

David Nolen

Reporter

Mike Fikes

Labels

None

Approval

None

Patch

Code and Test

Affects versions

1.7.228

Priority

Major