Skip to main content

wrong_number_of_parameters_for_operator

Operator '-' should declare 0 or 1 parameter, but {0} found.

Operator '{0}' should declare exactly {1} parameters, but {2} found.

Description

#

The analyzer produces this diagnostic when a declaration of an operator has the wrong number of parameters.

Example

#

The following code produces this diagnostic because the operator + must have a single parameter corresponding to the right operand:

dart
class C {
  int operator +(a, b) => 0;
}

Common fixes

#

Add or remove parameters to match the required number:

dart
class C {
  int operator +(a) => 0;
}