kw invariant
Contextual keyword — body of data (§4.2)
The list of words: §1.4
Syntax
Member = Field | "embed" Type | "invariant" Expr ;Grammar: App. A
Defined in
- 4.2 data — A field: visibility?
- 1.4 Keywords — Reserved (cannot be used as names)
- 4.3 Construction and constructors — Literal. T{ f1: e1, f2, ..base }
- 6.7 Contracts — requires is checked on entry, ensures on exit (result is the return value, old(e) is the value of e on entry), invariant (§4.2) — after cons
- 9.4 Decoding and validation — A missing required field → DecodeError.Missing.
Examples
pub(api) data User {
pub(api) id: UserId
pub(api) name: Name
pub(api) email: Email? @since(2)
role: Role = Role.User
createdAt: Time = now()
invariant name != "admin" || role == Role.Admin
}— 4.2 data
Related diagnostics
unknown-field, bad-init, missing-field, must-close, positional-literal, sealed-literal, contract