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.

    Language · chapter 15 · 1 rules

    Derived Show output

    Use derived Show to inspect record values. The output includes the record name, declared fields, and rendered field values.

    Rules

    Link
    Ruletopaz.rule.derived-show.record-output

    Derived record representation

    For a record that derives Show, Show.show(value) returns its record name and fields in declaration order. A nonempty record uses Name { field: value, field: value }; an empty record uses Name {}. Each field uses the standard value rendering, so string fields appear without added quotes. A record without a Show conformance is rejected with TPZ5522. A manual Show implementation supplies its own method result.

    Why

    The record name and field names expose the value's structure. Declaration order makes the display stable across construction sites, and nested values use the shared renderer.

    Source evidence

    Examples

    Link

    Render declared fields and an empty record

    Link
    derived-show.tpzRender declared fields and an empty recordOpen in Playground
    1. import std.io
    2. record Pair derives Show { z: int, a: string }
    3. record Empty derives Show {}
    4. io.writeLine(Show.show(Pair { a: "Topaz", z: 3 }))
    5. io.writeLine(Show.show(Empty {}))
    Expected outputexit 0
    Pair { z: 3, a: Topaz }
    Empty {}
    
    $ topaz run derived-show.tpz --compiler self · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. Pair { z: 3, a: Topaz }
    2. Empty {}
    Source evidence

    Reject a record without Show conformance

    Link
    derived-show-bad.tpzReject a record without Show conformanceOpen in Playground
    1. record Pair { z: int, a: string }
    2. let text = Show.show(Pair { z: 3, a: "Topaz" })
    Expected outputNonzero exit
    No stdout.
    $ topaz check derived-show-bad.tpz --compiler self · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5522 protocol-call-argument-does-not-conform at derived-show-bad.tpz:2:22
    Source evidence

    Related

    Link

    Missing protocol conformance

    Functions and generics

    Menu

    Download