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

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

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

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

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

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

    A runtime index operation addressed a position outside the collection/string bounds.

    Diagnostic and cause

    Ссылка

    Index out of bounds

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

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

    Reading an Array at a computed int index less than zero or at least the array length faults during execution.

    Действия

    Use an index from zero through length minus one, or test the index before the read. The repaired example reads index zero of a one-element Array.

    Compiler phase: runtime.

    Compiler explanation: A runtime index operation addressed a position outside the collection/string bounds.

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

    Observed for the candidate in Topaz 5.21.3. Execution

    • error[TPZ4001]: index 1 is out of bounds for an array of length 1

    The evaluated int index is not a valid position in the Array. Array indices start at zero and must be less than the current length; invalid reads fault instead of clamping or wrapping.

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

    Trigger and repair

    Reading an Array at a computed int index less than zero or at least the array length faults during execution.

    Response

    Ссылка

    Use an index from zero through length minus one, or test the index before the read. The repaired example reads index zero of a one-element Array.

    Reproduction and verification

    Ссылка

    Product diagnostic test

    Ссылка
    example.tpzProduct diagnostic testОткрыть песочницу →
    1. function readAt(index: int) -> int {
    2. let values = [10]
    3. values[index]
    4. }
    5. readAt(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 TPZ4001.

    The evaluated int index is not a valid position in the Array. Array indices start at zero and must be less than the current length; invalid reads fault instead of clamping or wrapping.

    The primary location is example.tpz:3: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 readAt(index: int) -> int {
    2. let values = [10]
    3. values[index]
    4. }
    5. readAt(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.

    Меню

    Загрузка →