Skip to content

Commit 15f93dc

Browse files
committed
khepri_import_export: Fix comparison between opaque khepri_tree:tree() terms
[Why] `khepri_tree:tree()` can be either a `tree_v0()` or a `tree_v1()` which are both opaque types. Therefore, they can't simply be compared with =:= because it violates the contract that a e.g. a `tree_v0()` can't be compared to a `tree_v1()` without knowing their internals. This was reported by Dialyzer in Erlang/OTP 28. [How] We move the assert to `khepri_tree` which defines these opaque types and thus has the right to compare them.
1 parent 7be79a4 commit 15f93dc

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
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_tree.erl

Lines changed: 9 additions & 0 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

@@ -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().

0 commit comments

Comments
 (0)