E4065#
Overloaded operator should accept the correct number of arguments.
You can refer to the Operator Overloading section for a list of operators that can be overloaded, and here is a list of number of arguments that each operator should accept:
Operator |
Method Name |
Number of Arguments |
---|---|---|
|
|
2 |
|
|
2 |
|
|
2 |
|
|
2 |
|
|
2 |
|
|
2 |
|
|
2 |
|
|
2 |
|
|
1 |
|
|
2 |
|
|
3 |
|
|
3 |
|
|
2 |
|
|
2 |
|
|
2 |
Erroneous example#
type A Int
fn A::op_add(self : A, other : A, opt? : A) -> A {
// ^~~~~~
// Error: overloaded operator "op_add" should accept 2 arguments, but it accepts 3 arguments
let opt = match opt {
None => 0
Some(opt) => opt._
}
return self._ + other._ + opt
}
Suggestion#
Modify the method to match the expected number of arguments of the operator.
fn A::op_add(self : A, other : A) -> A {
self._ + other._
}