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

方法名称

Number of Arguments

+

op_add

2

-

op_sub

2

*

op_mul

2

/

op_div

2

%

op_mod

2

==

op_equal

2

<<

op_shl

2

>>

op_shr

2

-(一元)

op_neg

1

_[_]

op_get

2

_[_] = _

op_set

3

_[_:_]

op_as_view

3

&

land

2

|

lor

2

^

lxor

2

错误示例#

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
}

建议#

Modify the method to match the expected number of arguments of the operator.

fn A::op_add(self : A, other : A) -> A {
  self._ + other._
}