docs

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

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

#E0067: block statement leaves a value

A block-like statement (if, match, a block) gives a value but is not the last expression and has no ;. Add ; to drop the value, or bind it with let.

nabi
fn pick(c: bool) -> i32 {
    if c { 1 } else { 2 }
    3
}
error[E0067]: this block-like statement leaves a value of type `i64` without `;`: a statement must be `()` (add `;` to discard it, or make it the block's last expression)
  --> main.nabi:2:5
   |
 2 |     if c { 1 } else { 2 }
   |     ^^

Make the if the function's value, or end it with ;:

nabi
fn pick(c: bool) -> i32 {
    if c { 1 } else { 2 }
}
println(f"{pick(true)}");
1

Related: E0040 mismatched types

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