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

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

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

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

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

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

    Comparing function values with == produces TPZ5007.

    Diagnostic and cause

    Ссылка

    Value is not comparable or keyable

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

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

    Equality requires comparable operand types. Function values are not comparable, so comparing two functions with == is rejected with TPZ5007. Comparing their int results is accepted.

    Действия

    Choose values with the required equality or ordering behavior. For a user-defined type, supply the supported protocol implementation or compare a suitable field.

    Compiler phase: check/runtime.

    Compiler explanation: The operation requires equality/order/key semantics that this type does not provide.

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

    • ⟨value⟩ is not ordered comparable, so .⟨value⟩() cannot sort it Source
    • the ⟨value⟩ key type ⟨value⟩ is not ordered comparable, so .⟨value⟩() cannot sort it Source
    • ⟨value⟩ is not comparable, so test.⟨value⟩ cannot compare it Source
    • ⟨value⟩ and ⟨value⟩ are not ordered comparable Source
    • ⟨value⟩ and ⟨value⟩ are not comparable values Source
    • ⟨value⟩ and ⟨value⟩ are never equal Source
    • ⟨value⟩ is not a valid Map/Set key (⟨value⟩ keys are not supported yet) Source

    Observed for the candidate in Topaz 5.21.3. Execution

    • error[TPZ5007]: () -> int and () -> int are not comparable values

    Equality requires comparable operand types. Function values are not comparable, so comparing two functions with == is rejected with TPZ5007. Comparing their int results is accepted.

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

    Function values cannot be compared for equality

    Equality requires comparable operand types. Function values are not comparable, so comparing two functions with == is rejected with TPZ5007. Comparing their int results is accepted.

    Response

    Ссылка

    Choose values with the required equality or ordering behavior. For a user-defined type, supply the supported protocol implementation or compare a suitable field.

    Reproduction and verification

    Ссылка

    Rejected program

    Ссылка
    example.tpzRejected programОткрыть песочницу →
    1. function first() -> int { 1 }
    2. function second() -> int { 2 }
    3. let same = first == second
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

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

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

    Repaired program

    Ссылка
    example.tpzRepaired program
    1. function first() -> int { 1 }
    2. function second() -> int { 2 }
    3. let same = first() == second()
    Ожидаемый выводКод завершения 0
    $ topaz check example.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

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

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

    Меню

    Загрузка →