I would expect the following code to typecheck, but I'm stumped on some errors. Am I missing something? Or should I create a bug report on JIRA?
Code:
(ns demo
(:require [clojure.core.typed :as t]))
(t/defprotocol Connectable
(add-connection [db, connection :- java.sql.Connection]
:- (t/HMap :mandatory {:connection java.sql.Connection}
:optional {:connection-string String
:level t/AnyInteger
:legacy Boolean}))
(get-level [db]
:- t/AnyInteger))
(extend-protocol Connectable
String
(add-connection [s connection] {:connection connection :level 0 :connection-string s})
(get-level [_] 0)
clojure.lang.Associative
(add-connection [m connection] (assoc m :connection connection))
(get-level [m] (or (:level m) 0))
nil
(add-connection [_ connection] {:connection connection :level 0 :legacy true})
(get-level [_] 0))
Output of (t/check-ns 'demo):
Type Error (demo.clj:19:34) Cannot assoc args `[(t/Val :connection) {:then tt, :else ff}] [java.sql.Connection {:then tt, :else ff} {:id connection__#0}]` on (Associative t/Any t/Any)
in: (assoc m :connection connection)
Type Error (demo.clj:20:18) Type mismatch:
Expected: t/AnyInteger
Actual: t/Any
in: or__4238__auto__
ExceptionInfo Type Checker: Found 2 errors clojure.core/ex-info (core.clj:4593)