secret
Last active

  • Download Gist
typed-error.clj
Clojure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
(ns imdb.testassert
(:require [clojure.core.typed :as t]))
;; This should and does work.
(t/ann testassert1 [(HMap) -> (HMap :mandatory {:foo (t/Seqable t/AnyInteger)})])
(defn testassert1 [m]
(assert (vector? (:foo m)))
(assert (every? integer? (:foo m)))
m
)
 
;; I think this should give me an error, as there's been no assertion about the contents of
;; the :foo value, but it does not.
(t/ann testassert2 [(HMap) -> (HMap :mandatory {:foo (t/Seqable t/AnyInteger)})])
(defn testassert2 [m]
(assert (vector? (:foo m)))
m
)
 
;; Using (Map Any Any) instead of (HMap) results in errors that I don't understand.
(t/ann testassert3 [(t/Map Any Any) -> (HMap :mandatory {:foo (t/Seqable t/AnyInteger)})])
(defn testassert3 [m] ;23
(assert (vector? (:foo m))) ;24
(assert (every? integer? (:foo m))) ;25
m
)
;; Type Error (imdb.testassert:23:11) Polymorphic function clojure.core/every? could not be applied to arguments:
;; Polymorphic Variables:
;; x
;; y
;; Domains:
;; (Fn [x -> Any :filters {:then (is y 0), :else tt}]) (t/Coll x)
;; (Fn [x -> Any :filters {:then (is y 0), :else tt}]) (U nil (t/Coll x))
;; (Fn [x -> Any]) (U (clojure.lang.Seqable x) nil)
;; Arguments:
;; (Fn [Any -> boolean :filters {:then (is t/AnyInteger 0), :else (! t/AnyInteger 0)}]) Any
;; Ranges:
;; Boolean :filters {:then (is (t/Coll y) 1), :else tt}
;; Boolean :filters {:then (is (U (t/Coll y) nil) 1), :else tt}
;; Boolean
;; in: (clojure.core/every? clojure.core/integer? (:foo m))
;; in: (clojure.core/every? clojure.core/integer? (:foo m))
;; Type Error (imdb.testassert:21) Local binding m expected type (HMap :mandatory {:foo (t/Seqable t/AnyInteger)}), but actual type (IPersistentMap Any Any)
;; in: m
;; Type Error (imdb.testassert:21) Type mismatch:
;; Expected: (HMap :mandatory {:foo (t/Seqable t/AnyInteger)})
;; Actual: (IPersistentMap Any Any)
;; in: (do (if (clojure.core/vector? (:foo m)) nil (throw (new java.lang.AssertionError #))) (if (clojure.core/every? clojure.core/integer? (:foo m)) nil (throw (new java.lang.AssertionError #))) m)
;; Type Error (imdb.testassert:21:1) Type mismatch:
;; Expected: (Fn [(t/Map Any Any) -> (HMap :mandatory {:foo (t/Seqable t/AnyInteger)})])
;; Actual: (Fn [(t/Map Any Any) -> (IPersistentMap Any Any) :filters {:then (& (is (IPersistentMap Any Any) 0) (! (U nil false) 0)), :else (is (U nil false) 0)} :object {:id 0}])
;;in: (def testassert3 (fn* ([m] (do # # m))))
 
 
;; Get EXPECTED error, as nothing has been asserted.
(t/ann testassert4 [(t/Vec Any) -> (t/Vec t/AnyInteger)])
(defn testassert4 [m] ;72
m
)
;; Type Error (imdb.testassert:74) Local binding m expected type (t/Vec t/AnyInteger), but actual type (t/Vec Any)
;; in: m
;; Type Error (imdb.testassert:74) Type mismatch:
;; Expected: (t/Vec t/AnyInteger)
;; Actual: (t/Vec Any)
;; in: m
;; Type Error (imdb.testassert:74:1) Type mismatch:
;; Expected: (Fn [(t/Vec Any) -> (t/Vec t/AnyInteger)])
;; Actual: (Fn [(t/Vec Any) -> (t/Vec Any) :filters {:then (& (is (IPersistentVector Any) 0) (! (U nil false) 0)), :else (is (U nil false) 0)} :object {:id 0}])
;; in: (def testassert4 (fn* ([m] m)))
 
 
 
;; Again, the error is EXPECTED, since we never said what was in the vector.
(t/ann testassert5 [(t/Vec Any) -> (t/Vec t/AnyInteger)])
(defn testassert5 [m]
(assert (vector? m))
m
)
;; Type Error (imdb.testassert:74) Local binding m expected type (t/Vec t/AnyInteger), but actual type (t/Vec Any)
;; in: m
;; Type Error (imdb.testassert:74) Type mismatch:
;; Expected: (t/Vec t/AnyInteger)
;; Actual: (t/Vec Any)
;; in: (do (if (clojure.core/vector? m) nil (throw (new java.lang.AssertionError #))) m)
 
;; Type Error (imdb.testassert:74:1) Type mismatch:
;; Expected: (Fn [(t/Vec Any) -> (t/Vec t/AnyInteger)])
;; Actual: (Fn [(t/Vec Any) -> (t/Vec Any) :filters {:then (& (is (IPersistentVector Any) 0) (! (U nil false) 0)), :else (is (U nil false) 0)} :object {:id 0}])
;; in: (def testassert5 (fn* ([m] (do # m))))
 
 
 
 
 
;; 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))))
 
 
;; There seems to be some difficulty in merging the two assertions here.
(t/ann testassert7 [Any -> (t/Vec t/AnyInteger)])
(defn testassert7 [m] ; line 92
(assert (vector? m))
(assert (every? integer? m))
m)
;; Type Error (imdb.testassert:115) Local binding m expected type (t/Vec t/AnyInteger), but actual type (I (t/Vec Any) (t/Coll t/AnyInteger))
;; in: m
;; Type Error (imdb.testassert:115) Type mismatch:
;; Expected: (t/Vec t/AnyInteger)
;; Actual: (I (t/Vec 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:115:1) Type mismatch:
;; Expected: (Fn [Any -> (t/Vec t/AnyInteger)])
;; Actual: (Fn [Any -> (I (t/Vec Any) (t/Coll t/AnyInteger)) :filters {:then (! (U nil false) 0), :else (is (U nil false) 0)} :object {:id 0}])
;; in: (def testassert7 (fn* ([m] (do # # m))))
 
;; No error.
(t/ann testassert8 [Any -> (t/Vec Any)])
(defn testassert8 [m]
(assert (vector? m))
m)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.