Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

erlc folds away an unused map update that should throw an exception #6960

Closed
RobinMorisset opened this issue Mar 2, 2023 · 2 comments · Fixed by #6965
Closed

erlc folds away an unused map update that should throw an exception #6960

RobinMorisset opened this issue Mar 2, 2023 · 2 comments · Fixed by #6965
Assignees
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM

Comments

@RobinMorisset
Copy link
Contributor

RobinMorisset commented Mar 2, 2023

To Reproduce
Running the following code:

f1() ->
    (#{}#{ok := ok}),
    'hello'.

wrapper0() ->
    io:write(catch f1()).

with the following:

erlc ~/minimized/divergence.erl
erl -noshell -pa . -s divergence wrapper0 -s init stop

outputs hello.

Expected behavior
I would expect a tuple containing an exception, since the map update operation is supposed to throw with badarg in this context (https://www.erlang.org/doc/reference_manual/expressions.html#map-expressions).

Affected versions
master

Additional context
Giving the argument +no_fold to erlc fixes this bug, resulting in the following output:

{'EXIT',{{badkey,ok},[{divergence,f1,0,[{file,[47,104,111,109,101,47,114,109,111,114,105,115,115,101,116,47,109,105,110,105,109,105,122,101,100,47,100,105,118,101,114,103,101,110,99,101,46,101,114,108]},{line,13}]},{divergence,wrapper0,0,[{file,[47,104,111,109,101,47,114,109,111,114,105,115,115,101,116,47,109,105,110,105,109,105,122,101,100,47,100,105,118,101,114,103,101,110,99,101,46,101,114,108]},{line,17}]},{init,start_em,1,[]},{init,do_boot,3,[]}]}}
@RobinMorisset RobinMorisset added the bug Issue is reported as a bug label Mar 2, 2023
@RobinMorisset
Copy link
Contributor Author

A much more minor weirdness is that the documentation predicts a badarg exception, but even with +no_fold I am getting a badkey exception. I suspect this just a small typo in the documentation.

@bjorng bjorng added the team:VM Assigned to OTP team VM label Mar 2, 2023
@bjorng bjorng self-assigned this Mar 2, 2023
bjorng added a commit to bjorng/otp that referenced this issue Mar 3, 2023
Fix an unsafe optimization that would remove a map update operation
that is supposed fail. For example:

    foo() ->
        #{}#{key := value},
        ok.

Instead of raising an exception, `foo/0` would return `ok`.

Closes erlang#6960
@bjorng bjorng linked a pull request Mar 3, 2023 that will close this issue
@bjorng
Copy link
Contributor

bjorng commented Mar 3, 2023

I have fixed documentation typo in a commit directly on the master branch.

bjorng added a commit that referenced this issue Mar 10, 2023
…ption/GH-6960/OTP-18497

Fix lost exception from map update
@bjorng bjorng closed this as completed Mar 10, 2023
u3s pushed a commit that referenced this issue Apr 27, 2023
…' into maint-25

* bjorn/compiler/fix-lost-map-exception/GH-6960/OTP-18497:
  Fix lost exception from map update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants