docs

#E0055: literal fits several types

An unsuffixed literal could be any of several types the call or operator accepts. When one of them is the literal's default (i64 for an integer, f64 for a float), the literal takes it; otherwise its type is unclear. Add a suffix (1i32) or an as.

nabi
struct X { v: i64; }
impl From<i32> for X { fn from(x: i32) -> X { X { v: x as i64 } } }
impl From<u8> for X { fn from(x: u8) -> X { X { v: x as i64 } } }

let x = X::from(5);
error[E0055]: `X::from`: the literal fits several `From` impls of `X` (`i32`, `u8`); add a suffix or `as`
  --> main.nabi:5:9
   |
 5 | let x = X::from(5);
   |         ^^^^^^^^^^

Add a suffix:

nabi
struct X { v: i64; }
impl From<i32> for X { fn from(x: i32) -> X { X { v: x as i64 } } }
impl From<u8> for X { fn from(x: u8) -> X { X { v: x as i64 } } }

let x = X::from(5i32);
println(f"{x.v}");
5

Related: E0042 type annotations needed, E0004 literal out of range for its type

Found a mistake? Edit this page on GitHub. Last updated