aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2015-01-19 15:10:34 +0100
committerBjörn Gustavsson <[email protected]>2015-01-19 15:36:22 +0100
commitbb561b0dd58a89489acb93bdf7b5386e7f306835 (patch)
treea550a9b87cb690fb5f804c3bdea7613692540a91 /lib/compiler/src
parent50a92094372b45c9864afe3418b79605da549122 (diff)
downloadotp-bb561b0dd58a89489acb93bdf7b5386e7f306835.tar.gz
otp-bb561b0dd58a89489acb93bdf7b5386e7f306835.tar.bz2
otp-bb561b0dd58a89489acb93bdf7b5386e7f306835.zip
core_lib: Handle patterns in map values
core_lib:is_var_used/2 would not consider a variable used in the value of a map pattern such as: case Map of #{key := <<42:N>>} -> ok end Here the variable 'N' would not be considered used. It was assumed that there was no need to check map patterns at all, since maps currently don't support variables in keys.
Diffstat (limited to 'lib/compiler/src')
-rw-r--r--lib/compiler/src/core_lib.erl9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/compiler/src/core_lib.erl b/lib/compiler/src/core_lib.erl
index 2792fd8fa5..0d95971f91 100644
--- a/lib/compiler/src/core_lib.erl
+++ b/lib/compiler/src/core_lib.erl
@@ -212,6 +212,8 @@ vu_pattern(V, #c_tuple{es=Es}, St) ->
vu_pattern_list(V, Es, St);
vu_pattern(V, #c_binary{segments=Ss}, St) ->
vu_pat_seg_list(V, Ss, St);
+vu_pattern(V, #c_map{es=Es}, St) ->
+ vu_map_pairs(V, Es, St);
vu_pattern(V, #c_alias{var=Var,pat=P}, St0) ->
case vu_pattern(V, Var, St0) of
{true,_}=St1 -> St1;
@@ -234,6 +236,13 @@ vu_pat_seg_list(V, Ss, St) ->
end
end, St, Ss).
+vu_map_pairs(V, [#c_map_pair{val=Pat}|T], St0) ->
+ case vu_pattern(V, Pat, St0) of
+ {true,_}=St -> St;
+ St -> vu_map_pairs(V, T, St)
+ end;
+vu_map_pairs(_, [], St) -> St.
+
-spec vu_var_list(cerl:var_name(), [cerl:c_var()]) -> boolean().
vu_var_list(V, Vs) ->