[erlang-bugs] Maps behaving oddly on update syntax with literal

Björn-Egil Dahlberg egil@REDACTED
Wed Feb 5 19:19:41 CET 2014


Thank you for reporting. =)

The linter should realize it's not a map when dealing with literals. 
It's just pass-through atm which is plainly obvious.

Try this: 
https://github.com/psyeugenic/otp/commits/egil/erts/fix-maps-beam_load


.. heading back to compiler fixes ..

// Björn-Egil

On 2014-02-05 18:25, José Valim wrote:
> 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é Valim*
> www.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 
> <mailto: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é Valim*
>     www.plataformatec.com.br <http://www.plataformatec.com.br/>
>     Founder and Lead Developer
>     *
>
>
>
>
> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://erlang.org/mailman/listinfo/erlang-bugs

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20140205/7daeb2e7/attachment.htm>


More information about the erlang-bugs mailing list