[erlang-bugs] maps inside records

Sergej Jurecko <>
Sun Feb 1 09:47:24 CET 2015


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?


Incorrect behavior 2: 
test1() ->
	Z = #{type => dir,name => "My folder"},
	io:format("Z = ~p ~n",[Z]),
	P = #ev{info = Z},
	io:format("P = ~p ~n",[P]),
	test1(P).
test1(#ev{info = #{type := dir, name := Name}} = E) ->
	io:format("E = ~p ~n",[E]),
	E#ev.info.

Calling test1/0 will print:

ecds:test1().
Z = #{name => "My folder",type => dir} 
P = {ev,#{name => "My folder",type => dir}} 
E = {ev,#{name => "My folder",type => dir}} 
** exception error: bad argument
     in function  ecds:test1/1 

Exception happened in second header of test1, yet E was printed.



Sergej




More information about the erlang-bugs mailing list