docs

您正在閱讀 v0.1.0 的文件。Nabi 0.1.0 已停止支援。 最新版本:v0.1.3 →

本頁尚未翻譯,以下為英文原文。

#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