Diagnostic and cause
LinkValue 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.
Related rule: Function values cannot be compared for equalityResponse
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/crates/topaz_diag/src/explain.rs at
151141d7bb44· 655-664 - compiler/crates/topaz_product_runtime/src/diagnostic.rs at
151141d7bb44· 68-68 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
151141d7bb44· 1174-1174 - compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
151141d7bb44· 963-963 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
151141d7bb44· 638-638 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
151141d7bb44· 290-302 - compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
151141d7bb44· 971-987 - compiler/crates/topaz_self_frontend/topaz/checker/type_algebra.tpz at
151141d7bb44· 128-144 - compiler/crates/topaz_self_frontend/topaz/parser/expressions.tpz at
151141d7bb44· 1591-1610
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.cannot sort it Source⟨value⟩() - the
⟨value⟩key type⟨value⟩is not ordered comparable, so.cannot sort it Source⟨value⟩() ⟨value⟩is not comparable, sotest.cannot compare it Source⟨value⟩ ⟨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]:
() -and> int () -are not comparable values> int
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.
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
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
151141d7bb44· 290-302 - compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
151141d7bb44· 971-987 - compiler/crates/topaz_self_frontend/topaz/checker/type_algebra.tpz at
151141d7bb44· 128-144 - compiler/crates/topaz_self_frontend/topaz/parser/expressions.tpz at
151141d7bb44· 1591-1610
Response
LinkChoose 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
LinkRejected program
Linkfunction first() -> int { 1 }function second() -> int { 2 }let same = first == second
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
151141d7bb44· 290-302 - compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
151141d7bb44· 971-987 - compiler/crates/topaz_self_frontend/topaz/checker/type_algebra.tpz at
151141d7bb44· 128-144 - compiler/crates/topaz_self_frontend/topaz/parser/expressions.tpz at
151141d7bb44· 1591-1610
Repaired program
Linkfunction first() -> int { 1 }function second() -> int { 2 }let same = first() == second()
Expected result
Expected result
Checking accepts the program. Exit code 0.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
151141d7bb44· 290-302 - compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
151141d7bb44· 971-987 - compiler/crates/topaz_self_frontend/topaz/checker/type_algebra.tpz at
151141d7bb44· 128-144 - compiler/crates/topaz_self_frontend/topaz/parser/expressions.tpz at
151141d7bb44· 1591-1610