E4065

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

#alias value

Number of Arguments

_[_]

"_[_]"

2

_[_] = _

"_[_]=_"

3

_[_:_]

"_[_:_]"

3

Erroneous example#

///|
struct A(Array[Int])

///|
#alias("_[_]")
fn A::get(self : A, idx : Int, offset? : Int) -> Int {
  //  ^~~~~~
  // Error: overloaded indexing should accept 2 arguments, but it accepts 3 arguments
  let idx = match offset {
    None => idx
    Some(offset) => idx + offset
  }
  return self.0[idx]
}

Suggestion#

Give the aliased method the number of arguments expected by the operator.

///|
struct A(Array[Int])

///|
#alias("_[_]")
fn A::get(self : A, idx : Int) -> Int {
  return self.0[idx]
}