Prerequisite
LinkUse 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
LinkSave 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
LinkCheck the constrained function
Linkimport 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)
Expected result
Expected result
Checking accepts the program. Exit code 0.
Observed assertions · passed · 5.21.3
Exit code 0.
describe.tpz: types-ok (2 modules)describe.tpz: resolve-ok (2 modules)
No stderr.
- Passed · expected 0; observed 0
Source evidence
- parseFunctionTypeParameters at
b48527d0a174· 100-146 - builtinProtocolDefinition at
b48527d0a174· 100-112 - typeConforms and checkFunctionBounds at
b48527d0a174· 2244-2335 - Generic Show sample at
b48527d0a174· 1-28
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
LinkRun the function with two record types
Linkimport 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 }
Expected result
Expected result
Execution completes. Exit code 0.
Label { text: Topaz }Count { value: 3 }
Observed assertions · passed · 5.21.3
Exit code 0.
Label { text: Topaz }Count { value: 3 }
No stderr.
- Passed · expected 0; observed 0
- Passed · stdout matches the authored expectation
- Passed · stderr matches the authored expectation
Source evidence
- parseFunctionTypeParameters at
b48527d0a174· 100-146 - builtinProtocolDefinition at
b48527d0a174· 100-112 - typeConforms and checkFunctionBounds at
b48527d0a174· 2244-2335 - Generic Show sample at
b48527d0a174· 1-28 - docs/samples/language/functions-generics.stdout at
b48527d0a174· 1-3
Both calls use the same function body.
4. Remove a repeated bound
LinkCompare 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
Linkfunction duplicate<T: Show + Show>(value: T) -> T {value}
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5523repeated-protocol-bound atexample.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.
Source evidence
- Functions and generics manuscript at
d61f9fd0efb0· 5.3D - checkFunctionDeclarationInner bound iteration at
151141d7bb44· 177-191
Verification record
LinkPublic 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.