From c01d59bc7e89b2fa534d63293f67b51a4cea51eb Mon Sep 17 00:00:00 2001 From: Erik Ernst Date: Wed, 14 Feb 2018 18:44:03 +0000 Subject: [PATCH] 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 Reviewed-by: Lasse R.H. Nielsen Commit-Queue: Erik Ernst --- docs/language/informal/generalized-void.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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