aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <egil@erlang.org>2014-03-06 15:06:43 +0100
committerBjörn-Egil Dahlberg <egil@erlang.org>2014-03-06 15:06:43 +0100
commit35e8ea1c100248acc037205b0d551f6ee0b9f773 (patch)
treec6ab8e187fc17bc5c275aecf655a85dbdf5eb4aa
parent24c1ee0228ff442dafa5c2e87661ba2d2f97bf2f (diff)
parent2b5acdb32471f2eb469221007fc70dc24db271b6 (diff)
downloadotp-35e8ea1c100248acc037205b0d551f6ee0b9f773.tar.gz
otp-35e8ea1c100248acc037205b0d551f6ee0b9f773.tar.bz2
otp-35e8ea1c100248acc037205b0d551f6ee0b9f773.zip
Merge branch 'nox/maps-cerl_clauses'
* nox/maps-cerl_clauses: Support maps in cerl_clauses:match/2
-rw-r--r--lib/compiler/src/cerl_clauses.erl18
-rw-r--r--lib/compiler/test/warnings_SUITE.erl25
2 files changed, 41 insertions, 2 deletions
diff --git a/lib/compiler/src/cerl_clauses.erl b/lib/compiler/src/cerl_clauses.erl
index 99fa8dd9d5..76d70dcabf 100644
--- a/lib/compiler/src/cerl_clauses.erl
+++ b/lib/compiler/src/cerl_clauses.erl
@@ -354,6 +354,24 @@ match(P, E, Bs) ->
{false, Bs}
end
end;
+ map ->
+ %% The most we can do is to say "definitely no match" if a
+ %% binary pattern is matched against non-binary data.
+ case E of
+ any ->
+ {false, Bs};
+ _ ->
+ case type(E) of
+ literal ->
+ none;
+ cons ->
+ none;
+ tuple ->
+ none;
+ _ ->
+ {false, Bs}
+ end
+ end;
_ ->
match_1(P, E, Bs)
end.
diff --git a/lib/compiler/test/warnings_SUITE.erl b/lib/compiler/test/warnings_SUITE.erl
index 16d15a59e5..f63299ea35 100644
--- a/lib/compiler/test/warnings_SUITE.erl
+++ b/lib/compiler/test/warnings_SUITE.erl
@@ -37,7 +37,8 @@
-export([pattern/1,pattern2/1,pattern3/1,pattern4/1,
guard/1,bad_arith/1,bool_cases/1,bad_apply/1,
- files/1,effect/1,bin_opt_info/1,bin_construction/1, comprehensions/1]).
+ files/1,effect/1,bin_opt_info/1,bin_construction/1, comprehensions/1,
+ maps/1]).
% Default timetrap timeout (set in init_per_testcase).
-define(default_timeout, ?t:minutes(2)).
@@ -61,7 +62,7 @@ groups() ->
[{p,test_lib:parallel(),
[pattern,pattern2,pattern3,pattern4,guard,
bad_arith,bool_cases,bad_apply,files,effect,
- bin_opt_info,bin_construction,comprehensions]}].
+ bin_opt_info,bin_construction,comprehensions,maps]}].
init_per_suite(Config) ->
Config.
@@ -552,6 +553,26 @@ comprehensions(Config) when is_list(Config) ->
run(Config, Ts),
ok.
+maps(Config) when is_list(Config) ->
+ Ts = [{bad_map,
+ <<"
+ t() ->
+ case maybe_map of
+ #{} -> ok;
+ not_map -> error
+ end.
+ x() ->
+ case true of
+ #{} -> error;
+ true -> ok
+ end.
+ ">>,
+ [],
+ {warnings,[{3,sys_core_fold,no_clause_match},
+ {9,sys_core_fold,nomatch_clause_type}]}}],
+ run(Config, Ts),
+ ok.
+
%%%
%%% End of test cases.
%%%