ClojureScript

Infer tags from :var ops

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor 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)))

Activity

Travis Thieman made changes -
Field Original Value New Value
Attachment infer-tags-from-vars-20131015.diff [ 12323 ]
Travis Thieman made changes -
Attachment infer-tags-from-vars-20131015.diff [ 12325 ]
David Nolen made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
David Nolen made changes -
Status Resolved [ 5 ] Closed [ 6 ]

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: