Перейти к содержимому
Топаздокументация
6.05.21

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

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

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

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

    Загрузка →

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

    A range pattern with two literal int endpoints is rejected when its interval contains no value.

    Diagnostic and cause

    Range pattern matches no value

    Семейство
    topaz
    Этап
    check
    Код
    TPZ5714

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

    An integer range pattern compares an int scrutinee with int endpoints. The value must be greater than or equal to the lower endpoint and satisfy the upper comparison. Both comparisons must succeed. The pattern introduces no bindings.

    Pattern operatorUpper comparison
    ..Less than or equal to the upper endpoint
    ..<Less than the upper endpoint

    Действия

    Choose endpoints and an operator that describe a nonempty interval, or remove the empty pattern. Use (0 .. 0) when the single value 0 is intended. An exclusive upper endpoint equal to the lower endpoint matches nothing.

    Topaz 6.0 reports TPZ5714 during checking. Its primary location is the empty range pattern. The diagnostic retains both written endpoints and the operator. Endpoint type checking and TPZ5001 literal-range checking run first. No product execution is recorded for these examples.

    A literal exclusive range (a ..< b) is empty when a is greater than or equal to b. A literal inclusive range (a .. b) is empty when a is greater than b. Negative literals and endpoints in simple grouping parentheses follow the same rule. Every pattern position is covered, including alternatives, nested patterns, for patterns, and destructuring.

    The integer range rule defines this rejection under empty-range-patterns.1. Computed endpoints are not checked for static emptiness. Their evaluation follows range-endpoint-evaluation.1, and an empty computed interval simply does not match. TPZ5713 continues to diagnose complete coverage by earlier unguarded match cases. It does not replace TPZ5714 for an empty subpattern.

    Response

    Choose endpoints and an operator that describe a nonempty interval, or remove the empty pattern. Use (0 .. 0) when the single value 0 is intended. An exclusive upper endpoint equal to the lower endpoint matches nothing.

    Reproduction and verification

    Rejected empty range

    example.tpzRejected empty rangeОткрыть песочницу →
    1. function classify(value: int) -> int {
    2. match (value) {
    3. case (0 ..< 0) => 1
    4. case _ => 0
    5. }
    6. }
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz
    Ожидаемый результат

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

    Этап отклонения check. Ненулевой код завершения.

    The exclusive range (0 ..< 0) contains no int. Its two literal endpoints and operator identify the invalid pattern.

    Repaired nonempty range

    example.tpzRepaired nonempty rangeОткрыть песочницу →
    1. function classify(value: int) -> int {
    2. match (value) {
    3. case (0 .. 0) => 1
    4. case _ => 0
    5. }
    6. }
    Ожидаемый выводКод завершения 0
    $ topaz check example.tpz
    Ожидаемый результат

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

    Проверка принимает программу. Код завершения 0.

    The inclusive range (0 .. 0) contains one int. The fallback handles every other input.