Prerequisite
СсылкаUse Topaz 5.21.3 with the SELF compiler and language mode 5.21. Start with First checked and executed program if you have not run a file yet.
1. Reuse one constrained function
СсылкаSave the source as describe.. Each record derives Show; T: Show lets describe call Show.. The calls infer different record types. See Type parameters and bounds.
2. Check the program
СсылкаCheck the constrained function
Ссылкаimport std.iorecord Label derives Show {text: string,}record Count derives Show {value: int,}function describe<T: Show>(value: T) -> string {Show.show(value)}io.writeLine(describe(Label { text: "Topaz" }))io.writeLine(describe(Count { value: 3 }))
describe.tpz: types-ok (2 modules)
describe.tpz: resolve-ok (2 modules)
Ожидаемый результат
Ожидаемый результат
Проверка принимает программу. Код завершения 0.
Наблюдаемые утверждения · Пройдено · 5.21.3
Код завершения 0.
describe.tpz: types-ok (2 modules)describe.tpz: resolve-ok (2 modules)
Нет вывода ошибок.
- Пройдено · expected 0; observed 0
Expected result: checking succeeds. If it fails, follow the reported code to its diagnostic entry and check the function's bound and argument types.
3. Run both calls
СсылкаRun the function with two record types
Ссылкаimport std.iorecord Label derives Show {text: string,}record Count derives Show {value: int,}function describe<T: Show>(value: T) -> string {Show.show(value)}io.writeLine(describe(Label { text: "Topaz" }))io.writeLine(describe(Count { value: 3 }))
Label { text: Topaz }
Count { value: 3 }
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
Label { text: Topaz }Count { value: 3 }
Наблюдаемые утверждения · Пройдено · 5.21.3
Код завершения 0.
Label { text: Topaz }Count { value: 3 }
Нет вывода ошибок.
- Пройдено · expected 0; observed 0
- Пройдено · stdout matches the authored expectation
- Пройдено · stderr matches the authored expectation
Both calls use the same function body.
4. Remove a repeated bound
СсылкаCompare the rejected declaration with describe<T: Show>. The second Show repeats a bound for the same type parameter. Remove + Show and check again. See TPZ5523, the Language rule, and the repaired declaration.
Repeated-bound example
Ссылкаfunction duplicate<T: Show + Show>(value: T) -> T {value}
Ожидаемый результат
Ожидаемый результат
Этап отклонения check. Ненулевой код завершения.
repeated-protocol-bound at
example.tpz:1:30
TPZ5523 points to the second Show at example.. 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-. Document source: 1d6f9265d918.
Verification record
СсылкаPublic Topaz 5.21.3 passed the check and run 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 derived Show representation contract is listed below.
Protocols and implementations defines conformance, protocol calls and derived implementations. Functions and generics defines function type parameters and calls.