Skip to content

Commit c01d59b

Browse files
eernstgcommit-bot@chromium.org
authored andcommitted
Adjusted generalized-void.md to make for-in on a void iterator an error, except when the iteration variable has type void.
A similar rule applies to asynchronous for-in loops. Change-Id: I88ba234c27a38167eaac0350d269e88894a0fe9e Reviewed-on: https://dart-review.googlesource.com/35920 Reviewed-by: Leaf Petersen <[email protected]> Reviewed-by: Lasse R.H. Nielsen <[email protected]> Commit-Queue: Erik Ernst <[email protected]>
1 parent ae5534a commit c01d59b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

docs/language/informal/generalized-void.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,22 @@ marked `async*`, or `sync*` has return type `void`.
312312
"fire-and-forget" operation, that is, it is not even useful for the caller
313313
to synchronize with the completion of that task.*
314314

315+
It is a static warning (Dart 2: a compile-time error) for a for-in
316+
statement to have an iterator expression of type `T` such that
317+
`Iterator<void>` is the most specific instantiation of `Iterator` that is a
318+
superinterface of `T`, unless the iteration variable has type void.
319+
320+
It is a static warning (Dart 2: a compile-time error) for an asynchronous
321+
for-in statement to have a stream expression of type `T` such that
322+
`Stream<void>` is the most specific instantiation of `Stream` that is a
323+
superinterface of `T`, unless the iteration variable has type void.
324+
325+
*Hence, `for (Object x in <void>[]) {}` and
326+
`await for (int x in new Stream<void>.empty()) {}` are errors, whereas
327+
`for (void x in <void>[]) {...}` and `for (var x in <void>[]) {...}` are OK. The
328+
usage of `x` in the loop body is constrained, though, because it has type
329+
void.*
330+
315331
During bounds checking, it is possible that a bound of a formal type
316332
parameter of a generic class or function is statically known to be the type
317333
void. In this case, the bound is considered to be the built-in class

0 commit comments

Comments
 (0)