diff --git a/docs/language/informal/generalized-void.md b/docs/language/informal/generalized-void.md index 847a1742b93..90bf55f20d4 100644 --- a/docs/language/informal/generalized-void.md +++ b/docs/language/informal/generalized-void.md @@ -312,6 +312,22 @@ marked `async*`, or `sync*` has return type `void`. "fire-and-forget" operation, that is, it is not even useful for the caller to synchronize with the completion of that task.* +It is a static warning (Dart 2: a compile-time error) for a for-in +statement to have an iterator expression of type `T` such that +`Iterator` is the most specific instantiation of `Iterator` that is a +superinterface of `T`, unless the iteration variable has type void. + +It is a static warning (Dart 2: a compile-time error) for an asynchronous +for-in statement to have a stream expression of type `T` such that +`Stream` is the most specific instantiation of `Stream` that is a +superinterface of `T`, unless the iteration variable has type void. + +*Hence, `for (Object x in []) {}` and +`await for (int x in new Stream.empty()) {}` are errors, whereas +`for (void x in []) {...}` and `for (var x in []) {...}` are OK. The +usage of `x` in the loop body is constrained, though, because it has type +void.* + During bounds checking, it is possible that a bound of a formal type parameter of a generic class or function is statically known to be the type void. In this case, the bound is considered to be the built-in class