program main
  enum Status
    variant Ready
    variant Blocked
  enum Reading
    variant Missing
    variant Value i32
  struct TaggedReading
    field status: Status
    field reading: Reading
  fn make_tagged(status: Status, reading: Reading) -> TaggedReading
    construct TaggedReading : TaggedReading
      field status
        var status : Status
      field reading
        var reading : Reading
  fn ready_value(payload: i32) -> TaggedReading
    call make_tagged : TaggedReading
      enum-variant Status.Ready #0 : Status
      enum-variant Reading.Value #1 payload : Reading
        var payload : i32
  fn missing_blocked() -> TaggedReading
    call make_tagged : TaggedReading
      enum-variant Status.Blocked #1 : Status
      enum-variant Reading.Missing #0 : Reading
  fn echo_tagged(tagged: TaggedReading) -> TaggedReading
    var tagged : TaggedReading
  fn local_tagged(payload: i32) -> TaggedReading
    local let tagged : unit
      call ready_value : TaggedReading
        var payload : i32
    call echo_tagged : TaggedReading
      var tagged : TaggedReading
  fn status_of(tagged: TaggedReading) -> Status
    field-access status : Status
      var tagged : TaggedReading
  fn reading_of(tagged: TaggedReading) -> Reading
    field-access reading : Reading
      var tagged : TaggedReading
  fn is_ready(tagged: TaggedReading) -> bool
    binary = : bool
      field-access status : Status
        var tagged : TaggedReading
      enum-variant Status.Ready #0 : Status
  fn reading_matches(tagged: TaggedReading, reading: Reading) -> bool
    binary = : bool
      field-access reading : Reading
        var tagged : TaggedReading
      var reading : Reading
  fn reading_code(tagged: TaggedReading) -> i32
    match : i32
      subject
        field-access reading : Reading
          var tagged : TaggedReading
      arm Reading.Missing
        int 0 : i32
      arm Reading.Value payload
        var payload : i32
  fn main() -> i32
    call reading_code : i32
      call local_tagged : TaggedReading
        int 42 : i32
  test "enum struct field payloadless equality"
    binary = : bool
      call status_of : Status
        call missing_blocked : TaggedReading
      enum-variant Status.Blocked #1 : Status
  test "enum struct field unary payload equality"
    call reading_matches : bool
      call ready_value : TaggedReading
        int 7 : i32
      enum-variant Reading.Value #1 payload : Reading
        int 7 : i32
  test "enum struct field access return"
    binary = : bool
      call reading_of : Reading
        call missing_blocked : TaggedReading
      enum-variant Reading.Missing #0 : Reading
  test "enum struct field local param return call flow"
    binary = : bool
      call reading_code : i32
        call local_tagged : TaggedReading
          int 9 : i32
      int 9 : i32
  test "enum struct field match missing"
    binary = : bool
      call reading_code : i32
        call missing_blocked : TaggedReading
      int 0 : i32
  test "enum struct field status predicate"
    call is_ready : bool
      call ready_value : TaggedReading
        int 11 : i32
