#E0138: pub function signature not written out
A pub or pub(pkg) function is called from other modules, so its signature is written out, not inferred from the body. Give every parameter a type, x: i32 (or a type parameter, fn f<T>(x: T), for any type). Without -> it returns (); when the body gives a value, write its type, -> i32, as the fix-it shows. Exempt: private and pub(sub) functions keep inference; trait impl methods take the trait's types; self and a variadic ...T parameter need no type; main and generators may omit ->; a function without a body (extern) is declared as written.
nabi
pub fn double(x: i32) { x * 2 }
println(f"{double(4)}");
error[E0138]: `pub fn double` has no `->`, so it returns `()`, but its body gives `i32` --> main.nabi:1:25 | 1 | pub fn double(x: i32) { x * 2 } | ^^^^^ | = help: write `-> i32` before the body
Write the return type:
nabi
pub fn double(x: i32) -> i32 { x * 2 }
println(f"{double(4)}");
8
Related: E0042 type annotations needed, E0040 mismatched types
Found a mistake? Edit this page on GitHub. Last updated