Diagnostic and cause
LinkTPZ5001
- Family
- topaz
- Phase
- check
- Code
TPZ5001
Cause and conditions
A parameter can contain a default expression after =. The checker checks that expression against the parameter type and applies a constant-expression restriction. Failure of the constant-expression check produces TPZ5001.
Response
Source evidence
- Default restriction at
d61f9fd0efb0· 100-121
Compiler phase: check/runtime.
Compiler explanation: A value's type does not match the type required by its context.
Message templates. The marker ⟨value⟩ stands for text computed for the reported program.
constinitializers must be constant expressions (§4) Source⟨value⟩is not iterable (§10) Sourcereturnoutside a function Source- a placeholder
_is valid only inside a pipeline stage (§11) Source - expected
⟨value⟩, found⟨value⟩Source ⟨value⟩outside a loop Source- bare
⟨value⟩cannot target ⟨value⟩ Source concurrenttimeout duration must fit in u64 milliseconds (§15) Source- the range step must not be zero (§10) Source
??needs an Option or nullable left operand, found⟨value⟩Source- Length operation requires compatible units and scalar operands, found
⟨value⟩and⟨value⟩Source - arithmetic needs matching numeric operands, found
⟨value⟩and⟨value⟩Source %needs int operands in v5.2, found⟨value⟩and⟨value⟩Source+needs matching int, float, string, BigInt, or Decimal operands, found⟨value⟩and⟨value⟩Sourceindoes not apply to a Map; usein map.Sourcekeys indoes not apply to strings Source- integer literal is out of range Source
- unary operator cannot apply to
⟨value⟩Source ?propagates an error, but the function returns⟨value⟩, not a Result Source?requires a Result value, found⟨value⟩Source⟨value⟩is not index-readable; only arrays support[…]indexing (§9) Source- integer literal
⟨value⟩is out of range Source - a placeholder
_is valid only in a pipeline stage's argument list (§11) Source ⟨value⟩is not iterable (§10) SourceBytevalues cannot be interpolated; snapshot toBuffer Bytesand encode explicitly Source- array spread needs an
Array, found⟨value⟩Source ?.needs an Option or nullable receiver, foundnamespaceSource?.needs an Option or nullable receiver, found⟨value⟩Source- record spread
.needs a declared record;. . ⟨value⟩is not one Source - record update needs a record, found
⟨value⟩Source - integer literal type
⟨value⟩is out of range Source - Length requires one compiler-owned Pt, Mm, Cm, In or Em marker Source
- this pattern can never match
⟨value⟩Source - a
⟨value⟩pattern cannot establish nominal identity for rigid scrutinee type⟨value⟩Source - this
⟨value⟩pattern can never match⟨value⟩Source - this
⟨value⟩pattern can never match⟨value⟩Source - a Map is not index-assignable; use
m.(§22) Sourceinsert - cannot assign through optional access
?.(§4) Source ??=needs an Option or nullable target, found⟨value⟩Source- constant expression error: ⟨value⟩ Source
Observed for the candidate in Topaz 5.21.3. Execution
- error[TPZ5001]: expected
int, foundstring
The initializer of an annotated binding must be assignable to the declared type. Assigning a string to int is rejected with TPZ5001 at the initializer.
An annotated binding requires an assignable initializer
The initializer of an annotated binding must be assignable to the declared type. Assigning a string to int is rejected with TPZ5001 at the initializer.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
151141d7bb44· 430-443 - compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
151141d7bb44· 460-474 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
151141d7bb44· 1660-1683 - compiler/crates/topaz_self_frontend/topaz/checker/syntax_index.tpz at
151141d7bb44· 485-505
Response
LinkCheck the reported expression and its expected type. Change the value or annotation, or perform the required conversion explicitly.
Reproduction and verification
LinkRejected program
Linklet value: int = "Ada"
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
151141d7bb44· 430-443 - compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
151141d7bb44· 460-474 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
151141d7bb44· 1660-1683 - compiler/crates/topaz_self_frontend/topaz/checker/syntax_index.tpz at
151141d7bb44· 485-505
Repaired program
Linklet value: int = 42
Expected result
Expected result
Checking accepts the program. Exit code 0.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
151141d7bb44· 430-443 - compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
151141d7bb44· 460-474 - compiler/crates/topaz_self_frontend/topaz/checker/call_facts.tpz at
151141d7bb44· 1660-1683 - compiler/crates/topaz_self_frontend/topaz/checker/syntax_index.tpz at
151141d7bb44· 485-505