Skip to content

Commit 4ac13fc

Browse files
committed
CLJS-1997: Outward function type hint propagation
1 parent ea53fd0 commit 4ac13fc

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,7 @@
16031603
(analyze (assoc env :context :expr) (:init args) sym))))
16041604
fn-var? (and (some? init-expr) (= (:op init-expr) :fn))
16051605
tag (if fn-var?
1606-
(or (:ret-tag init-expr) tag)
1606+
(or (:ret-tag init-expr) tag (:inferred-ret-tag init-expr))
16071607
(or tag (:tag init-expr)))
16081608
export-as (when-let [export-val (-> sym meta :export)]
16091609
(if (= true export-val) var-name export-val))
@@ -1844,13 +1844,17 @@
18441844
children (if (some? name-var)
18451845
[:local :methods]
18461846
[:methods])
1847+
inferred-ret-tag (let [inferred-tags (map (partial infer-tag env) (map :body methods))]
1848+
(when (apply = inferred-tags)
1849+
(first inferred-tags)))
18471850
ast (merge {:op :fn
18481851
:env env
18491852
:form form
18501853
:name name-var
18511854
:methods methods
18521855
:variadic? variadic
18531856
:tag 'function
1857+
:inferred-ret-tag inferred-ret-tag
18541858
:recur-frames *recur-frames*
18551859
:loop-lets *loop-lets*
18561860
:jsdoc [js-doc]

0 commit comments

Comments
 (0)