E07220: 'default' is not supported on this operator
What went wrong
You're using 'default' with an operator that doesn't support auto-generation. Only specific operators can be auto-generated.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 116 (What does 'default operator' generate?)
[SUPPORTED 'DEFAULT' OPERATORS] 'default' can generate only these operators, each from the type's fields:
- '?' - the set-check (true only when ALL fields are set)
- '<=>' (ordered) or '==' (equatable only) - the type's sameness; '<>', '<', '<=', '>' and '>=' are then generated from it, never asked for (that is E07181)
- '$' (String form), '$$' (JSON form), '#?' (hash code), ':=:' (shallow copy)
- 'close' - closes the type's closeable properties
The bare 'default operator' asks for all of these that the type can have.
[UNSUPPORTED - MUST IMPLEMENT MANUALLY] Every other operator - arithmetic ('+', '-', '*', '/', '++', '--'), 'empty', 'contains', 'length' and the rest - has a meaning only the type can decide.
Semantics
- 'default operator ?' = true only if ALL fields are set (own and inherited)
- 'default operator #?/$/$$' = UNSET if object completely empty
How to fix it
- Use only supported operators with 'default'
- Implement unsupported operators manually
The [EXAMPLE] section below shows 'default operator empty' on a record, and the record writing its own 'empty'.
Common causes
- Using 'default' with unsupported operator symbol
- Trying to auto-generate arithmetic operators
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07220: 'default' is not supported on this operator
#!ek9 defines module error.e07220.bad defines record Basket items <- List() of String //What 'empty' means is the type's own decision default operator ? default operator empty
Fixed: Write the operator
#!ek9 defines module error.e07220.good defines record Basket items <- List() of String default operator ? operator empty as pure <- rtn as Boolean: items.empty()
Questions and answers
These Q&A entries show E07220 and its fix: