Search code examples
clojurescriptread-eval-print-loopfigwheel

Recompiling functions in Clojure Repl cause compiler warning


I seem to not know some important aspects of REPLs, using figwheel or lein-autoreload.

If I start a REPL using one of the mentioned plugins and do changes on one of the project files, I usually get compiler warnings. Often, this means I have to restart the REPL, which defeats the whole purpose of those plugins.

Let me give you an example. I have three files: core.cljs, demoscene.cljs and objects.cljs. They reference each other in the order I mentioned them using e.g. (:require [ns.demoscene :as demoscene]). My main function is located in core.cljs.
I start a figwheel REPL using lein figwheel, start my browser, everything works fine.
If I edit a function in objects.cljs and save the changes, I get a compiler warning:

Compile Warning src/cljs/ns/demoscene.cljs
update already refers to: cljs.core/update being replaced by: ns.demoscene/update

This is really odd on more than one level:

  1. I didn't edit demoscene.cljs
  2. Why should cljs.core/update be replaced by ns.demoscene/update
  3. If I reload the site (I do not restart the figwheel session), everything is fine again. My changes are applied etc.

Can you tell me, what is happening in the background? What am I missing to understand this situation? What do I have to do to avoid these warnings?

Please tell me if you need any more resources.


Solution

  • I didn't edit demoscene.cljs

    I think this might be reloaded because it's required by the file you did edit: core.cljs.

    Why should cljs.core/update be replaced by ns.demoscene/update

    You'll see this warning whenever you define a function of the same name as a core namespace function, because those core functions are always available by default in your namespaces. The warning is telling you any call to update in that namespace will not be cljs.core/update; it will be the update function you defined in your namespace. You can explicitly exclude any core functions that you want to "overshadow" in your namespace e.g. (:refer-clojure :exclude [update])