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 |
|
|
3 |
|
|
3 |
Erroneous example#
///|
struct A(Array[Int])
///|
fn A::op_get(self : A, idx : Int, offset? : Int) -> Int {
// ^~~~~~
// Error: overloaded operator "op_get" should accept 2 arguments, but it accepts 3 arguments
let idx = match offset {
None => idx
Some(offset) => idx + offset
}
return self.0[idx]
}
Suggestion#
Modify the method to match the expected number of arguments of the operator.
///|
struct A(Array[Int])
///|
fn A::op_get(self : A, idx : Int) -> Int {
return self.0[idx]
}