LYR-SEM0158
a place outlives the call that handed it over
A coroutine function or a generator lambda takes a place parameter, or a lambda captures a place parameter.
Explanation
A place belongs to the call and ends with it. A coroutine's or generator's body runs after the call that created it has returned, and a lambda may be called after the function it was made in has returned, so neither may hold the caller's place.
Take the parameter by value, or read the place into a local and capture or yield that.
Wrong
fn counts(&n: int): Coroutine<int> {
yield n;
}
fn main(): void {
var x = 1;
let _ = counts(&x);
}
Right
fn counts(n: int): Coroutine<int> {
yield n;
}
fn main(): void {
let x = 1;
let _ = counts(x);
}