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

Unsafe variables wrongly reported in try ... of ...

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Resolved
    • Priority: Minor
    • Resolution: Done
    • Affects Version/s: 24.0
    • Fix Version/s: 24.0
    • Component/s: compiler
    • Labels:
      None

      Description

      The following program does not compile:

      -module(foo).
      baz() ->
        try Bar = 0 of
          _ -> Bar
        after 0
        end.

      The error message is "foo.erl:4: variable 'Bar' unsafe in 'try' (line 3)".

       

      I would not expect Bar to be unsafe here, because if we start matching the patterns after the 'of', then Bar = 0 must have been evaluated without an exception. The language manual says:

       "If the evaluation of Exprs succeeds without an exception, the patterns Pattern are sequentially matched against the result in the same way as for a case expression"

       But this program compiles just fine:

      -module(foo).
      baz() ->
        case Bar = 0 of
          _ -> Bar
        end.

        Attachments

          Activity

            People

            Assignee:
            bjorn Björn Gustavsson
            Reporter:
            rjmh John Hughes
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: