[erlang-bugs] maps inside records

Sergej Jurečko sergej.jurecko@REDACTED
Mon Feb 2 08:23:44 CET 2015


On Mon, Feb 2, 2015 at 8:04 AM, Björn Gustavsson <bjorn@REDACTED> wrote:

> On Sun, Feb 1, 2015 at 9:47 AM, Sergej Jurecko <sergej.jurecko@REDACTED>
> wrote:
> > Tested in 17.3 and 17.4
> >
> > Incorrect behavior 1:
> >
> > -record(ev,{info}).
> > test() ->
> >         test(#ev{info = #{type => dir, name => "My folder"}}).
> > test(#ev{info = #{type := dir} = I} = E) ->
> >         io:format("E = ~p~n",[E]),
> >         io:format("E#event.info = ~p~n",[E#ev.info]),
> >         io:format("I = ~p~n",[I]).
> >
> > Calling test/0 will print:
> > E = {ev,#{name => "My folder",type => dir}}
> > E#event.info = #{type => dir}
> > I = #{name => "My folder",type => dir}
> >
> > Why is E#event.info without name field?
> >
>
> The behaviour is the expected.
>
> Records are compile-time construct that are translated
> to tuples. So at run-time the record is a tuple and
> will be printed as a tuple.
>


Yes but E#event.info value is not a record. It is a map which should
contain #{type => dir, name => "My folder"}, yet when trying to extract
that record we only get #{type => dir}.

E#event.info should be the same as I, yet it is not.


Sergej
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20150202/b67e0765/attachment.htm>


More information about the erlang-bugs mailing list