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

Docs

XO0431: a tagged enum's variant whose payload is not an object

error · reported by the checker

An internally tagged enum writes its variant’s name under the tag key and the variant’s fields beside it, in one object: {"type":"say","text":"hi"}. A variant with named fields, or with one field that is a struct, has fields to put there; a variant holding an Int, a Str or a List does not. Give the variant named fields, wrap a struct, or add content: "KEY" to the derive, which puts every payload under its own key ({"type":"count","value":3}). See core 2.3 and decision 0478.

Example

enum Msg {
  Count(from Int)
  Ping
} derive Json(tag: "type")

Fix

enum Msg {
  Count(n: Int)
  Ping
} derive Json(tag: "type")

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