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

    TPZ4002: Division or remainder by zero

    An integer division or remainder operation used zero as the divisor.

    Diagnostic and cause

    Link

    Division or remainder by zero

    Family
    topaz
    Phase
    run
    Code
    TPZ4002

    Cause and conditions

    Integer division or remainder faults when its evaluated divisor is zero.

    Response

    Require a nonzero divisor before dividing or taking a remainder. The repair passes one to the same function.

    Source evidence

    Compiler phase: runtime.

    Compiler explanation: An integer division or remainder operation used zero as the divisor.

    Message templates are Pending. The explanation above is not an observed CLI message.

    Observed for the candidate in Topaz 5.21.3. Execution

    • error[TPZ4002]: integer division by zero

    The divisor of an int division or remainder evaluates to zero. The shared checked arithmetic leaf detects this before performing the operation.

    Rulediagnostics.tpz4002.rule

    Trigger and repair

    Integer division or remainder faults when its evaluated divisor is zero.

    Source evidence

    Response

    Link

    Require a nonzero divisor before dividing or taking a remainder. The repair passes one to the same function.

    Reproduction and verification

    Link

    Product diagnostic test

    Link
    example.tpzProduct diagnostic testOpen in Playground
    1. function divide(divisor: int) -> int {
    2. 42 / divisor
    3. }
    4. divide(0)
    target product 5.21.3
    Expected result

    Expected result

    The separate diagnostic product test validates this command, runtime diagnostic, or filesystem setup. The shared example runner does not execute that assertion plan.

    Run topaz run example.tpz --language-version 5.21.

    Expect exit status 1, empty standard output, and TPZ4002.

    The divisor of an int division or remainder evaluates to zero. The shared checked arithmetic leaf detects this before performing the operation.

    The primary location is example.tpz:2:5.

    Expect exactly one diagnostic.

    The diagnostic product test checks these expectations with the same files and command.

    Source evidence

    Corrected program

    Link
    example.tpzCorrected program
    1. function divide(divisor: int) -> int {
    2. 42 / divisor
    3. }
    4. divide(1)
    Expected outputexit 0
    No stdout.
    $ topaz run example.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

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

    Source evidence

    Menu

    Download