Skip to content
TE145 · Type · error

Recursive access inside a field accessor

Accessing `self.<same-field>` inside its accessor would recurse; use the contextual backing name `field`.

Why this fires

Inside an accessor, self.<same-field> means the public property and would invoke that accessor again forever. Use the contextual name field to read or write the stored backing slot.

struct Account {
  balance: int {
    get {
      return self.balance // error[TE145]
    }
  }
}

Fix it

Replace the recursive access with field:

get {
  return field
}

The diagnostic includes a machine-applicable edit for this replacement. Accessing a different field through self remains valid and follows that field's accessor normally.

See also

Search Zolo

9 results

en