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

externs fail on seeing defprotocol #16

Closed
gmp26 opened this issue Jan 24, 2017 · 3 comments
Closed

externs fail on seeing defprotocol #16

gmp26 opened this issue Jan 24, 2017 · 3 comments

Comments

@gmp26
Copy link

gmp26 commented Jan 24, 2017

On externs.js generation it's throwing

#object[java.io.File 0x2195f9a7 "src/graphics/scales.cljs"] #error {
 :cause "Can't change/establish root binding of: *unchecked-if* with set"
 :via
 [{:type clojure.lang.ExceptionInfo
   :message "Can't change/establish root binding of: *unchecked-if* with set in file src/graphics/scales.cljs"
   :data {:tag :cljs/analysis-error}
   :at [clojure.core$ex_info invokeStatic "core.clj" 4724]}
  {:type java.lang.IllegalStateException
   :message "Can't change/establish root binding of: *unchecked-if* with set"
   :at [clojure.lang.Var set "Var.java" 221]}]

Google this error and you find reference to an old clojurescript REPL problem where the problem was triggered by analysing a defprotocol form. I suspect the cause is similar here since src/graphics/scales.cljs is the new file in my repo that triggered this problem, and the only one in my app that uses defprotocol, and the stack trace contains this snippet: (edited)

[cljs.analyzer$analyze invoke "analyzer.cljc" 3061]
[externs$file_ast$fn__21780 invoke "externs.clj" 94]
[clojure.core$mapv$fn__9114 invoke "core.clj" 6785]
[clojure.core.protocols$fn__8889 invokeStatic "protocols.clj" 167]
[clojure.core.protocols$fn__8889 invoke "protocols.clj" 124]

I'll keep ferreting around to try and find a minimal case, but thought I'd let you know about the issue. The generated externs.js file ends up with a bad statement on line 1:

var ={};

Here is the fix David Nolen applied to the repl.
https://groups.google.com/forum/#!topic/clojurescript/__Qf6L40cwU.

Maybe we need to do something similar in externs.clj?...
See clojure/clojurescript@b2e3a46.

@gmp26
Copy link
Author

gmp26 commented Jan 24, 2017

Following above idea, I've added this binding to externs.clj:90

ana/*unchecked-if* false

This is a partial fix in that there is no longer an exception. However the dodgy var ={}; is still generated.

@seantempesta
Copy link
Owner

So, I ended up disabling @tiensonqin's extern inference code in favor of Clojurescript's new :infer-externs. Have you tried that?

https://clojurescript.org/guides/externs

:prod {:cljsbuild {:builds [{:id           "main"
                                          :source-paths ["src" "env/prod" "../kidlink-server/src/cljc/"]
                                          :compiler     {:output-to          "main.js"
                                                         :source-map         "main.js.map"
                                                         :main               "env.main"
                                                         :output-dir         "target"
                                                         :infer-externs      true
                                                         :parallel-build     true
                                                         :optimize-constants true
                                                         :optimizations      :advanced
                                                         :closure-defines    {"goog.DEBUG" false}}}]}}})

@seantempesta
Copy link
Owner

I'm closing this issue in favor of clojurescript compilers :infer-externs setting.

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