[erlang-questions] maps with records

Björn-Egil Dahlberg wallentin.dahlberg@REDACTED
Tue Jan 13 10:08:09 CET 2015


Compiling with erlc +no_copt test_ebug.erl generates no such error. So it
looks like an error in core optimization pass.


2015-01-13 1:29 GMT+01:00 Dmitry Aleksandrov <elixmoon@REDACTED>:

> Hi!
>
> We found strange behaviour from (As I can judge) erlang compiler, when
> dealing with records and maps in the same function.
>
> Here is example:
>
>   -module(test_ebug).
>   -compile([export_all]).
>
>   -record(session, {args, test}).
>
>   init(#session{args = #{test := Test}}=S) ->
>       io:format(user, "info~n", []),
>       {ok, [], S#session{test = Test}}.
>
>   test() -> init(#session{args = #{test => 1}}).
>
> After compiling and test:
>
> 1> test_ebug:test().
> info
> ** exception error: bad argument
>      in function  test_ebug:init/1 (test_ebug.erl, line 6)
>
> It shows, that info(which happen in line 7), but stacktrace shows line 6,
> what is wrong. And, this syntax should be correct, because if we make
> assignment in another function - it works without problem.
>
> For me, it seems, that core is generated not right on that place(or at
> least, I do not understand, what is <_fol3> here):
>
>           let <_fol3> =
>               ~{~<'test',Test>}~
>           in  let <_cor3> =
>               %% Line 8
>               call 'erlang':'setelement'
>                   (3, S, Test)
>               in  %% Line 8
>               {'ok',[],_cor3}
>
> If I replace record syntax, with 'erlang:setelement(3, S, Test)', than
> core is:
>
>           let <_cor1> =
>               %% Line 8
>               call 'erlang':'setelement'
>               (3, S, Test)
>           in  %% Line 8
>               {'ok',[],_cor1}
>
> And its working.
>
> Should we send it to erlang-bugs?
>
> Tested on erlang 17.4.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150113/a8ca27da/attachment.htm>


More information about the erlang-questions mailing list