Diagnostic and cause
LinkType could not be inferred
- Family
- topaz
- Phase
- check
- Code
TPZ5020
Cause and conditions
A bare empty array binding needs a contextual element type. An Array<T> annotation supplies that context.
Response
Add a type annotation at the binding, parameter, or surrounding expression so inference can choose the required type.
Source evidence
- compiler/crates/topaz_diag/src/explain.rs at
151141d7bb44· 688-700 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
151141d7bb44· 1092-1092 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
151141d7bb44· 609-609 - compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
151141d7bb44· 185-185 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
151141d7bb44· 668-680 - compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
151141d7bb44· 157-188
Compiler phase: check.
Compiler explanation: Inference reached a value whose type stays ambiguous without more context.
Message templates. The marker ⟨value⟩ stands for text computed for the reported program.
- this expression needs a contextual type (§22.1): annotate the binding or surrounding expectation Source
map {}needs a contextual type (§6): annotate the binding or the expected key/value types Source
Observed for the candidate in Topaz 5.21.3. Execution
- error[TPZ5020]:
[]needs a contextual type (§22.1): annotate the binding or the expected element type
A bare empty array binding needs a contextual element type. An Array<T> annotation supplies that context.
Type could not be inferred
A bare empty array binding needs a contextual element type. An Array<T> annotation supplies that context.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
151141d7bb44· 668-680 - compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
151141d7bb44· 157-188
Response
LinkAdd a type annotation at the binding, parameter, or surrounding expression so inference can choose the required type.
Reproduction and verification
LinkRejected program
Linklet values = []
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5020diagnostics-empty-array-needs-context atexample.tpz:1:14
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
151141d7bb44· 668-680 - compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
151141d7bb44· 157-188
Repaired program
Linklet values: Array<int> = []
Expected result
Expected result
Checking accepts the program. Exit code 0.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
151141d7bb44· 668-680 - compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
151141d7bb44· 157-188