Skip to content

Commit 248314c

Browse files
committed
alias two -opaque types with plain -type to address dialyzer issue
In riak_kv_gcounter.erl, redeclare gcounter() with -type (as gcounter_()) for local use, to make dialyzer accept the specs for merge/2,3. Apparently, dialyzer only accepts standalone variables for args having an opaque type spec, whereas we call those functions with an expressly constructed lists. Same with pncounter() in riak_kv_pncounter.erl.
1 parent d71634e commit 248314c

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

dialyzer.ignore-warnings

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
riak_core_pb.erl
2-
riak_kv_gcounter.erl:86: Function merge/2 has no local return
3-
riak_kv_gcounter.erl:87: The call riak_kv_gcounter:merge(GCnt1::any(),GCnt2::any(),[]) does not have an opaque term of type riak_kv_gcounter:gcounter() as 3rd argument
4-
riak_kv_gcounter.erl:100: The call riak_kv_gcounter:merge(Rest::any(),RestOfClock2::[tuple()],[{_,_},...]) does not have opaque terms as 2nd and 3rd arguments
5-
riak_kv_gcounter.erl:102: The call riak_kv_gcounter:merge(Rest::any(),Clock2::[tuple()],[{_,_},...]) does not have opaque terms as 2nd and 3rd arguments
62
riak_kv_pipe_index.erl:164: Function queue_existing_pipe/4 has no local return
73
riak_kv_pipe_listkeys.erl:159: Function queue_existing_pipe/3 has no local return
8-
riak_kv_pncounter.erl:101: Function merge/2 has no local return
94
riak_kv_put_fsm.erl:822: The pattern <[COP = {'counter_op', _Amt} | T], Acc> can never match the type <[{'details' | 'dw' | 'n_val' | 'pw' | 'retry_put_coordinator_failure' | 'returnbody' | 'sloppy_quorum' | 'timeout' | 'update_last_modified' | 'w','false' | 'infinity' | 'true' | [any()] | non_neg_integer()},...],[{'details' | 'dw' | 'n_val' | 'pw' | 'retry_put_coordinator_failure' | 'returnbody' | 'sloppy_quorum' | 'timeout' | 'update_last_modified' | 'w','false' | 'infinity' | 'true' | [any()] | non_neg_integer()}]>
105
riak_kv_put_fsm.erl:825: The pattern <[COP = {'crdt_op', _Op} | T], Acc> can never match the type <[{'details' | 'dw' | 'n_val' | 'pw' | 'retry_put_coordinator_failure' | 'returnbody' | 'sloppy_quorum' | 'timeout' | 'update_last_modified' | 'w','false' | 'infinity' | 'true' | [any()] | non_neg_integer()},...],[{'details' | 'dw' | 'n_val' | 'pw' | 'retry_put_coordinator_failure' | 'returnbody' | 'sloppy_quorum' | 'timeout' | 'update_last_modified' | 'w','false' | 'infinity' | 'true' | [any()] | non_neg_integer()}]>
116
riak_kv_util.erl:304: The pattern 'error' can never match the type 'ok' | 'undefined'

src/riak_kv_gcounter.erl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
-export_type([gcounter/0, gcounter_op/0]).
5353

5454
-opaque gcounter() :: [entry()].
55+
%% Redeclaring gcounter() with -type for local use, to make dialyzer
56+
%% accept specs for merge/2,3. Apparently, dialyzer only accepts
57+
%% standalone variables for args having an opaque type spec, whereas
58+
%% we call those functions with an expressly constructed lists.
59+
-type gcounter_() :: [entry()].
5560

5661
-type entry() :: {Actor::term(), Count::pos_integer()}.
5762
-type gcounter_op() :: increment | {increment, pos_integer()}.
@@ -82,12 +87,12 @@ update({increment, Amount}, Actor, GCnt) when is_integer(Amount), Amount > 0 ->
8287

8388
%% @doc Merge two `gcounter()'s to a single `gcounter()'. This is the Least Upper Bound
8489
%% function described in the literature.
85-
-spec merge(gcounter(), gcounter()) -> gcounter().
90+
-spec merge(gcounter_(), gcounter_()) -> gcounter_().
8691
merge(GCnt1, GCnt2) ->
8792
merge(GCnt1, GCnt2, []).
8893

8994
%% @private merge two counters.
90-
-spec merge(gcounter(), gcounter(), gcounter()) -> gcounter().
95+
-spec merge(gcounter_(), gcounter_(), gcounter_()) -> gcounter_().
9196
merge([], [], Acc) ->
9297
lists:reverse(Acc);
9398
merge(LeftOver, [], Acc) ->

src/riak_kv_pncounter.erl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@
5050
-export_type([pncounter/0, pncounter_op/0]).
5151

5252
-opaque pncounter() :: {riak_kv_gcounter:gcounter(), riak_kv_gcounter:gcounter()}.
53+
%% Redeclaring pncounter() with -type to please dialyzer, which would
54+
%% otherwise issue the following warning:
55+
%% riak_kv_pncounter.erl:100: Invalid type specification for
56+
%% function riak_kv_pncounter:merge/2. The success typing is
57+
%% ({[{_,pos_integer()}],[{_,pos_integer()}]},{[{_,pos_integer()}],[{_,pos_integer()}]})
58+
%% -> {[{_,pos_integer()}],[{_,pos_integer()}]}
59+
%% Apparently, dialyzer only accepts plain variables for args having
60+
%% an opaque type spec.
61+
-type pncounter_() :: {riak_kv_gcounter:gcounter(), riak_kv_gcounter:gcounter()}.
5362
-type pncounter_op() :: riak_kv_gcounter:gcounter_op() | decrement_op().
5463
-type decrement_op() :: decrement | {decrement, pos_integer()}.
5564

@@ -97,7 +106,7 @@ update({decrement, By}, Actor, {Incr, Decr}) when is_integer(By), By > 0 ->
97106

98107
%% @doc Merge two `pncounter()'s to a single `pncounter()'. This is the Least Upper Bound
99108
%% function described in the literature.
100-
-spec merge(pncounter(), pncounter()) -> pncounter().
109+
-spec merge(pncounter_(), pncounter_()) -> pncounter_().
101110
merge({Incr1, Decr1}, {Incr2, Decr2}) ->
102111
MergedIncr = riak_kv_gcounter:merge(Incr1, Incr2),
103112
MergedDecr = riak_kv_gcounter:merge(Decr1, Decr2),

0 commit comments

Comments
 (0)