Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix CTYP-62. Else filter is handled more carefully in = wrt simplifyi…

…ng to ff
  • Loading branch information...
commit 1fa44df8c1e341be333f06562a807f73d38ecda2 1 parent 3b79dfe
@frenchy64 frenchy64 authored
View
33 src/main/clojure/clojure/core/typed/check.clj
@@ -1251,6 +1251,7 @@
{:pre [(every? TCResult? vs)]
:post [(TCResult? %)]}
(assert (#{:=} comparator))
+ (assert (seq vs))
(let [; TODO sequence behaviour is subtle
; conservative for now
equiv-able (fn [t]
@@ -1258,18 +1259,32 @@
(when (r/Value? t)
((some-fn number? symbol? keyword? nil? true? false? class?) (.val ^Value t)))))
vs-combinations (comb/combinations vs 2)
+ ;_ (prn vs-combinations)
then-filter (apply fo/-and (apply concat
(for [[{t1 :t fl1 :fl o1 :o}
{t2 :t fl2 :fl o2 :o}] vs-combinations]
- (cond
- (equiv-able t1) [(fo/-filter-at t1 o2)]
- (equiv-able t2) [(fo/-filter-at t2 o1)]))))
- else-filter (apply fo/-or (apply concat
- (for [[{t1 :t fl1 :fl o1 :o}
- {t2 :t fl2 :fl o2 :o}] vs-combinations]
- (cond
- (equiv-able t1) [(fo/-not-filter-at t1 o2)]
- (equiv-able t2) [(fo/-not-filter-at t2 o1)]))))]
+ (concat
+ (when (equiv-able t1)
+ [(fo/-filter-at t1 o2)])
+ (when (equiv-able t2)
+ [(fo/-filter-at t2 o1)])))))
+ ;_ (prn then-filter)
+ else-filter (apply fo/-or
+ (if-let [fs (seq (apply concat
+ (for [[{t1 :t fl1 :fl o1 :o}
+ {t2 :t fl2 :fl o2 :o}] vs-combinations]
+ (concat
+ (when (equiv-able t1)
+ [(fo/-not-filter-at t1 o2)])
+ (when (equiv-able t2)
+ [(fo/-not-filter-at t2 o1)])))))]
+ fs
+ ; ensure we don't simplify to ff if we have more than one
+ ; argument to = (1 arg is always a true value)
+ (when (< 1 (count vs))
+ [fl/-top])))
+ ;_ (prn else-filter)
+ ]
(ret (c/Un r/-false r/-true)
(fo/-FS then-filter else-filter))))
View
24 src/test/clojure/clojure/core/typed/test/core.clj
@@ -2,7 +2,7 @@
(:import (clojure.lang ISeq ASeq IPersistentVector Atom IPersistentMap
Keyword ExceptionInfo Symbol Var))
(:require [clojure.test :refer :all]
- [clojure.tools.analyzer :refer [ast]]
+ [clojure.tools.analyzer :refer [ast analyze-form]]
[clojure.tools.analyzer.hygienic :refer [ast-hy]]
[clojure.repl :refer [pst]]
[clojure.pprint :refer [pprint]]
@@ -11,7 +11,8 @@
[clojure.core.typed.init]
[clojure.core.typed.utils :as u :refer [with-ex-info-handlers top-level-error?]]
[clojure.core.typed.current-impl :as impl]
- [clojure.core.typed.check :as chk :refer [expr-type tc-t combine-props env+ update check-funapp]]
+ [clojure.core.typed.check :as chk :refer [expr-type tc-t combine-props env+ update check-funapp
+ tc-equiv]]
[clojure.core.typed.inst :as inst]
[clojure.core.typed.subtype :as sub]
[clojure.core.typed.type-rep :refer :all]
@@ -238,10 +239,15 @@
(map parse-type '(Integer Double Float)))
(parse-type '[[Double Float -> Integer] (clojure.lang.Seqable Double) (clojure.lang.Seqable Float) -> (clojure.lang.Seqable Integer)]))))
+;return ret for an expression f
+(defmacro eret [f]
+ `(let [ret# (-> (check-form-info '~f) :ret)]
+ (assert (TCResult? ret#))
+ ret#))
+
;return type for an expression f
(defmacro ety [f]
- `(impl/with-clojure-impl
- (-> (ast ~f) ast-hy check expr-type ret-t)))
+ `(-> (eret ~f) ret-t))
(deftest tc-invoke-fn-test
(is-clj (subtype? (ety
@@ -1999,6 +2005,16 @@
(check-ns 'clojure.core.typed.test.fail.CTYP-37))))
+(deftest CTYP-62-equiv-test
+ (is (tc-equiv :=
+ (ret (-val "a"))
+ (ret -any))
+ (ret (Un -false -true)))
+ (is (= (eret (= "a" (clojure.core.typed/ann-form 1 Any)))
+ (ret (Un -false -true))))
+ (is (= (eret (= "a" (clojure.core.typed/ann-form 1 Any)))
+ (ret (Un -false -true)))))
+
;(reset-caches)
;(chk/abstract-result
Please sign in to comment.
Something went wrong with that request. Please try again.