Skip to content

Dartanalyzer 2.0 incorrectly throws type_argument_not_matching_bounds error for super-bounded types in preview-dart-2 mode #32903

Closed
@iarkh

Description

@iarkh

Dart SDK Version: 2.0.0-dev.48.0
OS: Windows 10

Dart 2.0 Super Bounded Types Spec reads:

The feature described here, super-bounded types, consists in allowing an actual type argument to be a supertype of the declared bound, as long as a consistent replacement of Object, dynamic, and void by Null produces a traditional, well-bounded type. For example, if a class C takes a type argument X which must extend C<X>, C<Object>, C<dynamic>, and C<void> are correct super-bounded types.
We extend covariance for generic class types such that it can be used also in cases where a type argument violates the corresponding bound.
For instance, assuming the classes C and D as declared in the Motivation section, C<D> is a subtype of C<Object>. This is new because C<Object> used to be a compile-time error, which means that no questions could be asked about its properties. Note that this is a straightforward application of the usual covariance rule: C<D> <: C<Object> because D <: Object. We need this relaxation of the rules in order to be able to define which violations of the declared bounds are admissible.

This means that constructions like C<dynamic> c0 = ... now should be allowed in strong mode for bounded types like class C<X extends C<X>>.

However, this is not so. For example, the following code sample:

class C<X extends C<X>> {}
class D extends C<D> {}
main() { C<dynamic> c = new D(); }

produces type_argument_not_matching_bounds error:

$> dartanalyzer --preview-dart-2 test.dart
Analyzing test.dart...
  error - 'dynamic' doesn't extend 'C' at test.dart:3:12 - type_argument_not_matching_bounds
  hint - The value of the local variable 'c' isn't used at test.dart:3:21 - unused_local_variable
1 error and 1 hint found.

Metadata

Metadata

Assignees

No one assigned

    Labels

    legacy-area-analyzerUse area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions