HMap alias oddities with :optional

29 views
Skip to first unread message

Peter Fraenkel

unread,
Oct 1, 2013, 12:34:45 PM10/1/13
to clojure-c...@googlegroups.com
This
(t/def-alias TA  (HMap :optional {:d Any}))
(t/ann a [TA -> TA])
(defn a [m] (assoc m :d "foo"))
results in
Type Error (imdb.test:83:13) Cannot assoc args `[(Value :d) {:then tt, :else ff}] [(Value "foo") {:then tt, :else ff}]` on imdb.test/TA
in: (clojure.core/assoc m :d foo)

Nearly any variation seems to be OK.  Mandatory instead of optional:
(t/def-alias TB  (HMap :mandatory {:d Any}))
(t/ann b [TB -> TB])
(defn b [m] (assoc m :d "foo"))
Inline instead of alias: 
(t/ann c [(HMap :optional {:d Any}) -> (HMap :optional {:d Any})])
(defn c [m] (assoc m :d "foo"))
Map instead of HMap:
(t/def-alias TD (t/Map Any Any))
(t/ann d [TD -> TD])
(defn d [m] (assoc m :d "foo"))
Totally unqualified HMap: 
(t/def-alias TE (HMap))
(t/ann e [TE -> TE])
(defn e [m] (assoc m :d "foo"))
 

Ambrose Bonnaire-Sergeant

unread,
Oct 1, 2013, 5:48:18 PM10/1/13
to core.typed, Chris Spencer
Thanks Peter.

Chris, can you see what's wrong here?

Thanks,
Ambrose

Chris Spencer

unread,
Oct 2, 2013, 4:50:07 AM10/2/13
to clojure-c...@googlegroups.com, Chris Spencer
Ah, just not quite enough type resolution going on.

check.clj#2085 should be:
(map c/fully-resolve-type (type-into-vector (c/fully-resolve-type t)))
Reply all
Reply to author
Forward
0 new messages