E07510: operator must not be declared pure
What went wrong
You've marked an operator 'pure' but it shouldn't be - this operator is expected to modify state (mutating operator).
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 241 (What are mutation operators and how do they differ from p...)
Operators that must not be pure
- '++' and '--' (increment and decrement)
- ':=:', ':~:' and ':^:' (copy, merge and replace)
- '+=', '-=', '*=' and '/=' (compound assignment)
Rationale
These operators modify state by design.
How to fix it
- Remove '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 E07510: operator must not be declared pure
#!ek9 defines module error.e07510.bad defines class Wallet amount <- 0.0 holding() as pure <- rtn as Float: amount //Copy changes this object, so it cannot be pure default operator ? operator :=: as pure -> other as Wallet amount :=: other.holding()
Fixed: Remove 'as pure' from a mutating operator
#!ek9 defines module error.e07510.good defines class Wallet amount <- 0.0 holding() as pure <- rtn as Float: amount default operator ? operator :=: -> other as Wallet amount :=: other.holding()
Questions and answers
These Q&A entries show E07510 and its fix: