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

Compiler/runtime yields invalid semantic behaviour in guard clauses with fail

    XMLWordPrintable

    Details

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

      Description

      This bug exists on master.

      Take this code:

      -module(foo).
      -export([struct_or_map/2]).
      
      struct_or_map(Arg, Name) when
        (is_map(Arg) andalso (is_atom(Name) orelse fail) andalso
         erlang:is_map_key(struct, Arg)) orelse is_map(Arg) -> true;
      
      struct_or_map(_Arg, _Name) ->
        false.
      

      When called like this:

      1> foo:struct_or_map(#{}, "foo").
      true
      

      It returns "true" but it should return "false" as the "fail" atom should force the whole clause to fail.

        Attachments

          Activity

            People

            Assignee:
            bjorn Björn Gustavsson
            Reporter:
            josevalim José Valim
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: