Skip to content
Playground(another site)

bynk.types.uninferable_element_type

Error An empty [] (or List.empty() / Map.empty()) has no expected type to infer its element type from.

An empty [], List.empty(), Set.empty() or Map.empty() has no elements to take a type from, and the compiler will not guess, because the element type becomes part of the type of everything the collection touches. Give it one: annotate the binding, as let xs: List[Int] = [], or use the empty value where a type is expected, such as an argument or a return value.

Example

fn count() -> Int {
let xs = [] // ✗ a list of what?
xs.length()
}
fn count() -> Int {
let xs: List[Int] = [] // ✓
xs.length()
}

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.uninferable_element_type shows the same from the installed toolchain, without a network.