Skip to content
TE144 · Type · error

Write through a getter-only field accessor

The field declares `get` but no `set`, so assignments after construction are not allowed.

Why this fires

A field that declares get but no set is read-only after construction. Struct literals and field defaults still initialize the stored value directly, but ordinary assignments must go through a setter.

struct Account {
  balance: int {
    get
  }
}

let account = Account { balance: 10 }
account.balance = 20 // error[TE144]

Compound assignments such as += and ??= also require a setter.

Fix it

Add a setter when mutation is part of the field's API:

balance: int {
  get
  set(value) {
    field = value
  }
}

Otherwise, remove the assignment and expose the state change through a method that preserves the struct's invariants.

See also

Search Zolo

9 results

en