error question-context
Оператор ? использован там, где ошибки некуда пробрасывать.
What it means#
e? returns the error of e from the enclosing function (or none for an optional), so the function must be able to carry it: its return type has to be a union with errors, or an optional (§6.5). In a function returning () or a plain type, in a const initialiser, or at a place without an enclosing function, there is nowhere to propagate to.
Example#
@error data BadNumber { text: str }
fn parse(s: str) -> i32 | BadNumber => 0
fn total(s: str) -> i32 {
parse(s)? // <- question-context (total cannot return BadNumber)
}error
question-context
How to fix#
@error data BadNumber { text: str }
fn parse(s: str) -> i32 | BadNumber => 0
fn total(s: str) -> i32 | BadNumber {
parse(s)?
}Declare the error in the return type, or handle the result locally with match, !> or ??.