本页尚未翻译,以下为英文原文。
#E0040: mismatched types
A value of one type is used where another type is expected: an argument, a let with a type, a return value, or the value of a function whose body drops it with ;. Convert the value (as i32, .to_str()), change the expected type, or remove the ;.
nabi
fn half(x: i32) -> i32 { x / 2 }
println(f"{half(3.0)}");
error[E0040]: mismatched types: argument `x` of `half` expects `i32`, found `f64` --> main.nabi:2:17 | 2 | println(f"{half(3.0)}"); | ^^^ | = help: convert it with `as`: `3.0 as i32`
Pass an i32, or convert explicitly with as:
nabi
fn half(x: i32) -> i32 { x / 2 }
println(f"{half(3)}");
1
Nabi has no implicit numeric conversions, so f64 is not accepted where i32 is expected (2.14 Casts and conversions). Most messages add a help: line that says what to write instead.
Related: E0041 branches of different types, E0053 invalid cast, E0054 operator cannot be applied
Found a mistake? Edit this page on GitHub. Last updated