Diagnostic and cause
СсылкаEmpty comprehension needs a type
- Семейство
- topaz
- Этап
- check
- Код
TPZ5612
Причина и условия
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 →Действия
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.
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.
Response
Ссылка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.
Reproduction and verification
СсылкаRejected program
Ссылкаlet values = [for value in ([]) => value]
Нет стандартного вывода.Ожидаемый результат
Ожидаемый результат
Этап отклонения check. Ненулевой код завершения.
diagnostic-tpz5612 at
example.tpz:1:14
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.
Repaired program
Ссылкаlet input: Array<int> = []let values = [for value in (input) => value]
Ожидаемый результат
Ожидаемый результат
Проверка принимает программу. Код завершения 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.