diff options
| author | Björn Gustavsson <bjorn@erlang.org> | 2023-03-10 08:17:29 +0100 |
|---|---|---|
| committer | Björn Gustavsson <bjorn@erlang.org> | 2023-03-10 08:17:29 +0100 |
| commit | 8130d7ff72b9a7344bbf38ae11283eb01aab3ae5 (patch) | |
| tree | c0720f21a1c32a0883d5452488be63f1b41f5172 /lib/compiler | |
| parent | 8f4e4cd18ed2c272c5eacf0f3d73957cd439c38d (diff) | |
| parent | 5063a62f102d2104b789e04541a88df4666e1380 (diff) | |
| download | erlang-8130d7ff72b9a7344bbf38ae11283eb01aab3ae5.tar.gz | |
Merge branch 'maint'
* maint:
Fix lost exception from map update
Diffstat (limited to 'lib/compiler')
| -rw-r--r-- | lib/compiler/src/sys_core_fold.erl | 28 | ||||
| -rw-r--r-- | lib/compiler/test/core_fold_SUITE.erl | 24 |
2 files changed, 34 insertions, 18 deletions
diff --git a/lib/compiler/src/sys_core_fold.erl b/lib/compiler/src/sys_core_fold.erl index d97954572b..cebc0660aa 100644 --- a/lib/compiler/src/sys_core_fold.erl +++ b/lib/compiler/src/sys_core_fold.erl @@ -218,15 +218,15 @@ expr(#c_tuple{anno=Anno,es=Es0}=Tuple, Ctxt, Sub) -> ann_c_tuple(Anno, Es) end; expr(#c_map{anno=Anno,arg=V0,es=Es0}=Map, Ctxt, Sub) -> - Es = pair_list(Es0, Ctxt, descend(Map, Sub)), + %% Warn for useless building, but always build the map + %% anyway to preserve a possible exception. case Ctxt of - effect -> - warn_useless_building(Map, Sub), - make_effect_seq(Es, Sub); - value -> - V = expr(V0, Ctxt, Sub), - ann_c_map(Anno,V,Es) - end; + effect -> warn_useless_building(Map, Sub); + value -> ok + end, + Es = pair_list(Es0, descend(Map, Sub)), + V = expr(V0, value, Sub), + ann_c_map(Anno, V, Es); expr(#c_binary{segments=Ss}=Bin0, Ctxt, Sub) -> %% Warn for useless building, but always build the binary %% anyway to preserve a possible exception. @@ -486,14 +486,12 @@ ifes_list(_FVar, [], _Safe) -> expr_list(Es, Ctxt, Sub) -> [expr(E, Ctxt, Sub) || E <- Es]. -pair_list(Es, Ctxt, Sub) -> - [pair(E, Ctxt, Sub) || E <- Es]. +pair_list(Es, Sub) -> + [pair(E, Sub) || E <- Es]. -pair(#c_map_pair{key=K,val=V}, effect, Sub) -> - make_effect_seq([K,V], Sub); -pair(#c_map_pair{key=K0,val=V0}=Pair, value=Ctxt, Sub) -> - K = expr(K0, Ctxt, Sub), - V = expr(V0, Ctxt, Sub), +pair(#c_map_pair{key=K0,val=V0}=Pair, Sub) -> + K = expr(K0, value, Sub), + V = expr(V0, value, Sub), Pair#c_map_pair{key=K,val=V}. bitstr_list(Es, Sub) -> diff --git a/lib/compiler/test/core_fold_SUITE.erl b/lib/compiler/test/core_fold_SUITE.erl index 9ee4990fc9..18284b9ebe 100644 --- a/lib/compiler/test/core_fold_SUITE.erl +++ b/lib/compiler/test/core_fold_SUITE.erl @@ -30,7 +30,8 @@ no_no_file/1,configuration/1,supplies/1, redundant_stack_frame/1,export_from_case/1, empty_values/1,cover_letrec_effect/1, - receive_effect/1,nested_lets/1]). + receive_effect/1,nested_lets/1, + map_effect/1]). -export([foo/0,foo/1,foo/2,foo/3]). @@ -51,8 +52,8 @@ groups() -> no_no_file,configuration,supplies, redundant_stack_frame,export_from_case, empty_values,cover_letrec_effect, - receive_effect,nested_lets]}]. - + receive_effect,nested_lets, + map_effect]}]. init_per_suite(Config) -> test_lib:recompile(?MODULE), @@ -856,5 +857,22 @@ nested_lets_6() -> ok end. +map_effect(_Config) -> + {'EXIT',{{badkey,key},_}} = catch map_effect_1(), + + {'EXIT',{{badkey,key},_}} = catch map_effect_2(#{}), + {'EXIT',{{badmap,no_map},_}} = catch map_effect_2(no_map), + + ok. + +map_effect_1() -> + #{}#{key := value}, + ok. + +map_effect_2(Map) -> + Map#{key := value}, + ok. + %%% Common utility functions. + id(I) -> I. |
