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

+no_copt changes effect of a guard #7517

Closed
RobinMorisset opened this issue Jul 28, 2023 · 1 comment · Fixed by #7519
Closed

+no_copt changes effect of a guard #7517

RobinMorisset opened this issue Jul 28, 2023 · 1 comment · Fixed by #7519
Assignees
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM

Comments

@RobinMorisset
Copy link
Contributor

Describe the bug
Running the following code:

f(_V0) when (ok /= _V0) or is_float(is_list(_V0) orelse (ok andalso ok)) ->
    ok.

wrapper0() ->
    io:format("~kp", [catch f(<<>>)]).

by doing

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

results in ok being output.
But passing +no_copt to erlc makes it output the following instead:

{'EXIT',
    {function_clause,
        [{test990917,f,
             [<<>>],
             [{file,"/home/rmorisset/minimized/test990917.erl"},{line,7}]},
         {test990917,wrapper0,0,
             [{file,"/home/rmorisset/minimized/test990917.erl"},{line,11}]},
         {init,start_em,1,[]},
         {init,do_boot,3,[]}]}}

Expected behavior
I believe that the behavior with +no_copt is the correct one:

  • is_list(_V0) is false
  • so (ok andalso ok) should execute (since the or is not supposed to short-circuit)
  • ok is not a boolean, so this should throw
  • and an exception in the guard should make the function clause be skipped

Affected versions

Additional context
This looks kind of similar to #7494, but the testcase is sufficiently different that I am unsure of whether they are duplicates, hence this issue being filed.

@RobinMorisset RobinMorisset added the bug Issue is reported as a bug label Jul 28, 2023
@jhogberg jhogberg added the team:VM Assigned to OTP team VM label Jul 28, 2023
@bjorng bjorng self-assigned this Jul 31, 2023
@bjorng
Copy link
Contributor

bjorng commented Jul 31, 2023

I can confirm that this is not the same bug as #7494.

bjorng added a commit that referenced this issue Aug 1, 2023
@bjorng bjorng closed this as completed in 42e6979 Aug 1, 2023
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.

3 participants