Skip to content
Topaz6.0 · Before release
Download

Search documentation

Specification 6.0 · Not released · Tested product 5.21.3

Use arrow keys to choose a result. Press Enter to open.

Type an API name, diagnostic number, rule, or project topic.

    Diagnostics

    TPZ5007 Value is not comparable or keyable

    Comparing function values with == produces TPZ5007.

    Diagnostic and cause

    Link

    Value is not comparable or keyable

    Family
    topaz
    Phase
    check
    Code
    TPZ5007

    Cause and conditions

    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.

    Source evidence

    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.

    Rulediagnostics.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.

    Source evidence

    Response

    Link

    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

    Link

    Rejected program

    Link
    example.tpzRejected programOpen in Playground
    1. function first() -> int { 1 }
    2. function second() -> int { 2 }
    3. let same = first == second
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5007 diagnostic-tpz5007 at example.tpz:3:12
    Source evidence

    Repaired program

    Link
    example.tpzRepaired program
    1. function first() -> int { 1 }
    2. function second() -> int { 2 }
    3. let same = first() == second()
    Expected outputexit 0
    $ topaz check example.tpz · target product 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Source evidence

    Menu

    Download