Skip to content
Playground(another site)

bynk.types.list_element_mismatch

Error A list-literal element has a different type from the list's element type.

A list has one element type, taken from the context if there is one and otherwise from the first element, and every element must have it. [1, 2, "3"] mixes Int and String, and the error is on the element that disagrees. Make the elements one type, or wrap them in a sum type if the list really holds more than one kind of value. An empty [] with no context is bynk.types.uninferable_element_type.

Example

fn scores() -> List[Int] {
[1, 2, "3"] // ✗ a `String` in a `List[Int]`
}
fn scores() -> List[Int] {
[1, 2, 3] // ✓
}

In the Book

See also

  • The grammar rule it governs: list_literal.
  • Every code in its category, Type checking, on the diagnostic index.
  • bynk explain bynk.types.list_element_mismatch shows the same from the installed toolchain, without a network.