You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is the expected output? What do you see instead?
Expected: program should run without a problem
Actual:
Dartboard: Failed type check: type Function is not assignable to type Iterator
Dart editor: Unhandled exception:
type '() => Iterator<Dynamic>' is not a subtype of type 'Iterator<Dynamic>' of '_iterator@28152909'.
What version of the product are you using? On what operating system?
Version 0.1.0.201204131908, Build 6557
Dart SDK version 6478
Windows 7 Home Premium, 64 bit
Please provide any additional information below.
The text was updated successfully, but these errors were encountered:
Iterable copy(Iterable iterable) {
return new _Iterable(iterable.iterator);
Here's the problem. You aren't calling the iterator function, you are closurizing it. If you write iterable.iterator, you get back a function that, when called, produces an iterator. Here, you want to produce the iterator immediately, so you must write iterable.iterator(). This isn't the first (and certainly not last) occurence of this "issue" (I personally call it the closurization trap).
git log --oneline 85bdb898aeb2ac7cea76489ba0bf4e52ff7a79bf..master
04b054b6 Find sdk path with cli_util (#2567)
36c195b9 Only alert about new prereleases for prereleases (#2556)
00b36394 Stop using deprecated mapMap from pkg:collection (#2544)
477cbe72 Improved expectations in flutter_plugin_format validator test (#2532)
a8e2442b `pub run` Don't write about precompilation if no terminal is attached (#2531)
d83d36a4 Don't precompile dependencies of global activate from path (#2530)
870f395c Sanitize git cache folder names (#2522)
03b7f9a5 Avoid divisive terms (#2523)
b239ada4 Remove divisive term (#2517)
Change-Id: I55ea52a86121a382dca5c0f85addd4513ada50bf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/154940
Reviewed-by: Jonas Jensen <[email protected]>
Commit-Queue: Sigurd Meldgaard <[email protected]>
This issue was originally filed by [email protected]
What steps will reproduce the problem?
I don't know what is the problem with the following program, as
similar pattern works in Java:
bool check(Iterable iter) {
return iter !== null;
}
class _Iterable<E> implements Iterable<E> {
final Iterator<E> _iterator;
_Iterable(this._iterator);
Iterator<E> iterator() {
return _iterator;
}
}
Iterable copy(Iterable iterable) {
return new _Iterable(iterable.iterator);
}
main() {
Expect.isTrue(check(copy([0, 1])));
}
You may try the test program here http://try.dartlang.org/s/zq05
What is the expected output? What do you see instead?
Expected: program should run without a problem
Actual:
Dartboard: Failed type check: type Function is not assignable to type Iterator
Dart editor: Unhandled exception:
type '() => Iterator<Dynamic>' is not a subtype of type 'Iterator<Dynamic>' of '_iterator@28152909'.
What version of the product are you using? On what operating system?
Version 0.1.0.201204131908, Build 6557
Dart SDK version 6478
Windows 7 Home Premium, 64 bit
Please provide any additional information below.
The text was updated successfully, but these errors were encountered: