Diagnostic and cause
LinkEmpty comprehension needs a type
- Family
- topaz
- Phase
- check
- Code
TPZ5612
Cause and conditions
An unannotated comprehension binding whose body type remains unresolved is rejected with TPZ5612. Giving its input array an element type makes the result inferable.
Related rule: Comprehension element type needs input contextResponse
Give the input collection a concrete element type. The repaired program annotates an empty input as Array<int> before using its elements in the comprehension.
Source evidence
- compiler/crates/topaz_diag/src/explain.rs at
151141d7bb44· 925-937 - compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
151141d7bb44· 451-451 - compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
17711dcdbc9b· 432-458 - compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
17711dcdbc9b· 1704-1730 - compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
17711dcdbc9b· 1768-1776
Compiler phase: check.
Compiler explanation: An empty comprehension cannot infer its element, key, or value type.
Message templates. The marker ⟨value⟩ stands for text computed for the reported program.
- this comprehension's element type cannot be inferred (§6.4): annotate the binding with its collection type Source
An unannotated comprehension binding whose body type remains unresolved is rejected with TPZ5612. Giving its input array an element type makes the result inferable.
Comprehension element type needs input context
An unannotated comprehension binding whose body type remains unresolved is rejected with TPZ5612. Giving its input array an element type makes the result inferable.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
17711dcdbc9b· 432-458 - compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
17711dcdbc9b· 1704-1730 - compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
17711dcdbc9b· 1768-1776
Response
LinkGive the input collection a concrete element type. The repaired program annotates an empty input as Array<int> before using its elements in the comprehension.
Reproduction and verification
LinkRejected program
Linklet values = [for value in ([]) => value]
No stdout.
Expected result
The empty input can also trigger TPZ5020. The required TPZ5612 refers to the complete comprehension. Supplying a typed input establishes the repair independently of result-context propagation.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
17711dcdbc9b· 432-458 - compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
17711dcdbc9b· 1704-1730 - compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
17711dcdbc9b· 1768-1776
Repaired program
Linklet input: Array<int> = []let values = [for value in (input) => value]
Expected result
Expected result
Checking accepts the program. Exit code 0.
The empty input can also trigger TPZ5020. The required TPZ5612 refers to the complete comprehension. Supplying a typed input establishes the repair independently of result-context propagation.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
17711dcdbc9b· 432-458 - compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
17711dcdbc9b· 1704-1730 - compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
17711dcdbc9b· 1768-1776