LYR-SEM0181
an inline function keeps a function parameter
Inside an inline fn, a parameter of function type is used other than by calling it or passing it to another inline fn: returned, stored, captured or passed to an ordinary function.
Explanation
An inline fn is set in place at every call, and the lambda it is handed is set in place with it. The lambda exists only where it is called; nothing is there to keep, return or capture.
Call the parameter inside the inline function, or make the function an ordinary fn.
Wrong
inline fn keep(f: fn() -> void): fn() -> void {
return f;
}
fn main(): void {
let g = keep(() => {});
g();
}
Right
inline fn twice(f: fn() -> void): void {
f();
f();
}
fn main(): void {
var n = 0;
twice(() => { n += 1; });
assert(n == 2);
}