typespec errors when using Erlang/Json encoder
Closed this issue · 1 comments
rwngallego commented
There's a type mismatch when using an encoder like Json or Erlang as the typespecs for set/add/replace are defined as binary()
instead of term()
. For example, in the unit tests:
assert {:ok} == Memcache.set(pid, "hello", ["list", 1])
Conflicts with the set/4 definition of binary
in the third parameter:
@doc """
Sets the key to value
Accepted options: `:cas`, `:ttl`
"""
@spec set(GenServer.server(), binary, binary, Keyword.t()) :: store_result
def set(server, key, value, opts \\ []) do
...
When calling dialyzer in an app that uses the Erlang encoder we get:
The call 'Elixir.Memcache':add
(_name@1 :: atom(),
_key@1 :: any(),
_data@1 ::
#{'ts' := 'nil' | integer(),
'ttl' := 'nil' | integer(),
'value' := _},
[{'ttl', integer()}, ...]) breaks the contract
('Elixir.GenServer':server(),
binary(),
binary(),
'Elixir.Keyword':t()) ->
store_result()
ananthakumaran commented
value type needs to be changed to term
. I guess other functions like set_cas
, multi_set
are also affected. Feel free to open a PR if you got time, otherwise, I will change it over the weekends.