Перейти к содержимому
Топаз6.0 · До релиза
Загрузка →

Поиск в документации

Спецификация 6.0

Выберите результат стрелками и нажмите Enter, чтобы открыть его.

Введите имя API, номер диагностики, правило или тему проекта.

    Диагностика TPZ5612

    An empty comprehension cannot infer its element, key, or value type.

    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.

    Действия

    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.

    Правилоdiagnostics.tpz5612.p5.rule

    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

    Ссылка
    example.tpzRejected programОткрыть песочницу →
    1. let values = [for value in ([]) => value]
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения check. Ненулевой код завершения.

    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

    Ссылка
    example.tpzRepaired program
    1. let input: Array<int> = []
    2. let values = [for value in (input) => value]
    Ожидаемый выводКод завершения 0
    $ topaz check example.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Проверка принимает программу. Код завершения 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.

    Меню

    Загрузка →