Details
-
Type:
Defect
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Completed
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Patch:Code
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:
(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.
(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)))
fixed http://github.com/clojure/clojurescript/commit/808f9989249506b92186f919d8eb886557fb31ee