Skip to content
Topaz6.0 · Before release
Download

Search documentation

Specification 6.0 · Not released · Tested product 5.21.3

Use arrow keys to choose a result. Press Enter to open.

Type an API name, diagnostic number, rule, or project topic.

    Tour

    Diagnose and test

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

    Prerequisite

    Link

    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

    Link

    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

    Link
    example.tpzRepeated-bound exampleOpen in Playground
    1. function duplicate<T: Show + Show>(value: T) -> T {
    2. value
    3. }
    Expected outputNonzero exit
    $ topaz check example.tpz · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5523 repeated-protocol-bound at example.tpz:1:30

    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.

    Source evidence

    2. Ask for the explanation

    Link

    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

    Link

    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

    Link
    diagnose-and-test.tpzCheck the repaired programOpen in Playground
    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)
    Recorded outputexit 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 · recorded with topaz 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Observed assertions · passed · 5.21.3

    Exit code 0.

    Observed stdout
    1. diagnose-and-test.tpz: types-ok (2 modules)
    2. diagnose-and-test.tpz: resolve-ok (2 modules)

    No stderr.

    • Passed · expected 0; observed 0
    Source evidence

    4. Execute the assertion

    Link

    Run the assertion with topaz test

    Link
    diagnose-and-test.tpzRun the assertion with topaz testOpen in Playground
    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)
    Recorded outputexit 0
    diagnose-and-test.tpz: test-ok
    
    $ topaz test diagnose-and-test.tpz --compiler self · recorded with topaz 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. diagnose-and-test.tpz: test-ok
    Observed assertions · passed · 5.21.3

    Exit code 0.

    Observed stdout
    1. diagnose-and-test.tpz: test-ok

    No stderr.

    • Passed · expected 0; observed 0
    • Passed · stdout matches the authored expectation
    • Passed · stderr matches the authored expectation
    Source evidence

    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

    Link

    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

    Link

    TPZ5523: Duplicate protocol bound

    Functions and generics

    check

    Menu

    Download