본문으로 건너뛰기
토파즈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.

    Rules

    링크
    규칙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" })
    기대 출력0이 아닌 종료 코드
    표준 출력 없음.
    $ topaz check derived-show-bad.tpz --compiler self · 대상 제품 5.21.3
    기대 결과

    기대 결과

    거절 단계 check. 종료 코드가 0이 아닙니다.

    • TPZ5522 →

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

    Related

    링크

    Missing protocol conformance →

    Functions and generics →

    메뉴

    다운로드 →