Xo is experimental. The source is now public on GitHub, or try Xo in your browser.
Menu · XO0432

Docs

XO0432: `to:` or `from:` names no function of the module

error · reported by the checker

A type with its own JSON form travels as P: encoding calls to to make the P, decoding decodes a P and calls from. Both are plain functions declared in the type’s module, not methods, not generic, and not imported from another module, so the conversion lives beside the type. Declare the function, or fix its name. See core 2.3 and decision 0478.

Example

struct Money {
  minor: Int
} derive Json(via: Int, to: money_minor, from: money_of)

fn money_of(n: Int) -> Money { Money{minor: n} }

Fix

struct Money {
  minor: Int
} derive Json(via: Int, to: money_minor, from: money_of)

fn money_minor(m: Money) -> Int { m.minor }

fn money_of(n: Int) -> Money { Money{minor: n} }

Run xo explain XO0432 for this text in a terminal, or see section 10.6 of the specification.