docs

你正在阅读 v0.1.0 的文档。Nabi 0.1.0 已不再提供支持。 最新版本:v0.1.3 →

本页尚未翻译,以下为英文原文。

#E0051: invalid spread argument

f(..x) spreads a tuple, List, Slice, array or Dict<str, V> into the arguments, and needs a callee known at compile time. Spread one of those, or pass the arguments one by one.

nabi
fn sum(xs: ...i32) -> i32 { 0 }

let n = 3;
println(f"{sum(..n)}");
error[E0051]: spread into a variadic `...T` needs a tuple, a `List`, a `Slice` or an array, found `i64`
  --> main.nabi:4:12
   |
 4 | println(f"{sum(..n)}");
   |            ^^^^^^^^

Spread a collection:

nabi
fn sum(xs: ...i32) -> i32 {
    let t = 0;
    for x in xs { t += x; }
    t
}

let ns = [1, 2, 3];
println(f"{sum(..ns)}");
6

Related: E0048 wrong number of arguments

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