Skip to content

Adjusted spec of For-In to insist on Iterable #291

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

Merged
merged 4 commits into from
May 2, 2019
Merged

Conversation

eernstg
Copy link
Member

@eernstg eernstg commented Mar 29, 2019

The specification of a for-in statement used to rely on having an iterator member on the iterable, and on being able to do moveNext() and current on the returned object. With this change, we insist that the iterable must actually have type Iterable<T> for some T.

Note that deployed code already requires this (verified with dart and dart2js), and it is already specified for an asynchronous for-in that it is a dynamic error for the iterable to not be a Stream. So this is more consistent, not breaking in practice, and more strongly typed.

@lrhn
Copy link
Member

lrhn commented Mar 29, 2019

The advantage of this change is that we can use Iterable<T> as context type for the iterable expression e of for (T x in e). We currently can't because it might not be an iterable.

My guess is that we are already doing this, which is why implementations fail when it's not actually an iterable.
That's also supported by for (var x in {}); not throwing. By the specification, this should be trying to iterate a map, but since it succeeds, we are obviously iterating a set. That means the context type must already be an iterable type.

@eernstg eernstg merged commit 20087c8 into master May 2, 2019
eernstg added a commit that referenced this pull request May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants