Lyricdev
GitHub

LYR-PAR0056

a 'throws' behind a function type that is a return type

error ยท spec 06-errors

A declaration's or lambda's return type is a function type without parentheses, followed by throws: fn make(): fn() -> int throws E.

Explanation

The throws could be the set of the function returned or of the one that returns it, and a reader cannot tell. Parentheses decide: (fn() -> int throws E) returns a function that throws, (fn() -> int) throws E gives the set to the one that returns it.

Put the parentheses where you mean them.

Wrong

class Negative :: [Error] { fn message(): string { return "negative"; } }

fn fail(): int throws Negative {
    throw Negative { };
}

fn make(): fn() -> int throws Negative {
    return fail;
}

fn main(): void {
}
class Negative :: [Error] { fn message(): string { return "negative"; } }

fn fail(): int throws Negative {
    throw Negative { };
}

fn make(): (fn() -> int throws Negative) {
    return fail;
}

fn main(): void {
    let _ = make();
}