docs

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

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

#E0023: invalid function signature

The function's parameters or return type break a rule: a variadic ... that is not last, a ref parameter on a coroutine or a fn value, a rethrows without a throwing parameter, or a signature a test attribute does not allow. The message names the rule; change the signature to fit it.

nabi
fn f(a: i32, ...) -> i32 { a }
error[E0023]: `f`: a C variadic `...` parameter is only allowed on a declaration in an `extern "C" { .. }` block
  --> main.nabi:1:1
   |
 1 | fn f(a: i32, ...) -> i32 { a }
   | ^^

A C variadic belongs to extern declarations. A Nabi function takes any number of arguments with ...T:

nabi
fn sum(xs: ...i32) -> i32 {
    let t = 0;
    for x in xs { t += x; }
    t
}
println(f"{sum(1, 2, 3)}");
6

Related: E0024 invalid generic parameters, E0036 invalid program entry point

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