diff options
author | Björn Gustavsson <[email protected]> | 2015-02-02 13:01:10 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2015-02-03 07:34:17 +0100 |
commit | 94b36c7c2534f92e1d1ce768fb63d9012bb0c630 (patch) | |
tree | 824fc247e6049575a2a0324a1a985d2432d57bde /lib/compiler | |
parent | d9ed708bb5d22cf61029eac0a23b9d3dc94a5146 (diff) | |
download | otp-94b36c7c2534f92e1d1ce768fb63d9012bb0c630.tar.gz otp-94b36c7c2534f92e1d1ce768fb63d9012bb0c630.tar.bz2 otp-94b36c7c2534f92e1d1ce768fb63d9012bb0c630.zip |
Be more careful about map patterns when evalutating element/2
We must not convert map patterns to map expressions.
Diffstat (limited to 'lib/compiler')
-rw-r--r-- | lib/compiler/src/sys_core_fold.erl | 9 | ||||
-rw-r--r-- | lib/compiler/test/core_fold_SUITE.erl | 6 |
2 files changed, 12 insertions, 3 deletions
diff --git a/lib/compiler/src/sys_core_fold.erl b/lib/compiler/src/sys_core_fold.erl index 2158c29576..f4f5c3f361 100644 --- a/lib/compiler/src/sys_core_fold.erl +++ b/lib/compiler/src/sys_core_fold.erl @@ -1338,9 +1338,12 @@ eval_element(Call, #c_literal{val=Pos}, #c_var{name=V}, Types) {ok,#c_tuple{es=Elements}} -> if 1 =< Pos, Pos =< length(Elements) -> - case lists:nth(Pos, Elements) of - #c_alias{var=Alias} -> Alias; - Res -> Res + El = lists:nth(Pos, Elements), + try + pat_to_expr(El) + catch + throw:impossible -> + Call end; true -> eval_failure(Call, badarg) diff --git a/lib/compiler/test/core_fold_SUITE.erl b/lib/compiler/test/core_fold_SUITE.erl index 6a7036d728..9c7e97a1bf 100644 --- a/lib/compiler/test/core_fold_SUITE.erl +++ b/lib/compiler/test/core_fold_SUITE.erl @@ -60,6 +60,12 @@ t_element(Config) when is_list(Config) -> X = make_ref(), ?line X = id(element(1, {X,y,z})), ?line b = id(element(2, {a,b,c,d})), + (fun() -> + case {a,#{k=>X}} of + {a,#{k:=X}}=Tuple -> + #{k:=X} = id(element(2, Tuple)) + end + end)(), %% No optimization, but should work. Tuple = id({x,y,z}), |