E07210: 'default' of operators can only support '?' operator with function delegate fields
What went wrong
You're using 'default operator' on a class with function delegate fields. Function delegates only support the '?' operator for auto-generation.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 834 (Why can't I use 'default operator <=>' on a record with a...)
Note
Function delegates can only meaningfully be checked for set/unset. Comparing function references for equality is not supported.
How to fix it
- Use only 'default operator ?' with function fields
- Implement other operators manually
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07210: 'default' of operators can only support '?' operator with function delegate fields
#!ek9 defines module error.e07210.bad defines record Rule check as Check? Rule() -> callback as Check this.check: callback default operator <=> default operator ? //A function cannot be compared, so '<=>' cannot be generated over it defines function Check() as abstract -> text as String <- rtn as Boolean?
Fixed: Default only '?', and write the operators over the data
#!ek9 defines module error.e07210.good defines record Rule name as String? check as Check? default private Rule() //Only '?' may be defaulted over a function delegate Rule() -> ruleName as String callback as Check this.name: ruleName this.check: callback operator <=> as pure -> other as Rule <- rtn as Integer: name <=> other.name default operator ? //Write the sameness over the data, not the function operator #? as pure <- rtn as Integer: #?name defines function Check() as abstract -> text as String <- rtn as Boolean?
Questions and answers
These Q&A entries show E07210 and its fix: