Skip to content

Commit

Permalink
Avoid depending on iterator.current != null. (#877)
Browse files Browse the repository at this point in the history
With the NNBD change to Dart, it's no longer safe to rely on an iterator returning `null` when it has hit the end (or before calling `moveNext` the first time). For non-nullable element types, it will have to throw instead.

This PR rewrites code that currently rely on a `null` value to recognize the end of an iterator.
  • Loading branch information
lrhn authored and nex3 committed Jan 7, 2020
1 parent e110961 commit 31c0960
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/src/extend/functions.dart
Expand Up @@ -522,14 +522,17 @@ List<List<T>> paths<T>(Iterable<List<T>> choices) => choices.fold(
QueueList<List<ComplexSelectorComponent>> _groupSelectors(
Iterable<ComplexSelectorComponent> complex) {
var groups = QueueList<List<ComplexSelectorComponent>>();
var iterator = complex.iterator..moveNext();
while (iterator.current != null) {
var group = <ComplexSelectorComponent>[];
do {
var iterator = complex.iterator;
if (!iterator.moveNext()) return groups;
var group = <ComplexSelectorComponent>[iterator.current];
groups.add(group);
while (iterator.moveNext()) {
if (group.last is Combinator || iterator.current is Combinator) {
group.add(iterator.current);
} while (iterator.moveNext() &&
(iterator.current is Combinator || group.last is Combinator));
groups.add(group);
} else {
group = [iterator.current];
groups.add(group);
}
}
return groups;
}
Expand Down

0 comments on commit 31c0960

Please sign in to comment.