[erlang-bugs] Updating key in empty map doesn't fail

Lars Hesel Christensen <>
Sun Feb 9 14:37:55 CET 2014

Hi All

I'm playing around with the maps in Erlang R17 rc1, and discovered
something unexpected (at least for me): When updating an empty map with
a key, the runtime system doesn't complain!

If I define a module with one function that updates a key in the map
given as an argument:

   update_key(Map) ->
       Map#{key := val}.

Then updating an existing key works as expected:

   1> maps_test:update_key(#{key => hello}).
   #{key => val}

Trying to update a non-existing key in a non-empty map fails as expected
as well:

   2> maps_test:update_key(#{non_existing_key => hello}).
   ** exception error: bad argument
        in function  maps_test:update_key/1 (maps_test.erl, line 4)

Updating a non-existing key in an emtpy-map does NOT fail as expected:

   3> maps_test:update_key(#{}).
   #{key => val}

I would expect ':=' to behave the same regardless if it is operating on
an empty map or not.

Maybe this has already been noticed, discussed, explained here or
somewhere else, but so far I didn't find anything about this behaviour.

A bug, maybe?


More information about the erlang-bugs mailing list