当我尝试对实现未类型化协议的记录进行类型检查时,我得到了内部断言错误。最小示例
(defprotocol Lifecycle
(start [component]))
(stop [component]))
(t/ann-record TestRec [host :- String
port :- Integer
connection :- String])
(defrecord TestRec [host port connection]
Lifecycle
(start [component]
(let [connection (str "Host: " host ", port: " port)]
(assoc component :connection connection)))
(stop [component]
(.close connection)))
异常
java.lang.AssertionError: 断言失败: (every? r/Type? types)
at clojure.core.typed.type_ctors$In.doInvoke (type_ctors.clj:498)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.core$apply.invoke (core.clj:630)
clojure.core.typed.assoc_utils/fn (assoc_utils.clj:40)
clojure.core.typed.assoc_utils$fn__10$G__5__17.invoke (assoc_utils.clj:25)
clojure.core.typed.type_ctors$reduce_type_transform$fn__7210$iter__7211__7217$fn__7218.invoke (type_ctors.clj:2200)
clojure.lang.LazySeq.sval (LazySeq.java:40)
clojure.lang.LazySeq.seq (LazySeq.java:49)
clojure.lang.RT.seq (RT.java:507)
clojure.core/seq (core.clj:137)
clojure.core$some.invoke (core.clj:2569)
clojure.core.typed.type_ctors$union_or_nil.invoke (type_ctors.clj:2180)
clojure.core.typed.type_ctors$reduce_type_transform.doInvoke (type_ctors.clj:2195)
clojure.lang.RestFn.invoke (RestFn.java:494)
错误位置的调试打印
(:types new-i) => #{{:the-class clojure.core.typed.test.records3.TestRec,
:variances nil,
:poly? nil,
:fields
{host {:id java.lang.String},
port {:id java.lang.Integer},
connection {:id java.lang.String}},
:record? true}
{:variances nil,
:poly? nil,
:the-class clojure.core.typed.test.records3.Lifecycle}}
(map #(assoc-type-pairs % assoc-entry) (:types new-i)) =>
({:the-class clojure.core.typed.test.records3.TestRec,
:variances nil,
:poly? nil,
:fields
{host {:id java.lang.String},
port {:id java.lang.Integer},
connection {:id java.lang.String}},
:record? true}
nil)