Skip to content

Commit 31c0960

Browse files
lrhnnex3
authored andcommitted
Avoid depending on iterator.current != null. (#877)
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.
1 parent e110961 commit 31c0960

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/src/extend/functions.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -522,14 +522,17 @@ List<List<T>> paths<T>(Iterable<List<T>> choices) => choices.fold(
522522
QueueList<List<ComplexSelectorComponent>> _groupSelectors(
523523
Iterable<ComplexSelectorComponent> complex) {
524524
var groups = QueueList<List<ComplexSelectorComponent>>();
525-
var iterator = complex.iterator..moveNext();
526-
while (iterator.current != null) {
527-
var group = <ComplexSelectorComponent>[];
528-
do {
525+
var iterator = complex.iterator;
526+
if (!iterator.moveNext()) return groups;
527+
var group = <ComplexSelectorComponent>[iterator.current];
528+
groups.add(group);
529+
while (iterator.moveNext()) {
530+
if (group.last is Combinator || iterator.current is Combinator) {
529531
group.add(iterator.current);
530-
} while (iterator.moveNext() &&
531-
(iterator.current is Combinator || group.last is Combinator));
532-
groups.add(group);
532+
} else {
533+
group = [iterator.current];
534+
groups.add(group);
535+
}
533536
}
534537
return groups;
535538
}

0 commit comments

Comments
 (0)