fix(bpapi): Fix dialyzer warnings

This commit is contained in:
k32 2022-01-05 11:27:56 +01:00
parent 4f3f938d71
commit 9c675194f5
2 changed files with 19 additions and 21 deletions

View File

@ -72,21 +72,22 @@ check_compat(Dump1, Dump2) ->
check_api_immutability(#{release := Rel1, api := APIs1}, #{release := Rel2, api := APIs2}) check_api_immutability(#{release := Rel1, api := APIs1}, #{release := Rel2, api := APIs2})
when Rel2 >= Rel1 -> when Rel2 >= Rel1 ->
%% TODO: Handle API deprecation %% TODO: Handle API deprecation
maps:map(fun(Key = {API, Version}, Val) -> _ = maps:map(
case maps:get(Key, APIs2, undefined) of fun(Key = {API, Version}, Val) ->
Val -> case maps:get(Key, APIs2, undefined) of
ok; Val ->
undefined -> ok;
setnok(), undefined ->
?ERROR("API ~p v~p was removed in release ~p without being deprecated.", setnok(),
[API, Version, Rel2]); ?ERROR("API ~p v~p was removed in release ~p without being deprecated.",
_Val -> [API, Version, Rel2]);
setnok(), _Val ->
?ERROR("API ~p v~p was changed between ~p and ~p. Backplane API should be immutable.", setnok(),
[API, Version, Rel1, Rel2]) ?ERROR("API ~p v~p was changed between ~p and ~p. Backplane API should be immutable.",
end [API, Version, Rel1, Rel2])
end, end
APIs1), end,
APIs1),
ok; ok;
check_api_immutability(_, _) -> check_api_immutability(_, _) ->
ok. ok.

View File

@ -31,7 +31,7 @@
, module :: atom() , module :: atom()
, version :: non_neg_integer() | undefined , version :: non_neg_integer() | undefined
, targets = [] :: [{semantics(), emqx_bpapi:call(), emqx_bpapi:call()}] , targets = [] :: [{semantics(), emqx_bpapi:call(), emqx_bpapi:call()}]
, errors = [] :: [string()] , errors = [] :: list()
, file , file
}). }).
@ -120,7 +120,7 @@ analyze_exprs(Line, Name, Arity, Head, Exprs, S) ->
invalid_fun(Line, Name, Arity, S) invalid_fun(Line, Name, Arity, S)
end. end.
-spec extract_outer_args(erl_parse:abstract_form()) -> [atom()]. -spec extract_outer_args([erl_parse:abstract_form()]) -> [atom()].
extract_outer_args(Abs) -> extract_outer_args(Abs) ->
lists:map(fun({var, _, Var}) -> lists:map(fun({var, _, Var}) ->
Var; Var;
@ -131,8 +131,7 @@ extract_outer_args(Abs) ->
end, end,
Abs). Abs).
-spec extract_target_call(Abs, [Abs]) -> {semantics(), emqx_bpapi:call()} -spec extract_target_call(_AST, [_AST]) -> {semantics(), emqx_bpapi:call()}.
when Abs :: erl_parse:abstract_form().
extract_target_call(RPCBackend, OuterArgs) -> extract_target_call(RPCBackend, OuterArgs) ->
{Semantics, {atom, _, M}, {atom, _, F}, A} = extract_mfa(RPCBackend, OuterArgs), {Semantics, {atom, _, M}, {atom, _, F}, A} = extract_mfa(RPCBackend, OuterArgs),
{Semantics, {M, F, list_to_args(A)}}. {Semantics, {M, F, list_to_args(A)}}.
@ -140,8 +139,6 @@ extract_target_call(RPCBackend, OuterArgs) ->
-define(BACKEND(MOD, FUN), {remote, _, {atom, _, MOD}, {atom, _, FUN}}). -define(BACKEND(MOD, FUN), {remote, _, {atom, _, MOD}, {atom, _, FUN}}).
-define(IS_RPC(MOD), (MOD =:= erpc orelse MOD =:= rpc)). -define(IS_RPC(MOD), (MOD =:= erpc orelse MOD =:= rpc)).
-spec extract_mfa(Abs, #s{}) -> {call | cast, Abs, Abs, Abs}
when Abs :: erl_parse:abstract_form().
%% gen_rpc: %% gen_rpc:
extract_mfa(?BACKEND(gen_rpc, _), _) -> extract_mfa(?BACKEND(gen_rpc, _), _) ->
%% gen_rpc has an extremely messy API, thankfully it's fully wrapped %% gen_rpc has an extremely messy API, thankfully it's fully wrapped