본문으로 건너뛰기
토파즈문서
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. }
    기대 출력0이 아닌 종료 코드
    표준 출력 없음.
    $ topaz check example.tpz
    기대 결과

    기대 결과

    거절 단계 check. 종료 코드가 0이 아닙니다.

    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.