Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Unified Diff: sdk/lib/core/iterable.dart

Issue 1895473004: Make dart:core strong-mode clean. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « CHANGELOG.md ('k') | sdk/lib/core/num.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/iterable.dart
diff --git a/sdk/lib/core/iterable.dart b/sdk/lib/core/iterable.dart
index dd195023655e93658810725bd989c256ea3c339d..d553a33d2f81abe6cb8761e7b0615dfb28adab17 100644
--- a/sdk/lib/core/iterable.dart
+++ b/sdk/lib/core/iterable.dart
@@ -451,7 +451,7 @@ abstract class Iterable<E> {
* equivalent to `(iterator..moveNext())..current`.
*/
E get first {
- Iterator it = iterator;
+ Iterator<E> it = iterator;
if (!it.moveNext()) {
throw IterableElementError.noElement();
}
@@ -469,7 +469,7 @@ abstract class Iterable<E> {
* without iterating through the previous ones).
*/
E get last {
- Iterator it = iterator;
+ Iterator<E> it = iterator;
if (!it.moveNext()) {
throw IterableElementError.noElement();
}
@@ -486,7 +486,7 @@ abstract class Iterable<E> {
* Throws a [StateError] if `this` is empty or has more than one element.
*/
E get single {
- Iterator it = iterator;
+ Iterator<E> it = iterator;
if (!it.moveNext()) throw IterableElementError.noElement();
E result = it.current;
if (it.moveNext()) throw IterableElementError.tooMany();
@@ -610,9 +610,19 @@ class _GeneratorIterable<E> extends Iterable<E>
final int _start;
final int _end;
final _Generator<E> _generator;
+
+ /// Creates an iterable that builds the elements from a generator function.
+ ///
+ /// The [generator] may be null, in which case the default generator
+ /// enumerating the integer positions is used. This means that [int] must
+ /// be assignable to [E] when no generator is provided. In practice this means
+ /// that the generator can only be emitted when [E] is equal to `dynamic`,
+ /// `int`, or `num`. The constructor will check that the types match.
_GeneratorIterable(this._end, E generator(int n))
: _start = 0,
- _generator = (generator != null) ? generator : _id;
+ // The `as` below is used as check to make sure that `int` is assignable
+ // to [E].
+ _generator = (generator != null) ? generator : _id as _Generator<E>;
_GeneratorIterable.slice(this._start, this._end, this._generator);
« no previous file with comments | « CHANGELOG.md ('k') | sdk/lib/core/num.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698