E08240: mutation operators are not applicable to function types, only '?' operator is supported
What went wrong
Function types are callable references, not data containers. Mutation operators (:=:, :~:, :^:, +=, -=) are not applicable to function types. Only the '?' (isSet) operator is supported on functions.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 738 (Why does EK9 reject mutation operators on function types?)
How to fix it
- Use ':=' (simple assignment) instead of ':=:' (copy) for function variables
- Functions are references - reassignment changes which function is referenced
- Only '?' (isSet) is valid as an operator on function types
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E08240: mutation operators are not applicable to function types, only '?' operator is supported
#!ek9 defines module error.e08240.bad defines class TextHandler processor as Processor? default private TextHandler() TextHandler() -> handler as Processor processor :=: handler default operator ? defines function Processor() as abstract -> text as String <- rtn as String?
Fixed: Assign the function; only ? applies to it
#!ek9 defines module error.e08240.good defines class TextHandler processor as Processor? default private TextHandler() TextHandler() -> handler as Processor processor: handler isReady() <- rtn as Boolean: processor? default operator ? defines function Processor() as abstract -> text as String <- rtn as String?
Questions and answers
These Q&A entries show E08240 and its fix: