Skip to content
Playground(another site)

bynk.resolve.self_outside_method

Error self referenced outside a method or handler.

self is the value a method was called on, so it exists only in the body of a method, declared as fn Type.name(self, …). A plain function has no receiver. Make the function a method of the type, or take the value as an ordinary parameter.

Example

type Counter = { n: Int }
fn read(c: Counter) -> Int {
self.n // ✗ a plain function has no `self`
}
fn Counter.read(self) -> Int { // ✓ a method declares `self`
self.n
}

In the Book

See also

  • The grammar rule it governs: self_expr.
  • Every code in its category, Resolution, on the diagnostic index.
  • bynk explain bynk.resolve.self_outside_method shows the same from the installed toolchain, without a network.