diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2014-03-08 18:12:13 +0100 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2014-03-14 21:51:51 +0100 |
commit | 766b8d3877a9c304e61828af4f376c5c4fb70a8e (patch) | |
tree | 7077996e90b271b78fc6e0b40b9287dc7470ad55 /lib/stdlib | |
parent | 870737ab657433c5e8751255fe3c4d298202d142 (diff) | |
download | otp-766b8d3877a9c304e61828af4f376c5c4fb70a8e.tar.gz otp-766b8d3877a9c304e61828af4f376c5c4fb70a8e.tar.bz2 otp-766b8d3877a9c304e61828af4f376c5c4fb70a8e.zip |
Fix evaluation of empty map updates in erl_eval
Diffstat (limited to 'lib/stdlib')
-rw-r--r-- | lib/stdlib/src/erl_eval.erl | 20 | ||||
-rw-r--r-- | lib/stdlib/test/erl_eval_SUITE.erl | 1 |
2 files changed, 16 insertions, 5 deletions
diff --git a/lib/stdlib/src/erl_eval.erl b/lib/stdlib/src/erl_eval.erl index 3a4108e297..3974fbc4ec 100644 --- a/lib/stdlib/src/erl_eval.erl +++ b/lib/stdlib/src/erl_eval.erl @@ -18,6 +18,9 @@ %% -module(erl_eval). +%% Guard is_map/1 is not yet supported in HiPE. +-compile(no_native). + %% An evaluator for Erlang abstract syntax. -export([exprs/2,exprs/3,exprs/4,expr/2,expr/3,expr/4,expr/5, @@ -243,11 +246,18 @@ expr({record,_,_,Name,_}, _Bs, _Lf, _Ef, _RBs) -> %% map expr({map,_, Binding,Es}, Bs0, Lf, Ef, RBs) -> {value, Map0, Bs1} = expr(Binding, Bs0, Lf, Ef, RBs), - {Vs,Bs} = eval_map_fields(Es, Bs1, Lf, Ef), - ret_expr(lists:foldl(fun - ({map_assoc,K,V}, Mi) -> maps:put(K,V,Mi); - ({map_exact,K,V}, Mi) -> maps:update(K,V,Mi) - end, Map0, Vs), Bs, RBs); + case Map0 of + #{} -> + {Vs,Bs} = eval_map_fields(Es, Bs1, Lf, Ef), + Map1 = lists:foldl(fun ({map_assoc,K,V}, Mi) -> + maps:put(K, V, Mi); + ({map_exact,K,V}, Mi) -> + maps:update(K, V, Mi) + end, Map0, Vs), + ret_expr(Map1, Bs, RBs); + _ -> + erlang:raise(error, {badarg,Map0}, stacktrace()) + end; expr({map,_,Es}, Bs0, Lf, Ef, RBs) -> {Vs,Bs} = eval_map_fields(Es, Bs0, Lf, Ef), ret_expr(lists:foldl(fun diff --git a/lib/stdlib/test/erl_eval_SUITE.erl b/lib/stdlib/test/erl_eval_SUITE.erl index e6512b7d71..7edf3d20a9 100644 --- a/lib/stdlib/test/erl_eval_SUITE.erl +++ b/lib/stdlib/test/erl_eval_SUITE.erl @@ -1451,6 +1451,7 @@ eep43(Config) when is_list(Config) -> " {Map#{a := B},Map#{a => c},Map#{d => e}} " "end.", {#{a => b},#{a => c},#{a => b,d => e}}), + error_check("[camembert]#{}.", {badarg,[camembert]}), ok. %% Check the string in different contexts: as is; in fun; from compiled code. |