본문으로 건너뛰기
토파즈6.0 · 출시 전
다운로드 →

문서 검색

명세 6.0

방향키로 결과를 고르고 Enter를 눌러 여세요.

API 이름, 진단 번호, 규칙 또는 프로젝트 주제를 입력하세요.

    투어

    진단과 테스트

    Use a diagnostic code, explain the failure, repair the program, and test the result.

    Prerequisite

    링크

    Use Topaz 5.21.3 with the SELF compiler and language mode 5.21. This walkthrough starts with a repeated protocol bound and ends with a checked assertion.

    1. Read the diagnostic code

    링크

    The rejected declaration repeats Show for one type parameter. Check it and use TPZ5523 to find the diagnostic explanation. Its recorded output comes from the same example used by the Language reference.

    Repeated-bound example

    링크
    example.tpzRepeated-bound example플레이그라운드 열기 →
    1. function duplicate<T: Show + Show>(value: T) -> T {
    2. value
    3. }
    기대 출력0이 아닌 종료 코드
    $ topaz check example.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

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

    TPZ5523 points to the second Show at example.tpz:1:30. Each later occurrence for the same type parameter is diagnosed. Checking continues, so other applicable diagnostics may also appear. Remove the repeated bound to correct this program. The earlier receipt predates the location assertion; CI must execute this revision.

    Observed: The authored exit and diagnostic-cause assertions passed. The primary-location assertion and additional-diagnostics policy remain pending. Recorded with Topaz 5.21.3 in run 42147883818 at 2026-11-06T02:04:56.5052224Z. Document source: 1d6f9265d918.

    2. Ask for the explanation

    링크

    Run topaz explain TPZ5523. Expected result: the command explains the repeated protocol bound and recommends removing the repeated name. This command's execution remains Pending in this walkthrough.

    3. Repair the declaration and check

    링크

    Save the complete source as diagnose-and-test.tpz. The declaration now contains one Show bound. Sample derives Show, so the call uses a record that provides the requested protocol. The assertion compares the returned record's value with 3. See Type parameters and bounds for the rules.

    Check the repaired program

    링크
    diagnose-and-test.tpzCheck the repaired program플레이그라운드 열기 →
    1. import std.test
    2. record Sample derives Show {
    3. value: int,
    4. }
    5. function duplicate<T: Show>(value: T) -> T {
    6. value
    7. }
    8. let result = duplicate(Sample { value: 3 })
    9. test.assertEq(result.value, 3)
    기록된 출력종료 코드 0
    diagnose-and-test.tpz: types-ok (2 modules)
    diagnose-and-test.tpz: resolve-ok (2 modules)
    
    $ topaz check diagnose-and-test.tpz --compiler self · 기록에 사용한 토파즈 5.21.3
    기대 결과

    기대 결과

    검사가 프로그램을 받아들입니다. 종료 코드 0.

    관측한 단언 · 통과 · 5.21.3

    종료 코드 0.

    관측한 표준 출력
    1. diagnose-and-test.tpz: types-ok (2 modules)
    2. diagnose-and-test.tpz: resolve-ok (2 modules)

    표준 오류 출력 없음.

    • 통과 · expected 0; observed 0

    4. Execute the assertion

    링크

    Run the assertion with topaz test

    링크
    diagnose-and-test.tpzRun the assertion with topaz test플레이그라운드 열기 →
    1. import std.test
    2. record Sample derives Show {
    3. value: int,
    4. }
    5. function duplicate<T: Show>(value: T) -> T {
    6. value
    7. }
    8. let result = duplicate(Sample { value: 3 })
    9. test.assertEq(result.value, 3)
    기록된 출력종료 코드 0
    diagnose-and-test.tpz: test-ok
    
    $ topaz test diagnose-and-test.tpz --compiler self · 기록에 사용한 토파즈 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. diagnose-and-test.tpz: test-ok
    관측한 단언 · 통과 · 5.21.3

    종료 코드 0.

    관측한 표준 출력
    1. diagnose-and-test.tpz: test-ok

    표준 오류 출력 없음.

    • 통과 · expected 0; observed 0
    • 통과 · stdout matches the authored expectation
    • 통과 · stderr matches the authored expectation

    Expected result: the command exits successfully and prints diagnose-and-test.tpz: test-ok. test.assertEq checks the returned value while the program runs. If the assertion fails, inspect the function result and the expected value, then rerun the test.

    Verification record

    링크

    Public Topaz 5.21.3 passed the repaired check and test expectations in Docs run 42224592687, attempt 2. The recorded results were compared with this page's current product assertions using unchanged fixture files, invocations and expectations. The shared TPZ5523 rejection specifies its source location and additional-diagnostic policy. Its current example revision awaits a product run. The test output and equality-assertion contracts are listed below.

    See test, explain and std.test.assertEq for their current reference entries.

    Next steps

    링크

    TPZ5523: Duplicate protocol bound →

    Functions and generics →

    check →

    메뉴

    다운로드 →