dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.25k stars 1.58k forks source link

Analyzer checks overriding between superclass and superinterface incorrectly. #36432

Closed iarkh closed 5 years ago

iarkh commented 5 years ago

DART version: 2.2.1-dev-1.1 OS: Windows 10 64 bit

This bug is similar with #34392 which was fixed some time ago.

Here is a source code example:

abstract class I { foo(a) {} }

abstract class A { foo() {} }
abstract class B { another() {} }

abstract class C extends A implements I {}    // compile error here
abstract class D extends B implements I {}    // no error here

main() {}

Analyzer throws a compile error for the line #6 and passes with the line #7:

Analyzing test.dart... error - Superinterfaces don't have a valid override for 'foo': I.foo ((dynamic) → dynamic), A.foo (() → dynamic) at test.dart:6:16 - inconsistent_inheritance 1 error found.

Seems like it should pass in both cases.

Please note that #34392 source example passes with the recent dart versions.

If I run my test with dart, it passes as well.

eernstg commented 5 years ago

This is working as intended.

You need to say foo([a]) in I in order to make that signature more specific than A.foo. Otherwise you just have two incomparable signatures for foo in the superinterfaces of C, and that makes the declaration of C an error.

Alternatively, if you add the declaration foo([a]); to the body of C then that declaration is a correct override of both A.foo and I.foo, and there is no error.

But it sounds like the front end is too forgiving ... testing ... no: I get an error for line 6 from dart (version 2.1.1-dev.3.2 plus a fresh one from 28e658814fc9d3d17631597b385f7ca0cb1f7fb9):

n002.dart:6:16: Error: The method 'C.foo' has more required arguments than those of overridden method 'A.foo'.
abstract class C extends A implements I {}    // compile error here
               ^
iarkh commented 5 years ago

I tested this with 2.2.1-dev-1.1 and dart passed for me. So, seems like it's fixed in the next release.

eernstg commented 5 years ago

I get the same response (error on line 6) from dart version 2.2.1-dev.1.1 as I did for the other versions (older and newer than that), which is also the response we should get, and also the response that we get from dartanalyzer.

But I'm not quite sure what you mean by 'it passed for me'. Do you mean that you have a version of dart that does not report an error for line 6? That would be a bug, but I can't recreate that behavior.

iarkh commented 5 years ago

Sorry for inaccuracy! Dart report compile error on the line 6 too, so if it's expected this bug can be closed.

eernstg commented 5 years ago

Yep, that error is expected. Thanks!

kevmoo commented 5 years ago

@eernstg – is there a bug here? For whom? Otherwise, please close! 😄