E07500: operator must be declared pure
What went wrong
Certain operators MUST be marked 'pure' because they should never have side effects. You've defined one without 'pure'.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 239 (How do comparison and ordering operators work in EK9?)
- ek9 -q 238 (What operators does EK9 support and why is the set fixed?)
- ek9 -q 96 (How do operators work in EK9?)
- ek9 -q 242 (How do conversion and introspection operators work in EK9?)
- ek9 -q 98 (How do record operators work in EK9?)
Operators that must be pure
==, <>, <, <=, >, >=, <=> // Comparison ? // Set check $, $$ // String conversion #? // Hashcode
Rationale
Comparison/query operations shouldn't modify state.
How to fix it
- Add 'as pure' modifier
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07500: operator must be declared pure
#!ek9 defines module error.e07500.bad defines class Basket items <- ["apple", "pear"] //A query operator must not change anything default operator ? operator contains -> item as String <- rtn as Boolean: items contains item
Fixed: Mark it 'as pure'
#!ek9 defines module error.e07500.good defines class Basket items <- ["apple", "pear"] default operator ? operator contains as pure -> item as String <- rtn as Boolean: items contains item
Questions and answers
These Q&A entries show E07500 and its fix:
- Q96: How do operators work in EK9?
- Q98: How do record operators work in EK9?
- Q238: What operators does EK9 support and why is the set fixed?
- Q239: How do comparison and ordering operators work in EK9?
- Q242: How do conversion and introspection operators work in EK9?
- Q245: How do I implement all the operators my custom type needs?
- Q568: How does purity apply to operators and their overrides?
- Q577: How do I override operators in EK9?
- Q910: How do I implement the $ operator on a custom class in EK9?