OxL Справочник OxL
РусскийEnglish

error question-context

error Стандарт: [§6.5]

Оператор ? использован там, где ошибки некуда пробрасывать.

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#

oxl✓ проверяется в CI
@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#

oxl✓ проверяется в CI
@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 ??.

See also#

OxL 1.0.0-beta · Версия документации 1.0.0-beta© OxwaldLink · сгенерировано из Стандарта, исходников std и руководства