Перейти к содержимому
Топаз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. }
    Ожидаемый выводНенулевой код завершения
    $ topaz check example.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

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

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

    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 →

    Меню

    Загрузка →