Skip to content

Commit

Permalink
stdlib: Fix map comprehension result when a key value is replaced
Browse files Browse the repository at this point in the history
Fix #9358
  • Loading branch information
lucioleKi committed Jan 30, 2025
1 parent 05886b9 commit aac7149
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/stdlib/src/erl_eval.erl
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ eval_bc1(E, [], Bs, Lf, Ef, FUVs, Acc) ->

eval_mc(E, Qs, Bs, Lf, Ef, RBs, FUVs) ->
L = eval_mc1(E, Qs, Bs, Lf, Ef, FUVs, []),
Map = maps:from_list(L),
Map = maps:from_list(reverse(L)),
ret_expr(Map, Bs, RBs).

eval_mc1(E, [Q|Qs], Bs0, Lf, Ef, FUVs, Acc0) ->
Expand Down
7 changes: 6 additions & 1 deletion lib/stdlib/test/erl_eval_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,12 @@ eep43(Config) when is_list(Config) ->
" (fun(#{X := value}) -> true end)(#{X => value}) "
"end.",
true),

check(fun() -> #{A => B || {A, B} <- [{1, 2}, {1, 3}]} end,
"#{A => B || {A, B} <- [{1, 2}, {1, 3}]}.",
#{1 => 3}),
check(fun() -> #{A => B || X <- [1, 5], {A, B} <- [{X, X+1}, {X, X+3}]} end,
"#{A => B || X <- [1, 5], {A, B} <- [{X, X+1}, {X, X+3}]}.",
#{1 => 4,5 => 8}),
error_check("[camembert]#{}.", {badmap,[camembert]}),
error_check("[camembert]#{nonexisting:=v}.", {badmap,[camembert]}),
error_check("#{} = 1.", {badmatch,1}),
Expand Down

0 comments on commit aac7149

Please sign in to comment.