본문으로 건너뛰기
토파즈6.0 · 출시 전
다운로드 →

문서 검색

명세 6.0

방향키로 결과를 고르고 Enter를 눌러 여세요.

API 이름, 진단 번호, 규칙 또는 프로젝트 주제를 입력하세요.

    진단 TPZ5022

    A type annotation, alias, or protocol bound names a type/protocol form that is not valid here.

    Diagnostic and cause

    링크

    TPZ5022

    계열
    topaz
    단계
    check
    코드
    TPZ5022

    원인과 조건

    Confirmed TPZ5022 paths include an inferred result containing a generic projection without a nameable return type, and an unresolved result when the function calls a definition whose return type is still pending.

    대응

    Compiler phase: check.

    Compiler explanation: A type annotation, alias, or protocol bound names a type/protocol form that is not valid here.

    Message templates. The marker ⟨value⟩ stands for text computed for the reported program.

    • export function main must be non-generic and have signature ⟨value⟩; found ⟨value⟩ Source
    • cannot infer a return type for ⟨value⟩: it returns a destructured generic value with no nameable type — annotate the return type Source
    • ⟨value⟩ is (mutually) recursive: declare its return type (§7) Source
    • cannot derive ⟨value⟩ for generic nominal ⟨value⟩ yet; conditional generic conformance is not defined Source
    • integer literal ⟨value⟩ is out of range Source
    • record literal declares field ⟨value⟩ twice Source
    • ⟨value⟩ takes ⟨value⟩ type argument⟨value⟩, found ⟨value⟩ Source
    • integer literal type ⟨value⟩ is out of range Source
    • record type declares field ⟨value⟩ twice Source
    • type parameter ⟨value⟩ takes no type arguments Source
    • primitive type ⟨value⟩ takes no type arguments Source
    • ⟨value⟩ takes no type arguments Source
    • ⟨value⟩ name ⟨value⟩ collides with ⟨value⟩; choose another name Source
    • enum variant ⟨value⟩ collides with a reserved prelude constructor; choose another variant name Source
    • enum variant ⟨value⟩ has a payload ⟨value⟩ that is a union containing an enum — enum-in-union payloads are not supported Source
    • protocol method ⟨value⟩.⟨value⟩ cannot be generic Source
    • protocol method ⟨value⟩.⟨value⟩ must take the conforming value as its first parameter Source
    • protocol method ⟨value⟩.⟨value⟩ requires an explicit return type (use -> () for unit) Source
    • protocol method ⟨value⟩.⟨value⟩ cannot be variadic Source
    • protocol method ⟨value⟩.⟨value⟩ cannot declare parameter defaults Source
    • protocol method ⟨value⟩.⟨value⟩ must use Self or the protocol's type parameter as its first parameter type Source
    • ⟨value⟩ is already a type and cannot also be a protocol Source
    • protocol ⟨value⟩ takes at most one conforming-type parameter; found ⟨value⟩ Source
    • protocol ⟨value⟩ has no method ⟨value⟩ Source
    • protocol implementation method ⟨value⟩.⟨value⟩ is module-local and cannot be exported Source
    • protocol implementation method ⟨value⟩.⟨value⟩ cannot be generic Source
    • protocol implementation method ⟨value⟩.⟨value⟩ requires an explicit return type (use -> () for unit) Source
    • protocol implementation method ⟨value⟩.⟨value⟩ cannot be variadic Source
    • protocol implementation method ⟨value⟩.⟨value⟩ cannot declare parameter defaults Source
    • protocol implementation method ⟨value⟩.⟨value⟩ must match the declared signature exactly; expected ⟨value⟩, found ⟨value⟩ Source
    • unknown protocol ⟨value⟩ in impl ⟨value⟩<⟨value⟩> Source
    • JSON conformance is derive-only; use derives JSON Source
    • cannot implement protocol ⟨value⟩ for generic nominal ⟨value⟩ yet; generic conformance binders are not defined Source
    • impl ⟨value⟩<⟨value⟩> is missing method ⟨value⟩ Source
    • method ⟨value⟩ on ⟨value⟩ must take self as its first parameter Source
    • method ⟨value⟩ on ⟨value⟩ must take bare self as its first parameter (no type annotation, default, or variadic marker) Source
    • generic methods are not supported yet (method ⟨value⟩) Source
    • method name ⟨value⟩ on ⟨value⟩ collides with a builtin member; choose another name Source
    • method ⟨value⟩ on ⟨value⟩ collides with a field of the same name; rename the method (a field shadows a method) Source
    • an impl block cannot be exported; mark individual methods with export Source
    • cannot define methods on ⟨value⟩ (⟨value⟩); impl is only allowed on an own-module record, enum, or newtype Source
    • cannot define receiver methods on generic nominal ⟨value⟩ yet; generic impl binders are not defined Source
    • ⟨value⟩ declarations are module-top-level only Source

    Observed for the candidate in Topaz 5.21.3. Execution

    • error[TPZ5022]: protocol implementation method Show.show must match the declared signature exactly; expected (Item) -> string, found (int) -> string

    A protocol implementation signature differs from its protocol, or a type cannot be determined under the applicable annotation rule. The Result error annotation rule also applies to lambdas used as callbacks.

    규칙diagnostics.tpz5022.p5.rule

    Malformed or unknown type

    A protocol implementation method must have exactly the parameter and result types required by its protocol after substituting the conforming type. TPZ5022 also requires annotations under function return inference and Result error inference. A lambda, including one used as a callback, follows the same annotation requirement under callback propagation.

    이유

    Result error inference uses the same annotation diagnostic as function return inference. The emitted return type is determined instead of falling back to a broad value type. Each callable has its own propagation destination. A callback can return a Result without ending its caller.

    Response

    링크

    Match the declared parameter and result types to the required signature. If Result error inference remains undetermined, add a type annotation. A lambda binding can declare its complete function type, including the Result error type.

    Reproduction and verification

    링크

    Rejected program

    링크
    example.tpzRejected program플레이그라운드 열기 →
    1. record Item { value: int }
    2. impl Show<Item> {
    3. function show(value: int) -> string { "item" }
    4. }
    기대 출력0이 아닌 종료 코드
    표준 출력 없음.
    $ topaz check example.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

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

    • TPZ5022 →

      diagnostics-protocol-implementation-signature at example.tpz:3:12

    Repaired program

    링크
    example.tpzRepaired program
    1. record Item { value: int }
    2. impl Show<Item> {
    3. function show(value: Item) -> string { "item" }
    4. }
    기대 출력종료 코드 0
    $ topaz check example.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    검사가 프로그램을 받아들입니다. 종료 코드 0.

    Lambda return inference

    링크

    The lambda annotation example applies TPZ5022 to an undetermined Result error type. Callback propagation gives each lambda its own return destination. The example and its execution record belong to that language rule.

    메뉴

    다운로드 →