program main
  enum Reading
    variant Missing
    variant Value i32
    variant Offset i32
  fn missing() -> Reading
    enum-variant Reading.Missing #0 : Reading
  fn value(payload: i32) -> Reading
    enum-variant Reading.Value #1 payload : Reading
      var payload : i32
  fn echo(reading: Reading) -> Reading
    var reading : Reading
  fn local_reading(payload: i32) -> Reading
    local let reading : unit
      enum-variant Reading.Value #1 payload : Reading
        var payload : i32
    var reading : Reading
  fn same_reading(left: Reading, right: Reading) -> bool
    binary = : bool
      var left : Reading
      var right : Reading
  fn reading_code(reading: Reading) -> i32
    match : i32
      subject
        var reading : Reading
      arm Reading.Missing
        int 0 : i32
      arm Reading.Value payload
        var payload : i32
      arm Reading.Offset payload
        binary + : i32
          var payload : i32
          int 100 : i32
  fn call_flow(payload: i32) -> Reading
    call echo : Reading
      call local_reading : Reading
        var payload : i32
  fn main() -> i32
    call reading_code : i32
      call call_flow : Reading
        int 42 : i32
  test "enum payload constructor equality"
    binary = : bool
      enum-variant Reading.Value #1 payload : Reading
        int 7 : i32
      call value : Reading
        int 7 : i32
  test "enum payload equality compares payload"
    if : bool
      binary = : bool
        enum-variant Reading.Value #1 payload : Reading
          int 7 : i32
        enum-variant Reading.Value #1 payload : Reading
          int 8 : i32
      bool false : bool
      bool true : bool
  test "enum payloadless equality"
    binary = : bool
      enum-variant Reading.Missing #0 : Reading
      call missing : Reading
  test "enum payload local return call flow"
    binary = : bool
      call call_flow : Reading
        int 9 : i32
      enum-variant Reading.Value #1 payload : Reading
        int 9 : i32
  test "enum payload parameter equality"
    call same_reading : bool
      call value : Reading
        int 11 : i32
      enum-variant Reading.Value #1 payload : Reading
        int 11 : i32
  test "enum payload match missing"
    binary = : bool
      call reading_code : i32
        enum-variant Reading.Missing #0 : Reading
      int 0 : i32
  test "enum payload match value"
    binary = : bool
      call reading_code : i32
        enum-variant Reading.Value #1 payload : Reading
          int 12 : i32
      int 12 : i32
  test "enum payload match offset"
    binary = : bool
      call reading_code : i32
        enum-variant Reading.Offset #2 payload : Reading
          int 5 : i32
      int 105 : i32
