Skip to content

Commit

Permalink
Fix several type specs
Browse files Browse the repository at this point in the history
The most significant one is the type spec of `gm_pids` in the amqqueue
records. I'm surprised Dialyzer didn't say anything about it. However it
was reported by Dialyzer in `v3.7.x`.

(cherry picked from commit 12d5f16)
  • Loading branch information
dumbbell committed Jun 26, 2020
1 parent 9c1b1bf commit ecaadf9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/amqqueue.erl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
%% implicit
%% update
%% as above
gm_pids = [] :: [{pid(), pid()} | pid()] | none | '_', %% transient
gm_pids = [] :: [{pid(), pid()}] | none | '_', %% transient
decorators :: [atom()] | none | undefined | '_', %% transient,
%% recalculated
%% as above
Expand All @@ -137,7 +137,7 @@
recoverable_slaves :: [atom()] | none,
policy :: binary() | none | undefined,
operator_policy :: binary() | none | undefined,
gm_pids :: [pid()] | none,
gm_pids :: [{pid(), pid()}] | none,
decorators :: [atom()] | none | undefined,
state :: atom() | none,
policy_version :: non_neg_integer(),
Expand Down Expand Up @@ -438,14 +438,14 @@ get_exclusive_owner(Queue) ->

% gm_pids

-spec get_gm_pids(amqqueue()) -> [{pid(), pid()} | pid()] | none.
-spec get_gm_pids(amqqueue()) -> [{pid(), pid()}] | none.

get_gm_pids(#amqqueue{gm_pids = GMPids}) ->
GMPids;
get_gm_pids(Queue) ->
amqqueue_v1:get_gm_pids(Queue).

-spec set_gm_pids(amqqueue(), [{pid(), pid()} | pid()] | none) -> amqqueue().
-spec set_gm_pids(amqqueue(), [{pid(), pid()}] | none) -> amqqueue().

set_gm_pids(#amqqueue{} = Queue, GMPids) ->
Queue#amqqueue{gm_pids = GMPids};
Expand Down
12 changes: 5 additions & 7 deletions src/amqqueue_v1.erl
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@
qnode/1,
macros/0]).

-dialyzer({nowarn_function, is_quorum/1}).

-define(record_version, ?MODULE).
-define(is_backwards_compat_classic(T),
(T =:= classic orelse T =:= ?amqqueue_v1_type)).
Expand All @@ -113,7 +111,7 @@
%% implicit
%% update
%% as above
gm_pids = [] :: [pid()] | none | '_', %% transient
gm_pids = [] :: [{pid(), pid()}] | none | '_', %% transient
decorators :: [atom()] | none | undefined | '_', %% transient,
%% recalculated
%% as above
Expand All @@ -137,7 +135,7 @@
recoverable_slaves :: [atom()] | none,
policy :: binary() | none | undefined,
operator_policy :: binary() | none | undefined,
gm_pids :: [pid()] | none,
gm_pids :: [{pid(), pid()}] | none,
decorators :: [atom()] | none | undefined,
state :: atom() | none,
policy_version :: non_neg_integer(),
Expand Down Expand Up @@ -289,7 +287,7 @@ new_with_version(?record_version,
rabbit_framing:amqp_table(),
rabbit_types:vhost() | undefined,
map(),
?amqqueue_v1_type) -> amqqueue().
?amqqueue_v1_type | classic) -> amqqueue().

new_with_version(?record_version,
#resource{kind = queue} = Name,
Expand Down Expand Up @@ -367,11 +365,11 @@ get_exclusive_owner(#amqqueue{exclusive_owner = Owner}) -> Owner.

% gm_pids

-spec get_gm_pids(amqqueue()) -> [{pid(), pid()} | pid()] | none.
-spec get_gm_pids(amqqueue()) -> [{pid(), pid()}] | none.

get_gm_pids(#amqqueue{gm_pids = GMPids}) -> GMPids.

-spec set_gm_pids(amqqueue(), [{pid(), pid()} | pid()] | none) -> amqqueue().
-spec set_gm_pids(amqqueue(), [{pid(), pid()}] | none) -> amqqueue().

set_gm_pids(#amqqueue{} = Queue, GMPids) ->
Queue#amqqueue{gm_pids = GMPids}.
Expand Down
4 changes: 2 additions & 2 deletions src/rabbit_amqqueue.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1428,12 +1428,12 @@ stat(Q) when ?amqqueue_is_quorum(Q) -> rabbit_quorum_queue:stat(Q);
stat(Q) -> delegate:invoke(amqqueue:get_pid(Q), {gen_server2, call, [stat, infinity]}).

-spec pid_of(amqqueue:amqqueue()) ->
{'ok', pid()} | rabbit_types:error('not_found').
pid().

pid_of(Q) -> amqqueue:get_pid(Q).

-spec pid_of(rabbit_types:vhost(), rabbit_misc:resource_name()) ->
{'ok', pid()} | rabbit_types:error('not_found').
pid() | rabbit_types:error('not_found').

pid_of(VHost, QueueName) ->
case lookup(rabbit_misc:r(VHost, queue, QueueName)) of
Expand Down

0 comments on commit ecaadf9

Please sign in to comment.