العرضar

يتطلب

Translation status: العربية reader-locale proof. Term names and code fences follow the ar pack; supporting prose may still be English.

Require a condition or throw a recoverable error.

Aliases: require

Syntax: يتطلب <expression> ارم <expression>

Category#

errors

Examples#

radix/corpus/meta/requirit.fab (canonical · keyword)#

Require a condition or throw a recoverable error.

# =============================================================================
# يتطلب — Require a condition or throw a recoverable error.
# =============================================================================
#
# What this teaches:
#   • Recoverable guard — `require <condition> throw <error>` throws into the
#     function's ⇥ channel when the condition is false (en surface of `يتطلب`)
#   • Twin of `أكد` — `assert` is fatal; `require` is catchable by `catch`
#   • Typed payload — the false-path expression is a `variant` with `causa`,
#     the same shape used at constructor guard ladders
#
# Common mistakes:
#   • Using `require` in a function without `⇥ E` — SEM010 `iace_requires_alternate_exit`, same as `throw`
#   • Treating `require` as a test-capability gate — it is a statement, not a named fixture on `test`
#
# See also: أكد, ارم, التقط, ⇥
# =============================================================================

# يتطلب — recoverable require statement
#
# require <condition> throw <error>
#
# GRAMMAR:
#   requiritStmt :← 'يتطلب' expr 'ارم' expr
#
# EXPECTED OUTPUT:
#   empty — success-path main only (requirit.expected)

union GuardError {
    Invalid { string causa }
}

fn guarded(int value) → int ⇥ GuardError {
    require value ≻ 0 throw variant Invalid { causa = "value must be positive" }
    return value
}

main {
    do {
        const int ok ← guarded(1)
        assert ok ≡ 1
    }
    catch err {
        assert false panic "success path must not throw"
    }
}

test "false path is recoverable" {
    do {
        const int dropped ← guarded(0)
        assert false panic "false path must throw"
    }
    catch err {
        # recovered — require entered ⇥ and catch intercepted it
    }
}