aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnthony Ramine <[email protected]>2015-03-11 14:21:37 +0100
committerAnthony Ramine <[email protected]>2015-03-11 15:30:22 +0100
commit36576d7de20e4e8cb7b3943cfe1b7e272b5e3971 (patch)
tree23e46b1c99ff4cae52e056871529ee8274c8c88a
parentd6073d78109f026ef96b29af4ce748242df2389d (diff)
downloadotp-36576d7de20e4e8cb7b3943cfe1b7e272b5e3971.tar.gz
otp-36576d7de20e4e8cb7b3943cfe1b7e272b5e3971.tar.bz2
otp-36576d7de20e4e8cb7b3943cfe1b7e272b5e3971.zip
Properly collect variables in match specs with maps
-rw-r--r--erts/emulator/beam/erl_db_util.c9
-rw-r--r--lib/stdlib/test/ets_SUITE.erl5
2 files changed, 13 insertions, 1 deletions
diff --git a/erts/emulator/beam/erl_db_util.c b/erts/emulator/beam/erl_db_util.c
index 1d986f2447..748be93fe3 100644
--- a/erts/emulator/beam/erl_db_util.c
+++ b/erts/emulator/beam/erl_db_util.c
@@ -3286,7 +3286,14 @@ int db_has_variable(Eterm node) {
while(arity--) {
ESTACK_PUSH(s,*(++tuple));
}
- }
+ } else if (is_map(node)) {
+ Eterm *values = map_get_values(map_val(node));
+ int size = map_get_size(map_val(node));
+ ESTACK_PUSH(s, ((map_t *) map_val(node))->keys);
+ while (size--) {
+ ESTACK_PUSH(s, *(values++));
+ }
+ }
break;
case TAG_PRIMARY_IMMED1:
if (node == am_Underscore || db_is_variable(node) >= 0) {
diff --git a/lib/stdlib/test/ets_SUITE.erl b/lib/stdlib/test/ets_SUITE.erl
index 2674f6886f..72f3c49b5a 100644
--- a/lib/stdlib/test/ets_SUITE.erl
+++ b/lib/stdlib/test/ets_SUITE.erl
@@ -3779,6 +3779,7 @@ match_object_do(Opts) ->
?line ets:insert(Tab,{{one,5},5}),
?line ets:insert(Tab,{{two,4},4}),
?line ets:insert(Tab,{{two,5},6}),
+ ?line ets:insert(Tab, {#{camembert=>cabécou},7}),
?line case ets:match_object(Tab, {{one, '_'}, '$0'}) of
[{{one,5},5},{{one,4},4}] -> ok;
[{{one,4},4},{{one,5},5}] -> ok;
@@ -3799,6 +3800,10 @@ match_object_do(Opts) ->
[{{two,4},4},{{two,5},6}] -> ok;
_ -> ?t:fail("ets:match_object() returned something funny.")
end,
+ % Check that maps are inspected for variables.
+ [{#{camembert:=cabécou},7}] =
+ ets:match_object(Tab, {#{camembert=>'_'},7}),
+ {'EXIT',{badarg,_}} = (catch ets:match_object(Tab, {#{'$1'=>'_'},7})),
% Check that unsucessful match returns an empty list.
?line [] = ets:match_object(Tab, {{three,'$0'}, '$92'}),
% Check that '$0' equals '_'.