Skip to content
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

Dartanalyzer does not allow declare class A with "X extends FutureOr<A<X>>" type parameter . #34264

Closed
iarkh opened this issue Aug 27, 2018 · 4 comments
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Milestone

Comments

@iarkh
Copy link
Contributor

iarkh commented Aug 27, 2018

Dart SDK Version: 2.1.0-dev.2.0
OS: Windows 10 (64 bit)

The following code sample declares two classes with Future and FutureOr type parameters:

import "dart:async";

class B<X extends Future<A<X>>> {}
class A<X extends FutureOr<A<X>>> {}

Dart passes with both code lines, i.e. just print OK as a result.

Dartanalyzer passes with class B<X extends Future<A<X>>> {} and fails with class A<X extends FutureOr<A<X>>> {}, sample output is:

Analyzing test.dart...
  error - 'X' doesn't extend 'FutureOr<A<X>>' at test.dart:4:30 - type_argument_not_matching_bounds
1 error found.

I believe this is incorrect result and analyzer should pass both for Future and FutureOr parameters.

@eernstg eernstg added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Aug 27, 2018
@askeksa-google
Copy link

askeksa-google commented Aug 27, 2018

The spec says (in 10.9):
"It is a compile-time error if the type in the extends clause of a class C is a type variable (14), a type alias (19.3.1), an enumerated type (13), a malformed type (19.1), a deferred type (19.1), type dynamic (19.6), or type FutureOr<T> for any T (19.7)."
So the class declaration with FutureOr as supertype is not valid Dart. See also #33744

@eernstg
Copy link
Member

eernstg commented Aug 27, 2018

Oh, but in this case we do not use FutureOr<..> as a superclass, we use it as the bound of a type variable (in this case: an F-bounded one), and I couldn't spot any reason why that would be an error.

It's not even impossible to find a type argument that satisfies this constraint: A<Null> would do, and with class C extends A<C> {}, A<C> would do as well (C can be given as an actual type argument to A in the first place because C <: A<C> <: FutureOr<A<C>>), and similarly for class D extends Future<A<D>>> {} and A<D>.

@iarkh
Copy link
Contributor Author

iarkh commented Aug 27, 2018

And anyway, analyzer and dart should behave in the same way here.

@eernstg
Copy link
Member

eernstg commented Oct 7, 2020

Closing: dart as well as dartanalyzer accepts the example program as of a49217b.

@eernstg eernstg closed this as completed Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

7 participants