Перейти к содержимому
Топаз6.0 · До релиза
Загрузка →

Поиск в документации

Спецификация 6.0

Выберите результат стрелками и нажмите Enter, чтобы открыть его.

Введите имя API, номер диагностики, правило или тему проекта.

    Диагностика TPZ4004

    A checked integer operation exceeded the int range.

    Diagnostic and cause

    Ссылка

    Integer overflow

    Семейство
    topaz
    Этап
    run
    Код
    TPZ4004

    Причина и условия

    An int addition whose mathematical result is outside the signed 64-bit int range faults at the addition expression. The range failures specified by Duration values use the same runtime diagnostic, TPZ4004.

    Действия

    Check that the intended result fits in int, or change the arithmetic representation. The repair adds zero to the maximum int value and stays at the representable boundary.

    Compiler phase: runtime.

    Compiler explanation: A checked integer operation exceeded the int range.

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

    Observed for the candidate in Topaz 5.21.3. Execution

    • error[TPZ4004]: integer addition overflows

    An int operation produces a result outside the signed 64-bit range, or a Duration operation violates the range rules in Duration values.

    Правилоdiagnostics.tpz4004.rule

    Trigger and repair

    An int addition whose mathematical result is outside the signed 64-bit int range faults at the addition expression. The range failures specified by Duration values use the same runtime diagnostic, TPZ4004.

    Причина

    Duration range failures use the existing integer overflow diagnostic. One code describes an arithmetic result that cannot be represented.

    Response

    Ссылка

    Check that the intended result fits in int, or change the arithmetic representation. The repair adds zero to the maximum int value and stays at the representable boundary.

    Reproduction and verification

    Ссылка

    Product diagnostic test

    Ссылка
    example.tpzProduct diagnostic testОткрыть песочницу →
    1. function add(left: int, right: int) -> int {
    2. left + right
    3. }
    4. add(9223372036854775807, 1)
    Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    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 TPZ4004.

    The evaluated operands of an int operation produce a result outside the representable signed 64-bit range. The reproduced case adds one to the maximum int value; the operation faults instead of wrapping.

    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.

    Corrected program

    Ссылка
    example.tpzCorrected program
    1. function add(left: int, right: int) -> int {
    2. left + right
    3. }
    4. add(9223372036854775807, 0)
    Ожидаемый выводКод завершения 0
    Нет стандартного вывода.
    $ topaz run example.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

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

    Меню

    Загрузка →