Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
iarkh opened this issue Apr 17, 2018 · 2 comments
Labels
legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Milestone

Comments

@iarkh
Copy link
Contributor

iarkh commented Apr 17, 2018

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.
@iarkh
Copy link
Contributor Author

iarkh commented Oct 6, 2018

This is the same as issue #34560 which has been closed several days ago, so I believe this bug is also fixed now.

@bwilkerson
Copy link
Member

Thanks for noticing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants