Skip to content

Commit 414b75c

Browse files
Merge pull request #1875 from rabbitmq/fix-more-dialyzer
Fix more dialyzer warnings
2 parents cea04c5 + 3efa9d8 commit 414b75c

14 files changed

+37
-49
lines changed

src/amqqueue.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
%% implicit
108108
%% update
109109
%% as above
110-
gm_pids = [] :: [pid()] | none | '_', %% transient
110+
gm_pids = [] :: [{pid(), pid()} | pid()] | none | '_', %% transient
111111
decorators :: [atom()] | none | undefined | '_', %% transient,
112112
%% recalculated
113113
%% as above
@@ -359,14 +359,14 @@ get_exclusive_owner(#amqqueue{exclusive_owner = Owner}) ->
359359
get_exclusive_owner(Queue) ->
360360
amqqueue_v1:get_exclusive_owner(Queue).
361361

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

364364
get_gm_pids(#amqqueue{gm_pids = GMPids}) ->
365365
GMPids;
366366
get_gm_pids(Queue) ->
367367
amqqueue_v1:get_gm_pids(Queue).
368368

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

371371
set_gm_pids(#amqqueue{} = Queue, GMPids) ->
372372
Queue#amqqueue{gm_pids = GMPids};

src/lager_exchange_backend.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ handle_log_event({log, Message},
165165
headers = Headers},
166166
Body = rabbit_data_coercion:to_binary(Formatter:format(Message, FormatConfig)),
167167
case rabbit_basic:publish(LogExch, RoutingKey, AmqpMsg, Body) of
168-
{ok, _DeliveredQPids} -> ok;
169-
{error, not_found} -> ok
168+
ok -> ok;
169+
{error, not_found} -> ok
170170
end,
171171
{ok, State};
172172
false ->

src/lqueue.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ is_empty(_) -> false.
5252

5353
in(V, {L, Q}) -> {L+1, ?QUEUE:in(V, Q)}.
5454

55-
-spec in_r(value(), ?MODULE()) -> ?MODULE().
55+
-spec in_r(value(), ?MODULE(T)) -> ?MODULE(T).
5656

5757
in_r(V, {L, Q}) -> {L+1, ?QUEUE:in_r(V, Q)}.
5858

59-
-spec out(?MODULE(T)) -> {result(T), ?MODULE()}.
59+
-spec out(?MODULE(T)) -> {result(T), ?MODULE(T)}.
6060

6161
out({0, _Q} = Q) -> {empty, Q};
6262
out({L, Q}) -> {Result, Q1} = ?QUEUE:out(Q),
6363
{Result, {L-1, Q1}}.
6464

65-
-spec out_r(?MODULE(T)) -> {result(T), ?MODULE()}.
65+
-spec out_r(?MODULE(T)) -> {result(T), ?MODULE(T)}.
6666

6767
out_r({0, _Q} = Q) -> {empty, Q};
6868
out_r({L, Q}) -> {Result, Q1} = ?QUEUE:out_r(Q),

src/rabbit_amqqueue.erl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
-type qpids() :: [pid()].
7878
-type qlen() :: rabbit_types:ok(non_neg_integer()).
7979
-type qfun(A) :: fun ((amqqueue:amqqueue()) -> A | no_return()).
80-
-type qmsg() :: {name(), pid(), msg_id(), boolean(), rabbit_types:message()}.
80+
-type qmsg() :: {name(), pid() | {atom(), pid()}, msg_id(), boolean(), rabbit_types:message()}.
8181
-type msg_id() :: non_neg_integer().
8282
-type ok_or_errors() ::
8383
'ok' | {'error', [{'error' | 'exit' | 'throw', any()}]}.
@@ -237,7 +237,9 @@ recover_durable_queues(QueuesAndRecoveryTerms) ->
237237
rabbit_framing:amqp_table(),
238238
rabbit_types:maybe(pid()),
239239
rabbit_types:username()) ->
240-
{'new' | 'existing' | 'absent' | 'owner_died', amqqueue:amqqueue()} |
240+
{'new' | 'existing' | 'owner_died', amqqueue:amqqueue()} |
241+
{'new', amqqueue:amqqueue(), rabbit_fifo_client:state()} |
242+
{'absent', amqqueue:amqqueue(), absent_reason()} |
241243
rabbit_types:channel_exit().
242244

243245
declare(QueueName, Durable, AutoDelete, Args, Owner, ActingUser) ->
@@ -1031,6 +1033,7 @@ notify_policy_changed(Q) when ?amqqueue_is_quorum(Q) ->
10311033

10321034
-spec consumers(amqqueue:amqqueue()) ->
10331035
[{pid(), rabbit_types:ctag(), boolean(), non_neg_integer(),
1036+
boolean(), atom(),
10341037
rabbit_framing:amqp_table(), rabbit_types:username()}].
10351038

10361039
consumers(Q) when ?amqqueue_is_classic(Q) ->

src/rabbit_amqqueue_process.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,10 +1592,10 @@ handle_cast({force_event_refresh, Ref},
15921592
[emit_consumer_created(
15931593
Ch, CTag, false, AckRequired, QName, Prefetch,
15941594
Args, Ref, ActingUser) ||
1595-
{Ch, CTag, AckRequired, Prefetch, Args, ActingUser}
1595+
{Ch, CTag, AckRequired, Prefetch, _, _, Args, ActingUser}
15961596
<- AllConsumers];
15971597
{Ch, CTag} ->
1598-
[{Ch, CTag, AckRequired, Prefetch, Args, ActingUser}] = AllConsumers,
1598+
[{Ch, CTag, AckRequired, Prefetch, _, _, Args, ActingUser}] = AllConsumers,
15991599
emit_consumer_created(
16001600
Ch, CTag, true, AckRequired, QName, Prefetch, Args, Ref, ActingUser)
16011601
end,

src/rabbit_backing_queue.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@
259259

260260
-callback set_queue_mode(queue_mode(), state()) -> state().
261261

262-
-callback zip_msgs_and_acks(delivered_publish(),
262+
-callback zip_msgs_and_acks([delivered_publish()],
263263
[ack()], Acc, state())
264264
-> Acc.
265265

src/rabbit_basic.erl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
-type properties_input() ::
3131
rabbit_framing:amqp_property_record() | [{atom(), any()}].
3232
-type publish_result() ::
33-
{ok, [pid()]} | rabbit_types:error('not_found').
33+
ok | rabbit_types:error('not_found').
3434
-type header() :: any().
3535
-type headers() :: rabbit_framing:amqp_table() | 'undefined'.
3636

@@ -76,8 +76,7 @@ publish(Delivery = #delivery{
7676

7777
publish(X, Delivery) ->
7878
Qs = rabbit_amqqueue:lookup(rabbit_exchange:route(X, Delivery)),
79-
DeliveredQPids = rabbit_amqqueue:deliver(Qs, Delivery),
80-
{ok, DeliveredQPids}.
79+
rabbit_amqqueue:deliver(Qs, Delivery).
8180

8281
-spec delivery
8382
(boolean(), boolean(), rabbit_types:message(), undefined | integer()) ->

src/rabbit_channel.erl

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -869,9 +869,7 @@ send(Command, #ch{writer_pid = WriterPid}) ->
869869
ok = rabbit_writer:send_command(WriterPid, Command).
870870

871871
format_soft_error(#amqp_error{name = N, explanation = E, method = M}) ->
872-
io_lib:format("operation ~s caused a channel exception ~s: ~ts", [M, N, E]);
873-
format_soft_error(Reason) ->
874-
Reason.
872+
io_lib:format("operation ~s caused a channel exception ~s: ~ts", [M, N, E]).
875873

876874
handle_exception(Reason, State = #ch{protocol = Protocol,
877875
channel = Channel,
@@ -2145,19 +2143,14 @@ send_confirms_and_nacks(State) ->
21452143

21462144
send_nacks([], _, State) ->
21472145
State;
2148-
send_nacks(_Rs, _, State = #ch{state = closing,
2149-
tx = none}) -> %% optimisation
2146+
send_nacks(_Rs, _, State = #ch{state = closing}) -> %% optimisation
21502147
State;
2151-
send_nacks(Rs, Cs, State = #ch{tx = none}) ->
2148+
send_nacks(Rs, Cs, State) ->
21522149
coalesce_and_send(Rs, Cs,
21532150
fun(MsgSeqNo, Multiple) ->
21542151
#'basic.nack'{delivery_tag = MsgSeqNo,
21552152
multiple = Multiple}
2156-
end, State);
2157-
send_nacks(_MXs, _, State = #ch{state = closing}) -> %% optimisation
2158-
State#ch{tx = failed};
2159-
send_nacks(_, _, State) ->
2160-
maybe_complete_tx(State#ch{tx = failed}).
2153+
end, State).
21612154

21622155
send_confirms([], _, State) ->
21632156
State;

src/rabbit_ff_registry.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ always_return_true() ->
161161
%% That's why this function makes a call which we know the result,
162162
%% but not Dialyzer, to "create" that hard-coded `true` return
163163
%% value.
164-
rand:uniform(1) > 0.
164+
erlang:get({?MODULE, always_undefined}) =:= undefined.
165165

166166
always_return_false() ->
167167
not always_return_true().

src/rabbit_fifo_client.erl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,8 @@ purge(Node) ->
407407
stat(Leader) ->
408408
%% short timeout as we don't want to spend too long if it is going to
409409
%% fail anyway
410-
case ra:local_query(Leader, fun rabbit_fifo:query_stat/1, 250) of
411-
{ok, {_, {R, C}}, _} ->
412-
{ok, R, C};
413-
Err ->
414-
Err
415-
end.
410+
{ok, {_, {R, C}}, _} = ra:local_query(Leader, fun rabbit_fifo:query_stat/1, 250),
411+
{ok, R, C}.
416412

417413
%% @doc returns the cluster name
418414
-spec cluster_name(state()) -> cluster_name().

src/rabbit_networking.erl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@
7070
-type protocol() :: atom().
7171
-type label() :: string().
7272

73+
%% @todo Remove once Dialyzer only runs on Erlang/OTP 21.3 or above.
74+
-dialyzer({nowarn_function, boot/0}).
75+
-dialyzer({nowarn_function, boot_listeners/3}).
76+
-dialyzer({nowarn_function, record_distribution_listener/0}).
77+
7378
-spec boot() -> 'ok'.
7479

7580
boot() ->
@@ -285,9 +290,6 @@ tcp_listener_stopped(Protocol, Opts, IPAddress, Port) ->
285290
port = Port,
286291
opts = Opts}).
287292

288-
%% @todo Remove once Dialyzer only runs on Erlang/OTP 21.3 or above.
289-
-dialyzer({nowarn_function, record_distribution_listener/0}).
290-
291293
record_distribution_listener() ->
292294
{Name, Host} = rabbit_nodes:parts(node()),
293295
{port, Port, _Version} = erl_epmd:port_please(Name, Host),

src/rabbit_queue_consumers.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ inactive(#state{consumers = Consumers}) ->
8686
priority_queue:is_empty(Consumers).
8787

8888
-spec all(state()) -> [{ch(), rabbit_types:ctag(), boolean(),
89-
non_neg_integer(), rabbit_framing:amqp_table(),
90-
rabbit_types:username()}].
89+
non_neg_integer(), boolean(), atom(),
90+
rabbit_framing:amqp_table(), rabbit_types:username()}].
9191

9292
all(State) ->
9393
all(State, none, false).

src/rabbit_quorum_queue.erl

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ init_state({Name, _}, QName = #resource{}) ->
8585
fun() -> credit_flow:unblock(Name), ok end).
8686

8787
-spec handle_event({'ra_event', amqqueue:ra_server_id(), any()}, rabbit_fifo_client:state()) ->
88-
{'internal', Correlators :: [term()], rabbit_fifo_client:state()} |
89-
{rabbit_fifo:client_msg(), rabbit_fifo_client:state()}.
88+
{internal, Correlators :: [term()], rabbit_fifo_client:actions(), rabbit_fifo_client:state()} |
89+
{rabbit_fifo:client_msg(), rabbit_fifo_client:state()} | eol.
9090

9191
handle_event({ra_event, From, Evt}, QState) ->
9292
rabbit_fifo_client:handle_ra_event(From, Evt, QState).
@@ -560,12 +560,7 @@ info(Q, Items) ->
560560
stat(Q) when ?is_amqqueue(Q) ->
561561
Leader = amqqueue:get_pid(Q),
562562
try
563-
case rabbit_fifo_client:stat(Leader) of
564-
{ok, _, _} = Stat ->
565-
Stat;
566-
_ ->
567-
{ok, 0, 0}
568-
end
563+
{ok, _, _} = rabbit_fifo_client:stat(Leader)
569564
catch
570565
_:_ ->
571566
%% Leader is not available, cluster might be in minority
@@ -921,7 +916,7 @@ format(Q) when ?is_amqqueue(Q) ->
921916
is_process_alive(Name, Node) ->
922917
erlang:is_pid(rpc:call(Node, erlang, whereis, [Name], ?RPC_TIMEOUT)).
923918

924-
-spec quorum_messages(atom()) -> non_neg_integer().
919+
-spec quorum_messages(rabbit_amqqueue:name()) -> non_neg_integer().
925920

926921
quorum_messages(QName) ->
927922
case ets:lookup(queue_coarse_metrics, QName) of

src/rabbit_trace.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ trace(#exchange{name = Name}, #basic_message{exchange_name = Name},
106106
ok;
107107
trace(X, Msg = #basic_message{content = #content{payload_fragments_rev = PFR}},
108108
RKPrefix, RKSuffix, Extra) ->
109-
{ok, _} = rabbit_basic:publish(
109+
ok = rabbit_basic:publish(
110110
X, <<RKPrefix/binary, ".", RKSuffix/binary>>,
111111
#'P_basic'{headers = msg_to_table(Msg) ++ Extra}, PFR),
112112
ok.

0 commit comments

Comments
 (0)