Lyricdev
GitHub

LYR-SEM0039

a value returned from a coroutine that returns nothing

error ยท spec 10-concurrency

A return v; with a value stands in a coroutine whose type gives no result, Coroutine<Y> rather than Coroutine<Y, R>.

Explanation

A coroutine hands values out through yield; what its return gives is its result, and the type says whether it has one: Coroutine<Y, R> ends with return r;, Coroutine<Y> with a bare return;.

Yield the value instead, or declare the result type as the second type argument.

Wrong

fn gen(): Coroutine<int> {
    yield 1;
    return 2;
}

fn main(): void {
    let c = gen();
    let _ = c.next();
}
fn gen(): Coroutine<int> {
    yield 1;
    yield 2;
}

fn main(): void {
    let c = gen();
    let _ = c.next();
}