Dart Analyze logoDart Analyze/
DRT-W1670

Undefined operatorDRT-W1670

Major severityMajor
Bug Risk categoryBug Risk

The analyzer produces this diagnostic when a user-definable operator is invoked on an object for which the operator isn't defined.

Example

The following code produces this diagnostic because the class C doesn't define the operator +:

class C {}

C f(C c) => c + 2;

Common fixes

If the operator should be defined for the class, then define it:

class C {
  C operator +(int i) => this;
}

C f(C c) => c + 2;