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

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

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

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

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

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

    A name bound by multiple alternatives of an or-pattern has inconsistent types.

    Diagnostic and cause

    Ссылка

    Or-pattern binding types disagree

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

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

    Binding the same name to disjoint payload types across or-pattern alternatives is rejected with TPZ5711. In this program, int and string cannot give value a compatible binding type.

    Действия

    Use compatible payload types for a shared binding, or split the alternatives into separate arms. The repaired enum supplies int from both alternatives.

    Compiler phase: check.

    Compiler explanation: A name bound by multiple alternatives of an or-pattern has inconsistent types.

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

    • binding ⟨value⟩ has type ⟨value⟩ in one or-pattern alternative and ⟨value⟩ in another Source

    Binding the same name to disjoint payload types across or-pattern alternatives is rejected with TPZ5711. In this program, int and string cannot give value a compatible binding type.

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

    Or-pattern binding types must be compatible

    Binding the same name to disjoint payload types across or-pattern alternatives is rejected with TPZ5711. In this program, int and string cannot give value a compatible binding type.

    Response

    Ссылка

    Use compatible payload types for a shared binding, or split the alternatives into separate arms. The repaired enum supplies int from both alternatives.

    Reproduction and verification

    Ссылка

    Rejected program

    Ссылка
    example.tpzRejected programОткрыть песочницу →
    1. enum Item { Count(int), Text(string) }
    2. function read(item: Item) -> int {
    3. match (item) {
    4. case Count(value) | Text(value) => 0
    5. }
    6. }
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

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

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

    The checker tests whether the collected types are disconnected under type overlap. This example establishes the disjoint int/string case; it does not require all alternative type spellings to be identical.

    Repaired program

    Ссылка
    example.tpzRepaired program
    1. enum Item { Count(int), Text(int) }
    2. function read(item: Item) -> int {
    3. match (item) {
    4. case Count(value) | Text(value) => 0
    5. }
    6. }
    Ожидаемый выводКод завершения 0
    $ topaz check example.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

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

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

    The checker tests whether the collected types are disconnected under type overlap. This example establishes the disjoint int/string case; it does not require all alternative type spellings to be identical.

    Меню

    Загрузка →