Skip to content
Topaz6.0 · Before release
Download

Search documentation

Specification 6.0 · Not released · Tested product 5.21.3

Use arrow keys to choose a result. Press Enter to open.

Type an API name, diagnostic number, rule, or project topic.

    Diagnostics

    TPZ5026: Refutable let pattern

    A let pattern could fail to match at runtime.

    Diagnostic and cause

    Link

    Refutable let pattern

    Family
    topaz
    Phase
    check
    Code
    TPZ5026

    Cause and conditions

    A let destructuring pattern must match every value of the initializer's type. Use match or if let when a constructor pattern can fail.

    Response

    Use if let or match to handle both outcomes, or choose an irrefutable pattern.

    Source evidence

    Compiler phase: check.

    Compiler explanation: A let pattern could fail to match at runtime.

    Message templates. The marker ⟨value⟩ stands for text computed for the reported program.

    • refutable pattern in let: it does not match every value of the type — use if let to handle the non-matching case Source

    A let destructuring pattern must match every value of the initializer's type. Use match or if let when a constructor pattern can fail.

    Rulediagnostics.tpz5026.p5.rule

    Refutable let pattern

    A let destructuring pattern must match every value of the initializer's type. Use match or if let when a constructor pattern can fail.

    Source evidence

    Response

    Link

    Use if let or match to handle both outcomes, or choose an irrefutable pattern.

    Reproduction and verification

    Link

    Rejected program

    Link
    example.tpzRejected programOpen in Playground
    1. let maybe: Option<int> = None()
    2. let Some(value) = maybe
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5026 diagnostics-refutable-let-pattern at example.tpz:2:5
    Source evidence

    Repaired program

    Link
    example.tpzRepaired program
    1. let maybe: Option<int> = None()
    2. let value: int = match (maybe) {
    3. case Some(number) => number
    4. case None() => 0
    5. }
    Expected outputexit 0
    $ topaz check example.tpz · target product 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Source evidence

    Menu

    Download