summaryrefslogtreecommitdiff
path: root/lib/compiler
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <egil@erlang.org>2014-03-25 18:37:56 +0100
committerBjörn-Egil Dahlberg <egil@erlang.org>2014-03-25 19:07:48 +0100
commit71df02b2ead5c68eb9c4dff00d91a1d0e94659fe (patch)
tree617c084408a29cf65b3be6ae9536ebd7288c960a /lib/compiler
parent9e01993aac2cc35c77e5e246ed6e160c3485a456 (diff)
downloaderlang-71df02b2ead5c68eb9c4dff00d91a1d0e94659fe.tar.gz
compiler: Throw 'nomatch' on matching with bad binary keys
Even if a binary key is written as a literal the compiler may choose to make an expression. Emit a warning in those cases and saying the case will not match. This is a limitation in current implementation.
Diffstat (limited to 'lib/compiler')
-rw-r--r--lib/compiler/src/v3_core.erl4
-rw-r--r--lib/compiler/test/warnings_SUITE.erl16
2 files changed, 18 insertions, 2 deletions
diff --git a/lib/compiler/src/v3_core.erl b/lib/compiler/src/v3_core.erl
index 04210ae243..46db9139c4 100644
--- a/lib/compiler/src/v3_core.erl
+++ b/lib/compiler/src/v3_core.erl
@@ -1595,7 +1595,9 @@ pattern_map_pair({map_field_exact,L,K,V}, St) ->
{bin,L,Es0} ->
case constant_bin(Es0) of
error ->
- throw(badmatch);
+ %% this will throw a cryptic error message
+ %% but it is better than nothing
+ throw(nomatch);
Bin ->
#c_literal{anno=lineno_anno(L,St),val=Bin}
end;
diff --git a/lib/compiler/test/warnings_SUITE.erl b/lib/compiler/test/warnings_SUITE.erl
index e8ec48df14..ad4ad91f74 100644
--- a/lib/compiler/test/warnings_SUITE.erl
+++ b/lib/compiler/test/warnings_SUITE.erl
@@ -600,7 +600,21 @@ maps(Config) when is_list(Config) ->
ok.
">>,
[],
- {warnings,[{3,v3_core,bad_map}]}}],
+ {warnings,[{3,v3_core,bad_map}]}},
+ {bad_map_literal_key,
+ <<"
+ t() ->
+ V = id(1),
+ M = id(#{ <<$h,$i>> => V }),
+ V = case M of
+ #{ <<0:257>> := Val } -> Val;
+ #{ <<$h,$i>> := Val } -> Val
+ end,
+ ok.
+ id(I) -> I.
+ ">>,
+ [],
+ {warnings,[{6,v3_core,nomatch}]}}],
run(Config, Ts),
ok.