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

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

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

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

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

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

    A loop expression has break values whose types cannot join to one result type.

    Diagnostic and cause

    Ссылка

    Loop break values do not agree

    Семейство
    topaz
    Этап
    check
    Код
    TPZ5721

    Причина и условия

    When a value-producing loop has no contextual result type, incompatible break-value types are rejected with TPZ5721. The int and string break values in this program are assignable in neither direction.

    Действия

    Make the breaks produce compatible values. The repaired program returns int from both branches.

    Compiler phase: check.

    Compiler explanation: A loop expression has break values whose types cannot join to one result type.

    Message templates. The marker ⟨value⟩ stands for text computed for the reported program.

    • break values targeting this loop disagree — earlier break is ⟨value⟩, this is ⟨value⟩ (all break values must have the same type) Source

    When a value-producing loop has no contextual result type, incompatible break-value types are rejected with TPZ5721. The int and string break values in this program are assignable in neither direction.

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

    Inferred loop break types must be compatible

    When a value-producing loop has no contextual result type, incompatible break-value types are rejected with TPZ5721. The int and string break values in this program are assignable in neither direction.

    Response

    Ссылка

    Make the breaks produce compatible values. The repaired program returns int from both branches.

    Reproduction and verification

    Ссылка

    Rejected program

    Ссылка
    example.tpzRejected programОткрыть песочницу →
    1. let flag: bool = true
    2. let result = loop {
    3. if (flag) { break 1 } else { break "text" }
    4. }
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

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

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

    This condition applies to a value loop with no expected result type and concrete incompatible break types. The checker compares assignability in both directions; the example does not impose a type-spelling equality rule on other loop contexts.

    Repaired program

    Ссылка
    example.tpzRepaired program
    1. let flag: bool = true
    2. let result = loop {
    3. if (flag) { break 1 } else { break 2 }
    4. }
    Ожидаемый выводКод завершения 0
    $ topaz check example.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

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

    Проверка принимает программу. Код завершения 0.

    This condition applies to a value loop with no expected result type and concrete incompatible break types. The checker compares assignability in both directions; the example does not impose a type-spelling equality rule on other loop contexts.

    Меню

    Загрузка →