[erlang-questions] maps with records

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


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.



More information about the erlang-questions mailing list