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

Docs

XO0434: an invalid catch-all variant of a valued enum

error · reported by the checker

A valued enum’s variants are field-less, except one: its last variant may keep the values no other variant names, as Unknown(value: Str) (one field of the enum’s value type, Str or Int, and no = value). E.from(v) returns it for an unlisted value, value() is its field, all() leaves it out, and derive Json reads and writes the value it keeps. Move the variant last, give it one field of the value type, or drop its value. See core 2.3 and decisions 0269 and 0493.

Example

enum StorageClass: Str {
  Unknown(value: Str)
  Standard = "STANDARD"
}

Fix

enum StorageClass: Str {
  Standard = "STANDARD"
  Unknown(value: Str)
}

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