diff options
author | Björn Gustavsson <[email protected]> | 2016-01-11 15:58:57 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2016-01-12 10:06:02 +0100 |
commit | ff2ef4278045c985738e3ddb4af6127c7db933e7 (patch) | |
tree | 77dda64e520079c050639390c63f70866f7da4cf /lib/compiler/test/compile_SUITE_data/simple-basic1.mk | |
parent | 12dffc7f0c85aa4662b97cba4af2c9ae2ba74083 (diff) | |
download | otp-ff2ef4278045c985738e3ddb4af6127c7db933e7.tar.gz otp-ff2ef4278045c985738e3ddb4af6127c7db933e7.tar.bz2 otp-ff2ef4278045c985738e3ddb4af6127c7db933e7.zip |
Fix crash when attempting to update a fun as if it were a map
The following example would cause an internal consistency
failure in the compiler:
f() -> ok.
update() -> (fun f/0)#{u => 42}.
The reason is that internally, v3_core will (incorrectly)
rewrite update/0 to code similar to this:
update() ->
if
is_map(fun f/0) ->
maps:update(u, 42, fun f/0)
end.
Since funs are not allowed to be created in guards, incorrect and
unsafe code would be generated.
It is easy to fix the bug. There already is a is_valid_map_src/1
function in v3_core that tests whether the argument for the map update
operation can possibly be a valid map. A fun is represented as a
variable with a special name in Core Erlang, so it would not be
recognized as unsafe. All we'll need to do to fix the bug is to look
closer at variables to ensure they don't represent funs. That will
ensure that the code is rewritten in the correct way:
update() ->
error({badmap,fun f/0})
end.
Reported-by: Thomas Arts
Diffstat (limited to 'lib/compiler/test/compile_SUITE_data/simple-basic1.mk')
0 files changed, 0 insertions, 0 deletions