Uploaded image for project: 'Erlang/OTP'
  1. Erlang/OTP
  2. ERL-1179

Compiler/runtime yields invalid semantic behaviour (boolean value is flipped)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 23
    • Fix Version/s: 23.0
    • Component/s: compiler
    • Labels:
      None

      Description

      This bug was found in master at commit:

      commit a4e8656d1aa4bde0bbfab6a52585add5d7951bd1
      Merge: b7d1866d48 75d4701fff
      Author: Sverker Eriksson <sverker@erlang.org>
      Date:   Tue Feb 18 16:38:24 2020 +0100
      

      Take the following Erlang code:

      -module(foo).
      -export([bar/2]).
      
      bar(_, Caller) ->
        erlang:display({find(module, Caller), find(function, Caller), find(context, Caller)}),
        IsFunction = find(function, Caller) /= nil,
      
        case not true of
          true ->
            ok;
          false ->
            case (not IsFunction) andalso (find(context, Caller) == match) of
              true -> ok;
              false -> erlang:display({IsFunction, Caller})
            end
        end.
      
      -compile({inline, [find/2]}).
      
      find(Key, Map) ->
        case Map of
          #{Key := Value} -> Value;
          #{} -> erlang:error(badmap)
        end.
      

      Compile it with `erlc foo.erl` and now in `erl` type this:

      1> foo:bar(baz, #{module => regex, function => nil, context => nil}).
      {regex,nil,nil}
      {true,#{context=>nil,function=>nil,module=>regex}}
      

      As you can see, it is saying that `IsFunction` is true but it should be false (as it is not different to nil).

      Thank you!

        Attachments

          Activity

            People

            Assignee:
            john John Högberg
            Reporter:
            josevalim José Valim
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: