Skip to content

Commit eeefdd6

Browse files
authored
Merge pull request #341 from rabbitmq/fix-dialyzer-warnings
Fix Dialyzer warnings
2 parents 5d14401 + 8ecac17 commit eeefdd6

File tree

5 files changed

+70
-26
lines changed

5 files changed

+70
-26
lines changed

src/khepri_import_export.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ do_export(State, PathPattern, Module, ModulePriv) ->
239239
Tree, PathPattern, TreeOptions, Fun, ModulePriv1),
240240
case Ret1 of
241241
{ok, Tree1, _AppliedChanges, FinalModulePriv} ->
242-
?assertEqual(Tree, Tree1),
242+
khepri_tree:assert_equal(Tree, Tree1),
243243
commit_write(Module, FinalModulePriv);
244244
{error, _} = Error ->
245245
Error

src/khepri_machine.erl

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,10 @@ readonly_transaction(StoreId, Fun, Args, Options)
520520
%% It is a read-only transaction, therefore we assert that
521521
%% the state is unchanged and that there are no side
522522
%% effects.
523-
{State, Ret, []} = khepri_tx_adv:run(
524-
State, Fun, Args, false,
525-
Meta),
523+
{State1, Ret, []} = khepri_tx_adv:run(
524+
State, Fun, Args, false,
525+
Meta),
526+
assert_equal(State, State1),
526527
Ret
527528
end,
528529
case process_query(StoreId, Query, Options) of
@@ -537,9 +538,10 @@ readonly_transaction(StoreId, PathPattern, Args, Options)
537538
%% It is a read-only transaction, therefore we assert that
538539
%% the state is unchanged and that there are no side
539540
%% effects.
540-
{State, Ret, []} = locate_sproc_and_execute_tx(
541-
State, PathPattern, Args, false,
542-
Meta),
541+
{State1, Ret, []} = locate_sproc_and_execute_tx(
542+
State, PathPattern, Args, false,
543+
Meta),
544+
assert_equal(State, State1),
543545
Ret
544546
end,
545547
case process_query(StoreId, Query, Options) of
@@ -2634,6 +2636,16 @@ get_store_id(State) ->
26342636
#config{store_id = StoreId} = get_config(State),
26352637
StoreId.
26362638

2639+
-spec assert_equal(State1, State2) -> ok when
2640+
State1 :: khepri_machine:state(),
2641+
State2 :: khepri_machine:state().
2642+
2643+
assert_equal(#khepri_machine{} = State1, #khepri_machine{} = State2) ->
2644+
?assertEqual(State1, State2),
2645+
ok;
2646+
assert_equal(State1, State2) ->
2647+
khepri_machine_v0:assert_equal(State1, State2).
2648+
26372649
-ifdef(TEST).
26382650
-spec make_virgin_state(Params) -> State when
26392651
Params :: khepri_machine:machine_init_args(),

src/khepri_machine_v0.erl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
-module(khepri_machine_v0).
1515

16+
-include_lib("stdlib/include/assert.hrl").
17+
1618
-include("src/khepri_machine.hrl").
1719

1820
-export([init/1]).
@@ -25,6 +27,7 @@
2527
get_emitted_triggers/1, set_emitted_triggers/2,
2628
get_projections/1, set_projections/2,
2729
get_metrics/1, set_metrics/2,
30+
assert_equal/2,
2831
state_to_list/1]).
2932

3033
-record(khepri_machine,
@@ -88,7 +91,7 @@ get_config(#khepri_machine{config = Config}) ->
8891

8992
-spec get_tree(State) -> Tree when
9093
State :: khepri_machine_v0:state(),
91-
Tree :: khepri_tree:tree().
94+
Tree :: khepri_tree:tree_v0().
9295
%% @doc Returns the tree from the given state.
9396
%%
9497
%% @private
@@ -191,6 +194,7 @@ get_metrics(#khepri_machine{metrics = Metrics}) ->
191194
set_metrics(#khepri_machine{} = State, Metrics) ->
192195
State#khepri_machine{metrics = Metrics}.
193196

197+
194198
-spec state_to_list(State) -> Fields when
195199
State :: khepri_machine_v0:state(),
196200
Fields :: [any()].
@@ -200,3 +204,11 @@ set_metrics(#khepri_machine{} = State, Metrics) ->
200204

201205
state_to_list(#khepri_machine{} = State) ->
202206
tuple_to_list(State).
207+
208+
-spec assert_equal(State1, State2) -> ok when
209+
State1 :: khepri_machine:state(),
210+
State2 :: khepri_machine:state().
211+
212+
assert_equal(#khepri_machine{} = State1, #khepri_machine{} = State2) ->
213+
?assertEqual(State1, State2),
214+
ok.

src/khepri_path.erl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
%% A node name.
7474

7575
-type component() :: node_id() |
76-
?KHEPRI_ROOT_NODE |
77-
?THIS_KHEPRI_NODE |
78-
?PARENT_KHEPRI_NODE.
76+
?KHEPRI_ROOT_NODE |
77+
?THIS_KHEPRI_NODE |
78+
?PARENT_KHEPRI_NODE.
7979
%% Component name in a path to a node.
8080

8181
-type native_path() :: [component()].
@@ -625,8 +625,9 @@ abspath([_ | _] = RelativePath, BasePath) ->
625625
abspath([] = PathToRoot, _) ->
626626
PathToRoot.
627627

628-
-spec realpath(Path) -> Path when
629-
Path :: native_pattern().
628+
-spec realpath(Path) -> NewPath when
629+
Path :: native_pattern(),
630+
NewPath :: native_pattern().
630631

631632
realpath(Path) ->
632633
realpath(Path, []).
@@ -639,7 +640,10 @@ realpath([?PARENT_KHEPRI_NODE | Rest], [_ | Result]) ->
639640
realpath(Rest, Result);
640641
realpath([?PARENT_KHEPRI_NODE | Rest], [] = Result) ->
641642
realpath(Rest, Result);
642-
realpath([Component | Rest], Result) ->
643+
realpath([Component | Rest], Result)
644+
when is_atom(Component) orelse
645+
is_binary(Component) orelse
646+
?IS_KHEPRI_CONDITION(Component) ->
643647
realpath(Rest, [Component | Result]);
644648
realpath([], Result) ->
645649
lists:reverse(Result).

src/khepri_tree.erl

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
-export([new/0,
2323
get_root/1,
2424
get_keep_while_conds/1,
25+
assert_equal/2,
2526

2627
are_keep_while_conditions_met/2,
2728

@@ -39,16 +40,16 @@
3940

4041
-record(tree, {root = #node{} :: khepri_tree:tree_node(),
4142
keep_while_conds = #{} :: khepri_tree:keep_while_conds_map(),
42-
keep_while_conds_revidx = #{} ::
43-
khepri_tree:keep_while_conds_revidx()}).
43+
keep_while_conds_revidx = #{}}).
4444

4545
-type tree_node() :: #node{}.
4646
%% A node in the tree structure.
4747

48-
-opaque tree_v0() :: #tree{keep_while_conds_revidx ::
49-
khepri_tree:keep_while_conds_revidx_v0()}.
50-
-opaque tree_v1() :: #tree{keep_while_conds_revidx ::
51-
khepri_tree:keep_while_conds_revidx_v1()}.
48+
-type tree(KeepWhileCondsRevIdxType) :: #tree{keep_while_conds_revidx ::
49+
KeepWhileCondsRevIdxType}.
50+
51+
-opaque tree_v0() :: tree(khepri_tree:keep_while_conds_revidx_v0()).
52+
-opaque tree_v1() :: tree(khepri_tree:keep_while_conds_revidx_v1()).
5253

5354
-type tree() :: tree_v0() | tree_v1().
5455

@@ -125,6 +126,14 @@ get_root(#tree{root = Root}) ->
125126
get_keep_while_conds(#tree{keep_while_conds = KeepWhileConds}) ->
126127
KeepWhileConds.
127128

129+
-spec assert_equal(Tree1, Tree2) -> ok when
130+
Tree1 :: khepri_tree:tree(),
131+
Tree2 :: khepri_tree:tree().
132+
133+
assert_equal(#tree{} = Tree1, #tree{} = Tree2) ->
134+
?assertEqual(Tree1, Tree2),
135+
ok.
136+
128137
-spec create_node_record(Payload) -> Node when
129138
Payload :: khepri_payload:payload(),
130139
Node :: tree_node().
@@ -312,9 +321,10 @@ squash_version_bumps_after_keep_while(
312321
%% Keep-while functions.
313322
%% -------------------------------------------------------------------
314323

315-
-spec to_absolute_keep_while(BasePath, KeepWhile) -> KeepWhile when
324+
-spec to_absolute_keep_while(BasePath, KeepWhile) -> AbsKeepWhile when
316325
BasePath :: khepri_path:native_path(),
317-
KeepWhile :: khepri_condition:native_keep_while().
326+
KeepWhile :: khepri_condition:native_keep_while(),
327+
AbsKeepWhile :: khepri_condition:native_keep_while().
318328
%% @private
319329

320330
to_absolute_keep_while(BasePath, KeepWhile) ->
@@ -379,18 +389,24 @@ is_keep_while_condition_met_on_self(
379389
true
380390
end.
381391

392+
-spec update_keep_while_conds(Tree, Watcher, KeepWhile) -> NewTree when
393+
Tree :: khepri_tree:tree(),
394+
Watcher :: khepri_path:native_path(),
395+
KeepWhile :: khepri_condition:native_keep_while(),
396+
NewTree :: khepri_tree:tree().
397+
382398
update_keep_while_conds(Tree, Watcher, KeepWhile) ->
383399
AbsKeepWhile = to_absolute_keep_while(Watcher, KeepWhile),
384400
Tree1 = update_keep_while_conds_revidx(Tree, Watcher, AbsKeepWhile),
385-
#tree{keep_while_conds = KeepWhileConds} = Tree1,
401+
KeepWhileConds = get_keep_while_conds(Tree1),
386402
KeepWhileConds1 = KeepWhileConds#{Watcher => AbsKeepWhile},
387403
Tree1#tree{keep_while_conds = KeepWhileConds1}.
388404

389-
-spec update_keep_while_conds_revidx(Tree, Watcher, KeepWhile) ->
390-
Tree when
405+
-spec update_keep_while_conds_revidx(Tree, Watcher, KeepWhile) -> NewTree when
391406
Tree :: tree(),
392407
Watcher :: khepri_path:native_path(),
393-
KeepWhile :: khepri_condition:native_keep_while().
408+
KeepWhile :: khepri_condition:native_keep_while(),
409+
NewTree :: tree().
394410

395411
update_keep_while_conds_revidx(
396412
#tree{keep_while_conds_revidx = KeepWhileCondsRevIdx} = Tree,

0 commit comments

Comments
 (0)