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 reports error message for sync* and async* functions in a strong mode #27468

Closed
sgrekhov opened this issue Oct 3, 2016 · 9 comments
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. devexp-ux P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@sgrekhov
Copy link
Contributor

sgrekhov commented Oct 3, 2016

class TestItearble<E> extends Iterable<E> {

  @override
  Iterator<E> get iterator => null;
}

TestItearble c() sync* { } // [error] Functions marked 'sync*' must have a return type assignable to 'Iterable'

main() {
  Iterable i = new TestItearble(); // Ok here
  c();
}

In a strong mode analyzer reports that "Functions marked 'sync*' must have a return type assignable to 'Iterable'". But TestItearble from above has type assignable to Iterable. Seems that there should be no error message at all.

The same issue exists for async* functions

import 'dart:async';

class TestStream<T> extends Stream<T> {

  @override
  StreamSubscription<T> listen(void onData(T event),
      {Function onError, void onDone(), bool cancelOnError}) => null;
}

TestStream c() async* { }// [error] Functions marked 'async*' must have a return type assignable to 'Stream'

main() {
  c();
}
@floitschG floitschG added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Oct 3, 2016
@floitschG
Copy link
Contributor

There are two parts to this bug: the error message that isn't "correct", and the question if we should even allow it.
Clearly, the sync* and async* will never return a subclass of Iterable/Stream, so the analyzer is right in telling users that this will not work.
However, I don't think that the language currently prohibits implicit downcasts in the return type for sync* and async* functions. I opened #27470 for the language.

@bwilkerson bwilkerson added analyzer-strong-mode P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Oct 3, 2016
@jmesserly
Copy link

this was an intentional strong mode bug fix. Your return type of TestStream will always fail. Offhand I don't remember the bug but I might be able to dig it up.

@jmesserly jmesserly added the closed-as-intended Closed as the reported issue is expected behavior label Oct 3, 2016
@jmesserly
Copy link

This was #25854.

@floitschG
Copy link
Contributor

The message is wrong, though.

The given return type is assignable to Iterable.

@floitschG floitschG reopened this Oct 3, 2016
@jmesserly
Copy link

sure, we can tweak the wording. The return type must be Iterable<T> for some T.

@floitschG
Copy link
Contributor

It can also be Object.

@lrhn
Copy link
Member

lrhn commented Oct 5, 2016

Spec is now changed to "must be a supertype of Iterable<T> for some T" (basically, must be a supertype of Iterable<⊥>).

That also allows dynamic and Object, as well as Iterable<T>, but doesn't allow any subclass of Iterable.

If it is, e.g., Iterable<int> then the yield sematnics will complain if it isn't yielding int values.

@jmesserly jmesserly added devexp-ux and removed closed-as-intended Closed as the reported issue is expected behavior labels Oct 5, 2016
@jmesserly
Copy link

this error message could still be improved.

@srawlins
Copy link
Member

srawlins commented Jun 8, 2020

This error is still present. ☹️

@srawlins srawlins self-assigned this Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. devexp-ux P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

6 participants