Created
April 2, 2017 19:31
-
-
Save mfikes/9ed67b91961cb8a689704ca7f720de22 to your computer and use it in GitHub Desktop.
Infer ret-tag for fn forms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 3db640efe0f312598199838a2e8fd58b358ac748 Mon Sep 17 00:00:00 2001 | |
From: Mike Fikes <mike@fikesfarm.com> | |
Date: Sun, 2 Apr 2017 15:07:05 -0400 | |
Subject: [PATCH] Infer ret-tag for fn forms | |
--- | |
src/main/clojure/cljs/analyzer.cljc | 6 +++++- | |
1 file changed, 5 insertions(+), 1 deletion(-) | |
diff --git a/src/main/clojure/cljs/analyzer.cljc b/src/main/clojure/cljs/analyzer.cljc | |
index 75f64f3..6dbb154 100644 | |
--- a/src/main/clojure/cljs/analyzer.cljc | |
+++ b/src/main/clojure/cljs/analyzer.cljc | |
@@ -1337,7 +1337,7 @@ | |
(analyze (assoc env :context :expr) (:init args) sym)))) | |
fn-var? (and (some? init-expr) (= (:op init-expr) :fn)) | |
tag (if fn-var? | |
- (or (:ret-tag init-expr) tag) | |
+ (or (:ret-tag init-expr) tag (:inferred-ret-tag init-expr)) | |
(or tag (:tag init-expr))) | |
export-as (when-let [export-val (-> sym meta :export)] | |
(if (= true export-val) var-name export-val)) | |
@@ -1547,6 +1547,9 @@ | |
js-doc (when (true? variadic) | |
"@param {...*} var_args") | |
children (mapv :expr methods) | |
+ inferred-ret-tag (let [inferred-tags (map (partial infer-tag env) children)] | |
+ (when (apply = inferred-tags) | |
+ (first inferred-tags))) | |
ast {:op :fn | |
:env env | |
:form form | |
@@ -1554,6 +1557,7 @@ | |
:methods methods | |
:variadic variadic | |
:tag 'function | |
+ :inferred-ret-tag inferred-ret-tag | |
:recur-frames *recur-frames* | |
:loop-lets *loop-lets* | |
:jsdoc [js-doc] | |
-- | |
2.5.4 (Apple Git-61) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment