[erlang-bugs] Maps behaving oddly on update syntax with literal
José Valim
jose.valim@REDACTED
Wed Feb 5 18:25:12 CET 2014
Actually, it seems M#{a := b} always work when M is an empty map:
-module(foo).
-compile(export_all).
bat(M) ->
M#{a := b}.
Here is my session:
1> foo:bat(#{a => b}).
#{a => b}
2> foo:bat(#{b => b}).
** exception error: bad argument
in function foo:bat/1 (foo.erl, line 5)
3> foo:bat(#{}).
#{a => b}
3> was supposed to fail. Note (#{})#{a := b} works in the shell (eval).
* José Valimwww.plataformatec.com.br <http://www.plataformatec.com.br/>
Founder and Lead Developer*
On Wed, Feb 5, 2014 at 6:16 PM, José Valim <jose.valim@REDACTED> wrote:
> Hello folks,
>
> Maps are not working properly on update with a literal (via a var):
>
> -module(foo).
> -compile(export_all).
>
> %% This function does not fail (and it should)
> bar() ->
> M = #{},
> M#{a := b}.
>
> %% This function fails horribly
> %%
> %% =ERROR REPORT==== 5-Feb-2014::18:10:18 ===
> %% beam/beam_load.c(2065): Error loading function foo:baz/0: op
> update_map_exact p a r u u a a:
> %% no specific operation found
> baz() ->
> M = nil,
> M#{a := b}.
>
>
> I assume there is some sort of inlining happening and discarding useful
> information.
> As far as I can see, the Erlang Abstract Format is correct.
>
> Thank you!
>
>
> * José Valimwww.plataformatec.com.br <http://www.plataformatec.com.br/>
> Founder and Lead Developer*
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20140205/e914fcc5/attachment.htm>
More information about the erlang-bugs
mailing list