E06280: operator declared with too many parameters
What went wrong
An OPERATOR is DECLARED with too many parameters. Each operator has a fixed number of parameters: a binary operator such as '+' or '==' takes exactly one (the right-hand operand - the left-hand operand is 'this'), and an operator such as '?', '$', '#?' or 'length' takes none. This error is about the DECLARATION of the operator. It is not about a call: a call that passes the wrong number of arguments is E06270 (or E50060 when nothing matches).
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 779 (Why must certain operators return a value in EK9?)
How to fix it
- Declare the operator with the number of parameters it takes: '+' one, '?' none
- For a binary operator remove the left-hand operand - it is 'this'
- If more input is needed, write a method rather than an operator
Common causes
- Declaring '+' (or '==', '<=>') as if it took both operands
- Giving '?', '$', '#?' or 'length' a parameter
- Copying a method signature into an operator declaration
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E06280: operator declared with too many parameters
#!ek9 defines module error.e06280.bad defines class Amount total as Integer: 0 //'+' takes the right-hand operand only: the left is this default operator ? operator + as pure -> first as Amount second as Amount <- rtn as Amount: Amount()
Fixed: A binary operator takes one parameter: the right-hand operand
#!ek9 defines module error.e06280.good defines class Amount total as Integer? default private Amount() as pure Amount() as pure -> initial as Integer total :=? initial default operator ? operator + as pure -> other as Amount <- rtn as Amount: Amount(total + other.total)
Questions and answers
These Q&A entries show E06280 and its fix: