Skip to content

Commit 483edea

Browse files
roman01laswannodette
authored andcommitted
CLJS-3181: Externs inference fails, even when manual type hint is provided
1 parent c205921 commit 483edea

File tree

2 files changed

+41
-24
lines changed

2 files changed

+41
-24
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3671,11 +3671,14 @@
36713671
f-sym (when bind-f-expr? (gensym "fexpr__"))
36723672
bindings (cond-> []
36733673
bind-args? (into (interleave arg-syms args))
3674-
bind-f-expr? (conj f-sym (analyzed f)))]
3674+
bind-f-expr? (conj f-sym (analyzed f)))
3675+
tag (:tag (meta form))]
36753676
(analyze env
36763677
`(let [~@bindings]
3677-
(~(analyzed (if bind-f-expr? f-sym f))
3678-
~@(if bind-args? arg-syms args)))))
3678+
~(with-meta
3679+
`(~(analyzed (if bind-f-expr? f-sym f))
3680+
~@(if bind-args? arg-syms args))
3681+
{:tag tag}))))
36793682
(let [ana-expr #(analyze enve %)
36803683
argexprs (mapv ana-expr args)]
36813684
(if (and (and (keyword? f)

src/test/clojure/cljs/analyzer_tests.clj

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@
926926
;; dotted :var
927927
(is (= [:host-field 'bar :host-field 'foo :var 'cljs.core/inc 'cljs.core/inc]
928928
(-> (ana inc.foo.bar)
929-
((juxt :op
929+
((juxt :op
930930
:field
931931
(comp :op :target)
932932
(comp :field :target)
@@ -936,7 +936,7 @@
936936
;; dotted :local
937937
(is (= [:host-field 'c :host-field 'b :local 'a 'a]
938938
(-> (ana (let [a 1] a.b.c)) :body :ret
939-
((juxt :op
939+
((juxt :op
940940
:field
941941
(comp :op :target)
942942
(comp :field :target)
@@ -974,22 +974,22 @@
974974
(is (= (-> (ana (let [a 1] a)) :body :ret :form) 'a))
975975
(is (map? (-> (ana (let [a 1] a)) :body :ret :env)))
976976
;; dotted :local
977-
(is (= [:host-field 'c :host-field 'b :local 'a]
977+
(is (= [:host-field 'c :host-field 'b :local 'a]
978978
(-> (ana (let [a 1] a.b.c)) :body :ret
979-
((juxt :op
979+
((juxt :op
980980
:field
981981
(comp :op :target)
982982
(comp :field :target)
983983
(comp :op :target :target)
984984
(comp :name :target :target))))))
985985
;local shadow
986986
(is (= 'alert
987-
(ana/no-warn (-> (ana (let [alert 1] js/alert)) :body
987+
(ana/no-warn (-> (ana (let [alert 1] js/alert)) :body
988988
:env :locals
989989
(get 'alert)
990990
:name))))
991991
(is (= [:local 'alert]
992-
(ana/no-warn (-> (ana (let [alert 1] js/alert)) :body :ret
992+
(ana/no-warn (-> (ana (let [alert 1] js/alert)) :body :ret
993993
((juxt :op :name))))))
994994
;loop
995995
(is (= (-> (ana (loop [])) :op) :loop))
@@ -1020,7 +1020,7 @@
10201020
; :finally
10211021
(is (= (-> (ana (try (finally 1))) :finally :op) :do))
10221022
(is (= (-> (ana (try (finally 1))) :finally :ret :op) :const))
1023-
;TODO case
1023+
;TODO case
10241024
(is (= (-> (ana (case 1)) :op) :let))
10251025
(is (= (-> (ana (case 1)) :body :ret :op) :case))
10261026
(is (= (-> (ana (case 1)) :body :ret :children) [:test :nodes :default]))
@@ -1063,7 +1063,7 @@
10631063
; :ns/:name
10641064
(is (= ['cljs.core 'cljs.core/a] (-> (ana (def a 1)) ((juxt :ns :name)))))
10651065
; :var
1066-
(is (= [:var 'cljs.core 'cljs.core/a 'a]
1066+
(is (= [:var 'cljs.core 'cljs.core/a 'a]
10671067
(-> (ana (def a 1)) :var
10681068
((juxt :op :ns :name :form)))))
10691069
; :init
@@ -1076,9 +1076,9 @@
10761076
(is (= :do (-> (ana (deftype A [a] Object (toString [this] a))) :statements first :body :op)))
10771077
; field reference
10781078
(is (= [:local :field]
1079-
(-> (ana (deftype A [a] Object (toString [this] a)))
1079+
(-> (ana (deftype A [a] Object (toString [this] a)))
10801080
:statements first :body :ret :val :methods
1081-
first :body :ret :body :ret
1081+
first :body :ret :body :ret
10821082
((juxt :op :local)))))
10831083
;defrecord
10841084
(is (= :defrecord (-> (ana (defrecord Ab [])) :body :statements first :ret :op)))
@@ -1139,10 +1139,10 @@
11391139
(-> (ana (fn [])) :methods first :params)))
11401140
(is (vector?
11411141
(-> (ana (fn [a b])) :methods first :params)))
1142-
(is (= [:binding 'a :arg]
1142+
(is (= [:binding 'a :arg]
11431143
(-> (ana (fn [a b])) :methods first :params
11441144
first ((juxt :op :name :local)))))
1145-
(is (= [:binding 'b :arg]
1145+
(is (= [:binding 'b :arg]
11461146
(-> (ana (fn [a b])) :methods first :params
11471147
second ((juxt :op :name :local)))))
11481148
;if
@@ -1342,7 +1342,7 @@
13421342
(is (= :throw (-> (ana (throw (js/Error. "bad"))) :op)))
13431343
(is (= [:exception] (-> (ana (throw (js/Error. "bad"))) :children)))
13441344
; :exception
1345-
(is (= [:js-var 'js 'js/Error] (-> (ana (throw (js/Error. "bad"))) :exception
1345+
(is (= [:js-var 'js 'js/Error] (-> (ana (throw (js/Error. "bad"))) :exception
13461346
:class
13471347
((juxt :op :ns :name)))))
13481348
;vector
@@ -1405,39 +1405,39 @@
14051405
;munging
14061406
(is (=
14071407
[false 'a]
1408-
(->
1408+
(->
14091409
(ana (let [a (println 1)
14101410
b (println 2)]
14111411
[a b]))
1412-
:bindings first
1412+
:bindings first
14131413
((juxt #(contains? % :ns) :name)))))
14141414
;shadowing
14151415
(is (=
14161416
'a
1417-
(->
1417+
(->
14181418
(ana (let [a (println 1)
14191419
a (println 2)]
14201420
[a a]))
1421-
:bindings second
1421+
:bindings second
14221422
:shadow
14231423
:name)))
14241424
(is (=
14251425
'a
1426-
(->
1426+
(->
14271427
(ana (let [a (println 1)
14281428
a (println 2)
14291429
a (println 3)
14301430
]
14311431
[a a a]))
1432-
:bindings (nth 2)
1432+
:bindings (nth 2)
14331433
:shadow
14341434
:shadow
14351435
:name)))
14361436
;ns
1437-
(is
1437+
(is
14381438
(binding [ana/*analyze-deps* false]
14391439
(binding [ana/*cljs-ns* 'cljs.user]
1440-
(ana
1440+
(ana
14411441
(ns my.ns.foo
14421442
(:require [clojure.repl]
14431443
[clojure.string]
@@ -2137,3 +2137,17 @@
21372137
(is (= w2 "cljs.core/-, all arguments must be numbers, got [string] instead"))
21382138
(is (= w3 "cljs.core//, all arguments must be numbers, got [number string] instead"))
21392139
(is (= w4 "cljs.core/*, all arguments must be numbers, got [string] instead")))))
2140+
2141+
(deftest test-cljs-3181
2142+
(let [ws (atom [])
2143+
res (binding [ana/*cljs-static-fns* true]
2144+
(infer-test-helper
2145+
{:forms '[(ns warn-on-infer-test.app)
2146+
(set! *warn-on-infer* true)
2147+
(defn f [gfn]
2148+
(.then ^js/Promise (gfn (inc 1)) identity))]
2149+
:externs ["src/test/externs/test.js"]
2150+
:warnings ws
2151+
:warn false
2152+
:with-core? true}))]
2153+
(is (empty? @ws))))

0 commit comments

Comments
 (0)