Fork me on GitHub
#core-typed
<
2022-06-08
>
J16:06:39

Hi! I don’t understand this error:

Type mismatch:
Expected: 	(t/U Short Byte Long BigInt BigInteger Integer)
Actual: 	(t/I t/AnyInteger t/Num)

in:
(:pokemon/level pokemon 1)
Occur with this code:
^::t/ignore
(def PokemonLevel
  [:and :int [:>= 1] [:<= 100]])

^::t/ignore
(def Pokemon
  [:map
   [:pokemon/name :string]
   [:pokemon/level {:optional true} PokemonLevel])

(m/=> get-pokemon-level [:=> [:cat Pokemon] PokemonLevel])
(defn get-pokemon-level [pokemon]
  (:pokemon/level pokemon 1))
I don’t understand why I get a different type.

ambrosebs21:06:02

Hi, looking. Looks strange..

ambrosebs21:06:18

Looks like Pokemon translates to a strange type

(t/HMap :mandatory {:pokemon/name t/Str} :optional {:pokemon/level (t/I t/AnyInteger t/Num)})

ambrosebs21:06:50

BTW I'm using metadata to debug this, might help you in the future:

(defn get-pokemon-level [pokemon]
  ^::t/dbg
  (:pokemon/level ^::t/dbg pokemon 1))
;=::t/dbg id=G__54475 (:pokemon/level pokemon 1)
;=::t/dbg id=G__54475 expected: (t/U Short Byte Long BigInt BigInteger Integer)
;= ::t/dbg id=G__54476 pokemon
;= ::t/dbg id=G__54476 result: [(t/HMap :mandatory {:pokemon/name t/Str} :optional {:pokemon/level (t/I t/AnyInteger t/Num)}) {:then tt, :else ff} {:id pokemon__#0}]
;=::t/dbg id=G__54475 result: (t/U Short Byte Long BigInt BigInteger Integer)

ambrosebs21:06:34

Minimal:

^::t/ignore
(def PokemonLevel
  [:and :int [:>= 1] [:<= 100]])

(m/=> get-pokemon-level [:=> [:cat [:maybe PokemonLevel]] PokemonLevel])
(defn get-pokemon-level [pokemon-level]
  (or pokemon-level 1))
Type mismatch:

Expected:       (t/U Short Byte Long BigInt BigInteger Integer)

Actual:         (t/I t/AnyInteger t/Num)


in:
or__5581__auto__

ambrosebs21:06:39

I don't think that's a real type mismatch, looks like a false negative.

ambrosebs23:06:24

@UHZPYLPU1 releasing 1.0.31 which should work around this problem. now [:and A B] will be simplified to A instead of (t/I A B).