<< Back to previous view

[CTYP-54] Merge compatible types to make more accurate ones Created: 11/Sep/13  Updated: 11/Sep/13

Status: Open
Project: core.typed
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Major
Reporter: Ambrose Bonnaire-Sergeant Assignee: Ambrose Bonnaire-Sergeant
Resolution: Unresolved Votes: 0
Labels: None


 Description   

We need to figure out how to merge types like (I (Vec Any) (Seqable Number)). A general solution is probably needed: we want a way for new types to "plug in" to this behaviour.

This needs to be considered in Clojurescript too, where Vec and Seqable are implemented as protocols and do not have an inheritance relationship.

(From https://gist.github.com/pnf/e208b0d44860aedc9c9d)

;; There seems to be some difficulty in merging the two assertions here.
(t/ann testassert6 [(t/Vec Any) -> (t/Vec t/AnyInteger)])
(defn testassert6 [m]
(assert (vector? m)) ; this should be redundant
(assert (every? integer? m))
m)
;; Type Error (imdb.testassert:92) Local binding m expected type (t/Vec t/AnyInteger), but actual type (I (IPersistentVector Any) (t/Coll t/AnyInteger))
;; in: m
;; Type Error (imdb.testassert:92) Type mismatch:
;; Expected: (t/Vec t/AnyInteger)
;; Actual: (I (IPersistentVector Any) (t/Coll t/AnyInteger))
;; in: (do (if (clojure.core/vector? m) nil (throw (new java.lang.AssertionError #))) (if (clojure.core/every? clojure.core/integer? m) nil (throw (new java.lang.AssertionError #))) m)
;; Type Error (imdb.testassert:92:1) Type mismatch:
;; Expected: (Fn [(t/Vec Any) -> (t/Vec t/AnyInteger)])
;; Actual: (Fn [(t/Vec Any) -> (I (IPersistentVector Any) (t/Coll t/AnyInteger)) :filters {:then (& (is (IPersistentVector Any) 0) (! (U nil false) 0)), :else (is (U nil false) 0)} :object {:id 0}])
;; in: (def testassert6 (fn* ([m] (do # # m))))


Generated at Fri Nov 28 18:21:15 CST 2014 using JIRA 4.4#649-r158309.