Skip to content

NNBD: Both dart and analyzer allow inherit two interfaces with incompatible type parameters: Object? vs dynamic and Object? vs void. #40453

@iarkh

Description

@iarkh

Dart VM version: 2.8.0-edge.40f23c735f04433e4fc334fbd674474bd3de0f8b (Tue Jan 28 01:14:48 2020 +0000) on "linux_x64"

The following source code declares classes X1 and X2 which inherit classes with incompatible type arguments:

class A<T>{}
class B implements A<Object?> {}

class C implements A<void> {}
class D implements A<dynamic> {}

class X1 extends B implements C {}
class X2 extends B implements D {}

main() {}

This code throws compile error with previous dart versions (for example, 2.7.0) and it seems like dart should do so, for example, see Classes defined in opted-in libraries in NNBD Spec:

If a class C in an opted-in library implements the same generic class I more than once as I0, .., In, and at least one of the Ii is not syntactically equal to the others, then it is an error if NNBD_TOP_MERGE(S0, ..., Sn) is not defined where Si is NORM(Ii). Otherwise, for the purposes of runtime subtyping checks, C is considered to implement the canonical interface given by NNBD_TOP_MERGE(S0, ..., Sn).

However, current both dart and analyzer do not throw error here, sample output is:

$ dart --enable-experiment=non-nullable test.dart
$ dartanalyzer --enable-experiment=non-nullable test.dart
Analyzing test.dart...
No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    closed-as-intendedClosed as the reported issue is expected behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions