Skip to content

Negate/Inverse operator overrides #60139

@nicholasspencer

Description

@nicholasspencer

It seems that with Dart 3.7, we're getting a lint error saying that our inverse operator overrides an inherited member. Fine, annotate with @override even though we have not defined it in our inherited type. However, once that is added it complains that it doesn't override anything. Which is true. The issue resolves if we add the operator to our super type but that causes a whole set of other problems for us.

The expectation is that we shouldn't have to annotate this operator since it isn't implemented in the super type.

Maybe we're doing something funny but this has been fine for us for years up until this release.

abstract class Foo {
  const Foo(this.value);

  final int value;

  Foo operator -(Foo other);
}

class Bar extends Foo {
  const Bar(super.value);

  @override
  Bar operator -(Foo other) {
    return Bar(value - other.value);
  }

  Bar operator -() {
    return Bar(-value);
  }
}

Steps to reproduce:

  1. dart create -t package inverse_operator with the default lint package and options.
  2. Drop the above code into lib/
  3. dart analyze with 3.6 and 3.7.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packagelinter-false-positiveIssues related to lint rules that report a problem when it isn't a problem.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions