abstract class A { void foo(A a); }
abstract class B { void foo(B b); }
class C implements A, B {
@override // Analyzer says: info: method doesn't override an inherited
method.
void foo(covariant C c) {}
}
This seems to work as intended. We have the following in the documentation for @override: 'The annotation @override marks an instance member as overriding a superclass member with the same name', and the superclass of C is Object. It may have been intended to specify that it should be a _concrete_ declaration in that superclass (such that the easy-to-remember rule would be that it is about implementations), but already the use of 'superclass' does make the observed behavior compliant with the documentation.
Sorry, I should have been clearer; the issue appears to be around covariant. In particular, this does not generate a warning:
abstract class A { void foo(A a); }
class C implements A {
@override
void foo(covariant C c) {}
}
it's when you also implement B, and so the covariant keyword is needed to make the analyzer happy about the override, that the analyzer decided it's not, in fact, an override.
OK, I actually think the analyzer gets confused about something here:
$ cat n017.dart
abstract class A { void foo(A a); }
abstract class B { void foo(B b); }
class C implements A, B {
@override
void foo(C c) {}
}
main() => new C().foo(new C());
$ cat n018.dart
abstract class B { void foo(B b); }
class C implements B {
@override
void foo(C c) {}
}
main() => new C().foo(new C());
$ dartanalyzer --strong n017.dart
Analyzing n017.dart...
error • Invalid override. The type of 'C.foo' ('(C) → void') isn't a subtype of 'A.foo' ('(A) → void') at n017.dart:6:3 • strong_mode_invalid_method_override
hint • Method doesn't override an inherited method at n017.dart:6:8 • override_on_non_overriding_method
1 error and 1 hint found.
$ dartanalyzer --strong n018.dart
Analyzing n018.dart...
error • Invalid override. The type of 'C.foo' ('(C) → void') isn't a subtype of 'B.foo' ('(B) → void') at n018.dart:5:3 • strong_mode_invalid_method_override
1 error found.
So the Method doesn't override hint is shown with class C implements B but not with class C implements A, B (so it does not consider the superclass chain alone), and in the latter case it does not report both invalid override relationships (only the one relative to A.foo).
There may be more things to note, but this is already enough to make it an issue.
I am getting the same error when making an abstract method invisible by using _.
abstract class A {
const A();
Future doWork(Timer timer) async {
await _doWork();
timer.cancel();
}
Future _doWork();
}
class B extends A {
B();
@override
Future _doWork() async {
// Do the hard work here!
await Future.delayed(Duration(seconds: 10), () {});
}
}
Yields the (lint) errors:
[dart] Method doesn't override an inherited method. [override_on_non_overriding_method]
[dart] The method '_doWork' isn't used. [unused_element]
Hi. Is my issue related to the one open here?
I also have this issue that probably is related.
Most helpful comment
I am getting the same error when making an abstract method invisible by using
_.Yields the (lint) errors: