Thanks to visit codestin.com
Credit goes to github.com

Skip to content

+no_copt changes effect of a guard #7517

@RobinMorisset

Description

@RobinMorisset

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.

Metadata

Metadata

Assignees

Labels

bugIssue is reported as a bugteam:VMAssigned to OTP team VM

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions