E07180: 'default' of operators requires this type to have appropriate operator
What went wrong
You're using 'default operator X' but this type doesn't have a required prerequisite operator that the default implementation depends on.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 260 (What types can be used as Dict keys?)
Operator dependency chain
A type defines its SAMENESS once - '<=>' (ordered) or '==' (equatable only) - and the other comparisons are GENERATED from it, never requested:
from '<=>': == <> < <= > >= from '==': <>
So asking for '<' on a type with no '<=>' has nothing to be generated from (this error). Declare the '<=>' instead - generated with 'default' or written by hand - and '<' comes with it. Asking for '<' beside a '<=>' is E07181 (redundant). A bare 'default operator' over a field that cannot be ordered (a Dict, a List) gives '==' compared field by field and no ordering operators.
Semantics note
- 'default operator ?' returns true only if ALL fields are set (one unset field is enough to make the whole object unset)
- 'default operator #?'/'$'/'$$' return UNSET if object is completely empty
- Custom '?' does NOT affect how 'default #?'/'$'/'$$' behave
How to fix it
- Replace 'default operator <' with 'default operator <=>' (or a hand-written '<=>')
- Or use 'default operator' to generate all at once
- For an ordering by some other rule, write a comparator function ('sort by f')
Common causes
- Asking for '<' (or '<=', '>', '>=') instead of declaring '<=>'
- Not aware that comparisons are generated from the type's sameness
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07180: 'default' of operators requires this type to have appropriate operator
#!ek9 defines module error.e07180.bad defines class Reading taken <- Time() //An ordering operator is generated from '<=>', and there is none default operator < default operator ?
Fixed: Default '<=>' instead: the comparisons come from it
#!ek9 defines module error.e07180.good defines class Reading taken <- Time() //Choose ordered sameness: '<', '<=', '>', '>=', '==' and '<>' are all generated from it default operator <=> default operator ?