Skip to content

Commit

Permalink
CLJS-3239: Infinite analysis with dotted symbols
Browse files Browse the repository at this point in the history
The analysis change for dotted symbols revealed a bug with import parsing.

`(:import goog)` would result in `:imports {goog goog}` in the ns analysis
map. Then when resolving a symbol like `goog.debug.Console`, the analyzer would
go into an infinite loop. This loop was in the `:import` branch of resolve-var.
This is because the expectation is that the value side of `:imports` map
is *different*.  But in this case, `{goog goog}`, it is not different, so the
analyzer would get stuck.

Notably, `(:import [goog])` doesn't have this problem.

Make `(:import goog)` match `(:import [goog])`
  • Loading branch information
swannodette committed Apr 26, 2020
1 parent 16e2ce4 commit 7171db2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/main/clojure/cljs/analyzer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2915,11 +2915,16 @@
(every? symbol? spec))
(and (symbol? spec) (nil? (namespace spec))))
(throw (error env (parse-ns-error-msg spec "Only lib.ns.Ctor or [lib.ns Ctor*] spec supported in :import"))))
(let [import-map (if (sequential? spec)
(let [import-map (cond
(sequential? spec)
(->> (rest spec)
(map #(vector % (symbol (str (first spec) "." %))))
(into {}))
{(symbol (last (string/split (str spec) #"\."))) spec})]

(not (== -1 (.indexOf (str spec) ".")))
{(symbol (last (string/split (str spec) #"\."))) spec}

:else {})]
(doseq [[_ spec] import-map]
(swap! deps conj spec))
{:import import-map
Expand Down
9 changes: 3 additions & 6 deletions src/test/clojure/cljs/analyzer_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1485,13 +1485,10 @@
(:import [goog.history Html5History]))]))
(is (some? (get-in @cenv [::ana/namespaces 'goog.history.Html5History :defs 'Html5History])))))

(comment

(deftest test-cljs-3239
(let [cenv (env/default-compiler-env)]
(env/with-compiler-env cenv
(ana/analyze-form-seq
'[(ns test.foo
(:import [goog.history Html5History]))]))
(get-in @cenv [::ana/namespaces 'goog.history.Html5History :defs]))

)
(:import goog))]))
(is (= {} (get-in @cenv [::ana/namespaces 'test.foo :imports])))))

0 comments on commit 7171db2

Please sign in to comment.