Diagnostic and cause
LinkTPZ5022
- Family
- topaz
- Phase
- check
- Code
TPZ5022
Cause and conditions
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.
Related rule: When inference needs an annotationResponse
Source evidence
- Return inference at
d61f9fd0efb0· 249-330
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 mainmust 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⟩.cannot be generic Source⟨value⟩ - protocol method
⟨value⟩.must take the conforming value as its first parameter Source⟨value⟩ - protocol method
⟨value⟩.requires an explicit return type (use⟨value⟩ -for unit) Source> () - protocol method
⟨value⟩.cannot be variadic Source⟨value⟩ - protocol method
⟨value⟩.cannot declare parameter defaults Source⟨value⟩ - protocol method
⟨value⟩.must use⟨value⟩ Selfor 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⟩.is module-local and cannot be exported Source⟨value⟩ - protocol implementation method
⟨value⟩.cannot be generic Source⟨value⟩ - protocol implementation method
⟨value⟩.requires an explicit return type (use⟨value⟩ -for unit) Source> () - protocol implementation method
⟨value⟩.cannot be variadic Source⟨value⟩ - protocol implementation method
⟨value⟩.cannot declare parameter defaults Source⟨value⟩ - protocol implementation method
⟨value⟩.must match the declared signature exactly; expected ⟨value⟩, found ⟨value⟩ Source⟨value⟩ - unknown protocol
⟨value⟩inimpl ⟨value⟩<⟨value⟩>Source JSONconformance is derive-only; usederives JSONSource- 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 takeselfas its first parameter Source - method
⟨value⟩on⟨value⟩must take bareselfas 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
implblock cannot be exported; mark individual methods withexportSource - cannot define methods on
⟨value⟩(⟨value⟩);implis only allowed on an own-module record, enum, or newtype Source - cannot define receiver methods on generic nominal
⟨value⟩yet; genericimplbinders 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.must match the declared signature exactly; expected (Item) ->show string, found (int) ->string
A protocol implementation signature differs from its protocol, or a type cannot be determined under the applicable annotation 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.
Why
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.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/protocols_methods.tpz at
151141d7bb44· 425-452 - issues/31 at
1cbf38d3d422
Response
LinkCompare the declaration with the required type or protocol signature. Match the declared parameter and result types and remove unsupported type-related forms.
Reproduction and verification
LinkRejected program
Linkrecord Item { value: int }impl Show<Item> {function show(value: int) -> string { "item" }}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5022diagnostics-protocol-implementation-signature atexample.tpz:3:12
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/protocols_methods.tpz at
151141d7bb44· 425-452 - issues/31 at
1cbf38d3d422
Repaired program
Linkrecord Item { value: int }impl Show<Item> {function show(value: Item) -> string { "item" }}
Expected result
Expected result
Checking accepts the program. Exit code 0.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/protocols_methods.tpz at
151141d7bb44· 425-452 - issues/31 at
1cbf38d3d422