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

Non-lexical evaluation order in records

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Not a Bug
    • Affects Version/s: 23
    • Fix Version/s: None
    • Component/s: compiler
    • Labels:
      None

      Description

      The way records are compiled, the expressions for fields are evaluated in the definition order, not in the order they can be seen in the code. This can lead to subtle and hard to spot errors. For example, given the following module:

       

      -module(test).
      -export([test/0]).
      -record(x, {a, b}).
      test() ->
          #x{
              b = io:put_chars("b"),
              a = io:put_chars("a")
          }.
      

      When test:test() is evaluated, ab is printed to the console, instead of the expected ba that would correspond to the order of print statement in the source code.

       

        Attachments

          Activity

            People

            Assignee:
            bjorn Björn Gustavsson
            Reporter:
            michalmuskala Michał Muskała
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: