Permalink
Browse files

Fix CTYP-73

Support reduced
  • Loading branch information...
1 parent edeb6cf commit a75e1834be5c6cc6c329ec9f882a35b275f0f70a @frenchy64 frenchy64 committed Oct 6, 2013
@@ -6,7 +6,7 @@
ILookup Indexed Associative IPersistentStack PersistentVector Cons
IPersistentList IRef IReference AReference ARef Var Delay Reversible
ITransientCollection ITransientSet ITransientAssociative ITransientMap
- ITransientVector PersistentHashMap))
+ ITransientVector PersistentHashMap Reduced))
(:require [clojure.core.typed.base-env-helper :as h]
[clojure.core.typed.base-env-common :refer [delay-and-cache-env]]
[clojure.core.typed.parse-unparse :as prs]
@@ -457,6 +457,10 @@ LazySeq [[[a :variance :covariant]]
#_(TFn [[x :variance :covariant]] x)
#_(TFn [[x :variance :covariant]] (LazySeq x)))}]
+Reduced [[[a :variance :covariant]]
+ :replace
+ {IDeref (IDeref a)}]
+
; Hack for Seqable things. Not needed if Seqable was a protocol.
java.lang.CharSequence [[]
@@ -1056,11 +1060,14 @@ clojure.core/reduce
;Without accumulator
; default
; (reduce + my-coll)
- [[a c -> a] (NonEmptySeqable c) -> a]
- [(Fn [a c -> a] [-> a]) (Option (Seqable c)) -> a]
+ [[a c -> (U (Reduced a) a)] (NonEmptySeqable c) -> a]
+ [(Fn [a c -> (U (Reduced a) a)] [-> (U (Reduced a) a)]) (Option (Seqable c)) -> a]
; default
; (reduce + 3 my-coll)
- [[a c -> a] a (Option (Seqable c)) -> a]))
+ [[a c -> (U (Reduced a) a)] a (Option (Seqable c)) -> a]))
+
+clojure.core/reduced (All [x] [x -> (Reduced x)])
+clojure.core/reduced? (predicate (Reduced Any))
#_(comment
clojure.core/reduce
@@ -2357,6 +2357,15 @@
(deftest CTYP-74-malformed-TApp-test
(is (u/tc-error-thrown? (parse-type '([Any -> Any])))))
+(deftest CTYP-73-reduced-test
+ (is-cf (reduced 1) (clojure.lang.Reduced Number))
+ (is-cf @(reduced 1) Number)
+ (is-cf (reduce (clojure.core.typed/ann-form
+ (fn [a b] (if (= a b) 1 (reduced 1)))
+ [Number Number -> (U (clojure.lang.Reduced Number) Number)])
+ 1 [1 2 3])
+ Number))
+
;(reset-caches)
;(chk/abstract-result

0 comments on commit a75e183

Please sign in to comment.