Skip to content

Commit

Permalink
Make dialyzer happy by ensuring rabbit_data_coercion:to_list/1 can …
Browse files Browse the repository at this point in the history
…handle `inet:ip_address()`
  • Loading branch information
lukebakken committed Apr 24, 2023
1 parent 667db16 commit 6c39f68
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions deps/rabbit_common/src/rabbit_data_coercion.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,27 @@ to_binary(Val) when is_integer(Val) -> integer_to_binary(Val);
to_binary(Val) when is_function(Val) -> list_to_binary(io_lib:format("~w", [Val]));
to_binary(Val) -> Val.

-spec to_list(Val :: integer() | list() | binary() | atom() | map()) -> list().
-spec to_list(Val :: integer() | list() | binary() | atom() | map() | inet:ip_address()) -> list().
to_list(Val) when is_list(Val) -> Val;
to_list(Val) when is_map(Val) -> maps:to_list(Val);
to_list(Val) when is_atom(Val) -> atom_to_list(Val);
to_list(Val) when is_binary(Val) -> binary_to_list(Val);
to_list(Val) when is_integer(Val) -> integer_to_list(Val).
to_list(Val) when is_integer(Val) -> integer_to_list(Val);
to_list({V0, V1, V2, V3}=Val) when (is_integer(V0) andalso (V0 >=0 andalso V0 =< 255)) andalso
(is_integer(V1) andalso (V1 >=0 andalso V1 =< 255)) andalso
(is_integer(V2) andalso (V2 >=0 andalso V2 =< 255)) andalso
(is_integer(V3) andalso (V3 >=0 andalso V3 =< 255)) ->
io_lib:format("~w", [Val]);
to_list({V0, V1, V2, V3, V4, V5, V6, V7}=Val)
when (is_integer(V0) andalso (V0 >=0 andalso V0 =< 65535)) andalso
(is_integer(V1) andalso (V1 >=0 andalso V1 =< 65535)) andalso
(is_integer(V2) andalso (V2 >=0 andalso V2 =< 65535)) andalso
(is_integer(V3) andalso (V3 >=0 andalso V3 =< 65535)) andalso
(is_integer(V4) andalso (V4 >=0 andalso V4 =< 65535)) andalso
(is_integer(V5) andalso (V5 >=0 andalso V5 =< 65535)) andalso
(is_integer(V6) andalso (V6 >=0 andalso V6 =< 65535)) andalso
(is_integer(V7) andalso (V7 >=0 andalso V7 =< 65535)) ->
io_lib:format("~w", [Val]).

-spec to_atom(Val :: atom() | list() | binary()) -> atom().
to_atom(Val) when is_atom(Val) -> Val;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ parse_peeraddr(unknown) ->
parse_peeraddr(PeerAddr) ->
handle_inet_ntoa_peeraddr(inet:ntoa(PeerAddr), PeerAddr).

-spec handle_inet_ntoa_peeraddr({'error', term()} | string(), inet:ip_address()) -> string().
-spec handle_inet_ntoa_peeraddr({'error', term()} | string(), inet:ip_address() | unknown) -> string().
handle_inet_ntoa_peeraddr({error, einval}, PeerAddr) ->
rabbit_data_coercion:to_list(PeerAddr);
handle_inet_ntoa_peeraddr(PeerAddrStr, _PeerAddr0) ->
Expand Down

0 comments on commit 6c39f68

Please sign in to comment.