Skip to content
Playground(another site)

bynk.json.encode_plain_generic

Error Json.encodePlain is given a value whose type mentions a type parameter. A generic value encodes through its Codable witness, which always writes Option in the tagged form, so plain encoding is available only at a concrete type.

Json.encodePlain writes an Option as its value or null, which it can do only when it knows the type. A generic function is compiled once for every T, and encodes through its Codable witness, which always writes Option in the tagged form {"kind":"Some",…}. Encode at a concrete type, or use Json.encode if the tagged form will do. A concrete type that is ambiguous in plain form is bynk.json.nested_option_plain.

Example

fn plain[T: Codable](v: T) -> String { Json.encodePlain(v) } // ✗ `T` could be an `Option`
fn plain(v: Option[Int]) -> String { Json.encodePlain(v) } // ✓ a concrete type

In the Book

See also

  • Every code in its category, Other, on the diagnostic index.
  • bynk explain bynk.json.encode_plain_generic shows the same from the installed toolchain, without a network.