We're updating the issue view to help you get more done. 

Infer tags from :var ops

Description

cljs.compiler/infer-tag fails on the form "(and true false)", returning nil when boolean is expected. Previously, infer-tag stopped traversing the AST when a :var op was found. The macroexpansion of this form is:

1 (clojure.core/let [and__3941__auto__ true] (if and__3941__auto__ (clojure.core/and false) and__3941__auto__))

The failure lies in the :else clause of the if. infer-tag returned nil since this was a :var. This patch causes infer-tag to successfully infer the boolean tag in this situation.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 (ns patch (:require [clojure.tools.reader :as reader] [clojure.tools.reader.reader-types :as readers] [cljs.analyzer :as ana] [cljs.compiler :as c]) (:import [java.io StringReader])) (defn string-reader [s] (clojure.lang.LineNumberingPushbackReader. (java.io.StringReader. s))) (defn forms-seq [stream] (let [rdr (readers/indexing-push-back-reader stream 1) forms-seq* (fn forms-seq* [] (lazy-seq (if-let [form (reader/read rdr nil nil)] (cons form (forms-seq*)))))] (forms-seq*))) (def user-env '{:ns {:name cljs.user} :locals {}}) (defn read1 [str] (first (forms-seq (string-reader str)))) ;; successfully infers boolean (let [form (read1 "(let [x true] true)")] (c/infer-tag (ana/analyze user-env form))) ;; fails, infers nil before patch (let [form (read1 "(and true false)")] (c/infer-tag (ana/analyze user-env form)))

Environment

None

Status

Assignee

Unassigned

Reporter

Travis Thieman

Labels

None

Approval

None

Patch

Code

Priority

Minor