[erlang-questions] maps with records

Dmitry Aleksandrov elixmoon@REDACTED
Tue Jan 13 01:29:27 CET 2015


We found strange behaviour from (As I can judge) erlang compiler, when 
dealing with records and maps in the same function.

Here is example:


   -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().
** 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> =
           in  let <_cor3> =
               %% Line 8
               call 'erlang':'setelement'
                   (3, S, Test)
               in  %% Line 8

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

And its working.

Should we send it to erlang-bugs?

Tested on erlang 17.4.

More information about the erlang-questions mailing list