You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I'm trying to shift from Jason to Jsonrs but I'm hitting some weird type issues. Dialyzer is going crazy overall. One example is the code below:
@spec deserialize(binary) :: {term, Metadata.t() | nil} | :error
def deserialize(message) do
case Jsonrs.decode!(message) do
%{"route" => route, "reference" => reference, "payload" => payload} ->
{payload, %Metadata{reference: reference, route: route}}
%{"d" => payload} ->
{payload, nil}
_ ->
:error
end
end
Dialyzer just give me this for the first case clause line
The pattern can never match the type.
Pattern:
%{
<<114, 101, 102, 101, 114, 101, 110, 99, 101>> => _reference,
<<114, 111, 117, 116, 101>> => _route,
<<112, 97, 121, 108, 111, 97, 100>> => _payload
}
Type:
binary()
I don't understand how decode!() can be expecting a binary() type as return for the dialyzer run?
I did look at Jsonrs typing and everything seems correct, specs says decode!() should return term so I'm in a bit of a loss...
Important to notice is that I had no dialyzer issues at all with Jason and the only thing that changed in that function was the decode function module name
The text was updated successfully, but these errors were encountered:
Thanks for reporting this. Looks like the typespec for nif_decode!/1 was wrong, and dialyzer was appropriately narrowing the return type of decode!/2 because of that.
0.1.4 should fix this. Let me know.
Hello, I'm trying to shift from Jason to Jsonrs but I'm hitting some weird type issues. Dialyzer is going crazy overall. One example is the code below:
Dialyzer just give me this for the first case clause line
I don't understand how
decode!()
can be expecting abinary()
type as return for the dialyzer run?I did look at Jsonrs typing and everything seems correct, specs says
decode!()
should returnterm
so I'm in a bit of a loss...Important to notice is that I had no dialyzer issues at all with Jason and the only thing that changed in that function was the decode function module name
The text was updated successfully, but these errors were encountered: