Перейти к содержимому
Топаз6.0 · До релиза
Загрузка →

Поиск в документации

Спецификация 6.0

Выберите результат стрелками и нажмите Enter, чтобы открыть его.

Введите имя API, номер диагностики, правило или тему проекта.

    Язык · 15 глав · 1 правило

    Вывод производного Show

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

    Правилоtopaz.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.

    Причина

    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.

    Examples

    Ссылка

    Render declared fields and an empty record

    Ссылка
    derived-show.tpzRender declared fields and an empty recordОткрыть песочницу →
    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 {}))
    Ожидаемый выводКод завершения 0
    Pair { z: 3, a: Topaz }
    Empty {}
    
    $ topaz run derived-show.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

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

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. Pair { z: 3, a: Topaz }
    2. Empty {}

    Reject a record without Show conformance

    Ссылка
    derived-show-bad.tpzReject a record without Show conformanceОткрыть песочницу →
    1. record Pair { z: int, a: string }
    2. let text = Show.show(Pair { z: 3, a: "Topaz" })
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check derived-show-bad.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

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

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

    • TPZ5522 →

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

    Related

    Ссылка

    Missing protocol conformance →

    Functions and generics →

    Меню

    Загрузка →