OxL Reference

error cannot-infer

error Standard: [§3]

What it means#

Type inference is local (§3). When nothing in the context fixes a type, for example an empty list that is never used with elements, a generic argument not present in any parameter, or an ambiguous call (§4.8), the compiler asks for an annotation.

Example#

oxl✓ checked in CI
fn make<T>() -> T where T: Default => T.default()

fn main() io {
  let x = make()      // <- cannot-infer
  print("{x}")
}
error
cannot-infer

How to fix#

oxl✓ checked in CI
fn make<T>() -> T where T: Default => T.default()

fn main() io {
  let x: i32 = make()
  print("{x}")
}

Add a type annotation to the binding, or pass explicit generic arguments (f<i32>()).

See also#

OxL 1.0.0-beta · Documentation version 1.0.0-beta© OxwaldLink · generated from the Standard, the std sources and the guides