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

    TPZ2004: Invalid defer body

    A defer statement body is neither a block nor a call expression.

    Diagnostic and cause

    Link

    Invalid defer body

    Family
    topaz
    Phase
    parse
    Code
    TPZ2004

    Cause and conditions

    The body of a defer statement must be a block (topaz.decision.defer-block-only.1).

    Response

    Place the deferred work in a block.

    Source evidence

    Compiler phase: parse.

    Compiler explanation: A defer statement body is neither a block nor a call expression.

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

    • defer takes a block or a call Source

    Observed for the candidate in Topaz 5.21.3. Execution

    • error[TPZ2004]: defer takes a block or a call

    A defer statement has a body that is not a block.

    Rulediagnostics.tpz2004.rule

    Trigger and repair

    The body of a defer statement must be a block (topaz.decision.defer-block-only.1).

    Source evidence

    Response

    Link

    Place the deferred work in a block.

    Reproduction and verification

    Link

    Rejected program

    Link
    example.tpzRejected programOpen in Playground
    1. defer 1
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz · target product 5.21.3
    Expected result

    Expected result

    Rejection during parse. Nonzero exit.

    • TPZ2004 diagnostic-tpz2004 at example.tpz:1:7

    The expected diagnostic, cause, source location, and accompanying diagnostics are specified below. The verification status records whether this program has been run.

    Source evidence

    Corrected program

    Link
    example.tpzCorrected program
    1. defer {}
    Expected outputexit 0
    $ topaz check example.tpz · target product 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    This program applies the repair described above. The verification status records whether it has been run.

    Source evidence

    Menu

    Download