Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation breaks down in recent versions when changing CLJC file #708

Closed
mtruyens opened this issue May 11, 2020 · 4 comments
Closed

Compilation breaks down in recent versions when changing CLJC file #708

mtruyens opened this issue May 11, 2020 · 4 comments

Comments

@mtruyens
Copy link

Since a few versions, I get the error below when changing a CLJC file. I then have to kill Shadow-cljs, clean all directories, and restart it. (Note that I have quite some macros in my fairly large and complex code base, whereby the the macros affect both CLJS and CLJ files.)

No problems occur when changing only CLJS files.

I had to downgrade to the last version that worked perfectly, 2.8.93. If I recall correctly, the problem started somewhere around version 2.8.100, and the most recent one 2.9.0 also exhibits the problem.

Note that the error message about the redefining of a constant makes no sense. (Which is also evidenced by the fact that recompiling after cleaning the folders works fine. As does advanced compilation using lein-cljsbuild.)

Compilation failed!
Multiple files failed to compile.
------ ERROR -------------------------------------------------------------------
 File: /Users/mtruyens/symposix-stable/src-cljc/sx/cljc/utils/misc.cljc:11:1
--------------------------------------------------------------------------------
   8 |             #?(:clj  [clj-time.core :as clj-time]
   9 |                :cljs [cljs-time.core :as clj-time])))
  10 | 
  11 | (def ^:const app-title "ClauseBase")
-------^------------------------------------------------------------------------
Error in phase :compilation
Can't redefine a constant at line 11 sx/cljc/utils/misc.cljc
--------------------------------------------------------------------------------
  12 | 
  13 | (def ^:const docx-mimetype (str "application/vnd.openxmlformats-officedocument"
  14 |                         ".wordprocessingml.document"))
  15 | 
--------------------------------------------------------------------------------
------ ERROR -------------------------------------------------------------------
 File: /Users/mtruyens/symposix-stable/src-cljc/sx/cljc/lang/numerals.cljc:8:1
--------------------------------------------------------------------------------
   5 |             [sx.cljc.utils.string :as ustr]
   6 |             [clojure.string :as str]))
   7 | 
   8 | (declare ordinals cardinals)
-------^------------------------------------------------------------------------
Error in phase :compilation
Can't redefine a constant at line 8 sx/cljc/lang/numerals.cljc
--------------------------------------------------------------------------------
   9 | 
  10 | ; ----------------------------------------------------------------------------------------
  11 | 
  12 | (defn- nr->reverse-grouped-per-three
-------------------------------------
@thheller
Copy link
Owner

thheller commented May 11, 2020

I would strongly advise not using ^:const to begin with. It is buggy in all sorts of weird ways.

Beyond that this error is coming from the CLJS compiler. shadow-cljs version 2.8.101 bumped the clojurescript version from 1.10.597 to 1.10.741 so I'm guessing that is the shadow-cljs release where this started breaking for you?

PS: I can't reproduce with a local .cljc file.

@mtruyens
Copy link
Author

That's the first time I hear from this buggy behaviour, thanks! (Is it related to the warning made regarding the caching behaviour at the bottom of https://blog.fikesfarm.com/posts/2017-06-28-clojurescript-const-var-inlining.html ?)

Anyway, you seem to be right, because removing the ^:const does seem to remove errors (I have to comb through my entire code base, however).

The problem is, from my perspective, unrelated to the ClojureScript version. Both 1.10.597 and 1.10.758 work nicely with Shadow-cljs 2.8.93, even when changing those CLJC versions.

@mtruyens
Copy link
Author

Addendum: all ^:const declarations removed from my code base, and the error is indeed gone. Thanks!

@thheller
Copy link
Owner

thheller commented May 11, 2020

Well, the post you linked would be describing one of the bugs IMHO. I consider it a bug since the behavior is different from Clojure, not sure why that was added.

$ clj
Clojure 1.10.1
user=> (def ^:const x 1)
#'user/x
user=> (case 1 x true false)
false
$ shadow-cljs node-repl
shadow-cljs - config: /mnt/c/Users/thheller/code/shadow-cljs/shadow-cljs.edn
shadow-cljs - connected to server
cljs.user=> (def ^:const x 1)
#'cljs.user/x
cljs.user=> (case 1 x true false)
true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants