Skip to content

Commit 3c7c37b

Browse files
committed
CLJS-3140: Not inferring on implements?
1 parent 63cddf1 commit 3c7c37b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,14 +1599,15 @@
15991599

16001600
(defn- type-check-induced-tag
16011601
"Look for a type-check-induced tag when the test expression is the use of
1602-
instance? on a local, as in (instance? ICounted x)."
1602+
instance? on a local, as in (instance? UUID x) or implements? on a local, as
1603+
in (implements? ICounted x)."
16031604
[env test]
16041605
(when (and (list? test)
16051606
(== 3 (count test))
16061607
(every? symbol? test))
16071608
(let [analyzed-fn (no-warn (analyze (assoc env :context :expr) (first test)))]
16081609
(when (= :var (:op analyzed-fn))
1609-
(when ('#{cljs.core/instance?} (:name analyzed-fn))
1610+
(when ('#{cljs.core/instance? cljs.core/implements?} (:name analyzed-fn))
16101611
(let [analyzed-type (no-warn (analyze (assoc env :context :expr) (second test)))
16111612
tag (:name analyzed-type)
16121613
sym (last test)]

src/test/clojure/cljs/analyzer_tests.clj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,3 +2091,13 @@
20912091
(env/with-compiler-env test-cenv
20922092
(:tag (ana/analyze test-env '(let [x ^any []] (if (qualified-ident? x) x nil))))))
20932093
'#{cljs.core/Keyword cljs.core/Symbol clj-nil})))
2094+
2095+
(deftest test-cljs-3140
2096+
(is (= (ana/no-warn
2097+
(env/with-compiler-env test-cenv
2098+
(:tag (ana/analyze test-env '(let [x ^any []] (if (instance? UUID x) x nil))))))
2099+
'#{cljs.core/UUID clj-nil}))
2100+
(is (= (ana/no-warn
2101+
(env/with-compiler-env test-cenv
2102+
(:tag (ana/analyze test-env '(let [x ^any []] (if (implements? ICounted x) x nil))))))
2103+
'#{cljs.core/ICounted clj-nil})))

0 commit comments

Comments
 (0)