Skip to content

Commit 7171db2

Browse files
committed
CLJS-3239: Infinite analysis with dotted symbols
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])`
1 parent 16e2ce4 commit 7171db2

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/main/clojure/cljs/analyzer.cljc

+7-2
Original file line numberDiff line numberDiff line change
@@ -2915,11 +2915,16 @@
29152915
(every? symbol? spec))
29162916
(and (symbol? spec) (nil? (namespace spec))))
29172917
(throw (error env (parse-ns-error-msg spec "Only lib.ns.Ctor or [lib.ns Ctor*] spec supported in :import"))))
2918-
(let [import-map (if (sequential? spec)
2918+
(let [import-map (cond
2919+
(sequential? spec)
29192920
(->> (rest spec)
29202921
(map #(vector % (symbol (str (first spec) "." %))))
29212922
(into {}))
2922-
{(symbol (last (string/split (str spec) #"\."))) spec})]
2923+
2924+
(not (== -1 (.indexOf (str spec) ".")))
2925+
{(symbol (last (string/split (str spec) #"\."))) spec}
2926+
2927+
:else {})]
29232928
(doseq [[_ spec] import-map]
29242929
(swap! deps conj spec))
29252930
{:import import-map

src/test/clojure/cljs/analyzer_tests.clj

+3-6
Original file line numberDiff line numberDiff line change
@@ -1485,13 +1485,10 @@
14851485
(:import [goog.history Html5History]))]))
14861486
(is (some? (get-in @cenv [::ana/namespaces 'goog.history.Html5History :defs 'Html5History])))))
14871487

1488-
(comment
1489-
1488+
(deftest test-cljs-3239
14901489
(let [cenv (env/default-compiler-env)]
14911490
(env/with-compiler-env cenv
14921491
(ana/analyze-form-seq
14931492
'[(ns test.foo
1494-
(:import [goog.history Html5History]))]))
1495-
(get-in @cenv [::ana/namespaces 'goog.history.Html5History :defs]))
1496-
1497-
)
1493+
(:import goog))]))
1494+
(is (= {} (get-in @cenv [::ana/namespaces 'test.foo :imports])))))

0 commit comments

Comments
 (0)