docs

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

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

#E0050: ref parameter and argument mismatch

A ref parameter takes an argument written ref x, which names a variable or a field of one; a plain parameter takes a plain argument. The same variable cannot go to two ref parameters of one call. Write ref exactly where the parameter has it.

nabi
fn inc(ref n: i32) { n += 1; }

let c = 0;
inc(c);
error[E0050]: parameter `n` of `inc` is `ref` - pass `ref c` at the call site
  --> main.nabi:4:1
   |
 4 | inc(c);
   | ^^^^^^

Write ref at the call too:

nabi
fn inc(ref n: i32) { n += 1; }

let c = 0;
inc(ref c);
println(f"{c}");
1

Related: E0048 wrong number of arguments, E0057 invalid assignment

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