<< Back to previous view

[CLJS-621] Infer tags from :var ops Created: 15/Oct/13  Updated: 15/Oct/13  Resolved: 15/Oct/13

Status: Closed
Project: ClojureScript
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Travis Thieman Assignee: Unassigned
Resolution: Completed Votes: 0
Labels: None

Attachments: File infer-tags-from-vars-20131015.diff    
Patch: Code


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]
    (java.io.StringReader. s)))

(defn forms-seq [stream]
  (let [rdr (readers/indexing-push-back-reader stream 1)
        forms-seq* (fn forms-seq* []
                        (if-let [form (reader/read rdr nil nil)]
                          (cons form (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)))

Comment by David Nolen [ 15/Oct/13 7:14 PM ]

fixed http://github.com/clojure/clojurescript/commit/808f9989249506b92186f919d8eb886557fb31ee

Generated at Sun May 19 02:24:54 CDT 2019 using JIRA 4.4#649-r158309.