Skip to content

Commit 76a03f5

Browse files
committed
CLJS-3133: simple-* / qualified-* predicate-induced inference
1 parent 11de795 commit 76a03f5

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,12 @@
15501550
cljs.core/delay? cljs.core/Delay
15511551
cljs.core/reduced? cljs.core/Reduced
15521552

1553+
;; Subtypes
1554+
cljs.core/simple-keyword? cljs.core/Keyword
1555+
cljs.core/qualified-keyword? cljs.core/Keyword
1556+
cljs.core/simple-symbol? cljs.core/Symbol
1557+
cljs.core/qualified-symbol? cljs.core/Symbol
1558+
15531559
;;; Note: For non-marker protocol entries below, we
15541560
;;; omit predicates that are based on satisfies? because
15551561
;;; we cannot safely apply the fast-path optimization
@@ -1570,6 +1576,10 @@
15701576
;; Composites
15711577
cljs.core/seqable? #{cljs.core/ISeqable array string}
15721578
cljs.core/ident? #{cljs.core/Keyword cljs.core/Symbol}
1579+
1580+
;; Composite subtypes
1581+
cljs.core/simple-ident? #{cljs.core/Keyword cljs.core/Symbol}
1582+
cljs.core/qualified-ident? #{cljs.core/Keyword cljs.core/Symbol}
15731583
})
15741584

15751585
(defn- simple-predicate-induced-tag

src/test/clojure/cljs/analyzer_tests.clj

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,3 +2054,40 @@
20542054
(is #(= '#{([this] [this x] [this x y])} (set (map :arglists (vals sigs)))))
20552055
(is #(= '#{"foo fn" "bar fn" "baz fn"} (set (map :doc (vals sigs)))))))
20562056

2057+
(deftest test-cljs-3133
2058+
(is (= (ana/no-warn
2059+
(env/with-compiler-env test-cenv
2060+
(:tag (ana/analyze test-env '(let [x ^any []] (if (keyword? x) x nil))))))
2061+
'#{cljs.core/Keyword clj-nil}))
2062+
(is (= (ana/no-warn
2063+
(env/with-compiler-env test-cenv
2064+
(:tag (ana/analyze test-env '(let [x ^any []] (if (simple-keyword? x) x nil))))))
2065+
'#{cljs.core/Keyword clj-nil}))
2066+
(is (= (ana/no-warn
2067+
(env/with-compiler-env test-cenv
2068+
(:tag (ana/analyze test-env '(let [x ^any []] (if (qualified-keyword? x) x nil))))))
2069+
'#{cljs.core/Keyword clj-nil}))
2070+
(is (= (ana/no-warn
2071+
(env/with-compiler-env test-cenv
2072+
(:tag (ana/analyze test-env '(let [x ^any []] (if (symbol? x) x nil))))))
2073+
'#{cljs.core/Symbol clj-nil}))
2074+
(is (= (ana/no-warn
2075+
(env/with-compiler-env test-cenv
2076+
(:tag (ana/analyze test-env '(let [x ^any []] (if (simple-symbol? x) x nil))))))
2077+
'#{cljs.core/Symbol clj-nil}))
2078+
(is (= (ana/no-warn
2079+
(env/with-compiler-env test-cenv
2080+
(:tag (ana/analyze test-env '(let [x ^any []] (if (qualified-symbol? x) x nil))))))
2081+
'#{cljs.core/Symbol clj-nil}))
2082+
(is (= (ana/no-warn
2083+
(env/with-compiler-env test-cenv
2084+
(:tag (ana/analyze test-env '(let [x ^any []] (if (ident? x) x nil))))))
2085+
'#{cljs.core/Keyword cljs.core/Symbol clj-nil}))
2086+
(is (= (ana/no-warn
2087+
(env/with-compiler-env test-cenv
2088+
(:tag (ana/analyze test-env '(let [x ^any []] (if (simple-ident? x) x nil))))))
2089+
'#{cljs.core/Keyword cljs.core/Symbol clj-nil}))
2090+
(is (= (ana/no-warn
2091+
(env/with-compiler-env test-cenv
2092+
(:tag (ana/analyze test-env '(let [x ^any []] (if (qualified-ident? x) x nil))))))
2093+
'#{cljs.core/Keyword cljs.core/Symbol clj-nil})))

0 commit comments

Comments
 (0)