| OLD | NEW |
| 1 ## Feature: Generalized Void | 1 ## Feature: Generalized Void |
| 2 | 2 |
| 3 Author: eernst@ | 3 Author: eernst@ |
| 4 | 4 |
| 5 **Status**: Under implementation. | 5 **Status**: Under implementation. |
| 6 | 6 |
| 7 **This document** is an informal specification of the generalized support | 7 **This document** is an informal specification of the generalized support |
| 8 in Dart 1.x for the type `void`. Dart 2 will have a very similar kind of | 8 in Dart 1.x for the type `void`. Dart 2 will have a very similar kind of |
| 9 generalized support for `void`, without the function type subtype exception | 9 generalized support for `void`, without the function type subtype exception |
| 10 that this feature includes for backward compatibility in Dart 1.x. This | 10 that this feature includes for backward compatibility in Dart 1.x. This |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 able to treat the type void as `Object` in all cases during subtype | 263 able to treat the type void as `Object` in all cases during subtype |
| 264 checks.* | 264 checks.* |
| 265 | 265 |
| 266 It is a static warning for an expression to have type void, except for the | 266 It is a static warning for an expression to have type void, except for the |
| 267 following situations: | 267 following situations: |
| 268 | 268 |
| 269 * In an expressionStatement `e;`, e may have type void. | 269 * In an expressionStatement `e;`, e may have type void. |
| 270 * In the initialization and increment expressions of a for-loop, | 270 * In the initialization and increment expressions of a for-loop, |
| 271 `for (e1; e2; e3) {..}`, `e1` and `e3` may have type void. | 271 `for (e1; e2; e3) {..}`, `e1` and `e3` may have type void. |
| 272 * In a typeCast `e as T`, `e` may have type void. | 272 * In a typeCast `e as T`, `e` may have type void. |
| 273 * In a typeTest `e is T` or `e is! T`, `e` may have type void. | |
| 274 * In a parenthesized expression `(e)`, `e` may have type void. | 273 * In a parenthesized expression `(e)`, `e` may have type void. |
| 275 * In a return statement `return e;`, when the return type of the innermost | 274 * In a return statement `return e;`, when the return type of the innermost |
| 276 enclosing function is the type void, `e` may have type void. | 275 enclosing function is the type void, `e` may have type void. |
| 277 | 276 |
| 278 *Note that the parenthesized expression itself has type void, so it is | 277 *Note that the parenthesized expression itself has type void, so it is |
| 279 again subject to the same constraints. Also note that we may not allow | 278 again subject to the same constraints. Also note that we may not allow |
| 280 return statements returning an expression of type void in the future, but | 279 return statements returning an expression of type void in the future, but |
| 281 it is allowed here for backward compatibility.* | 280 it is allowed here for backward compatibility.* |
| 282 | 281 |
| 283 During bounds checking, it is possible that a bound of a formal type | 282 During bounds checking, it is possible that a bound of a formal type |
| (...skipping 21 matching lines...) Expand all Loading... |
| 305 this would presumably require a transitive traversal of all generic classes | 304 this would presumably require a transitive traversal of all generic classes |
| 306 and functions where the corresponding formal type parameter is passed on to | 305 and functions where the corresponding formal type parameter is passed on to |
| 307 other generic classes or functions, which would be highly brittle: A tiny | 306 other generic classes or functions, which would be highly brittle: A tiny |
| 308 change to a generic class or function could break code far away. So we do | 307 change to a generic class or function could break code far away. So we do |
| 309 not wish to prevent formal type parameter bounds from indirectly becoming | 308 not wish to prevent formal type parameter bounds from indirectly becoming |
| 310 the type void. This motivated the decision to treat such a void-valued | 309 the type void. This motivated the decision to treat such a void-valued |
| 311 bound as `Object`. | 310 bound as `Object`. |
| 312 | 311 |
| 313 ## Updates | 312 ## Updates |
| 314 | 313 |
| 314 * August 16h 2017: Removed exceptions allowing `e is T` and `e is! T`. |
| 315 |
| 315 * August 9th 2017: Transferred to SDK repo, docs/language/informal. | 316 * August 9th 2017: Transferred to SDK repo, docs/language/informal. |
| 316 | 317 |
| 317 * July 16th 2017: Reformatted as a gist. | 318 * July 16th 2017: Reformatted as a gist. |
| 318 | 319 |
| 319 * June 13th 2017: Compile-time error for using a void value was changed to | 320 * June 13th 2017: Compile-time error for using a void value was changed to |
| 320 static warning. | 321 static warning. |
| 321 * June 12th 2017: Grammar changed extensively, to use | 322 * June 12th 2017: Grammar changed extensively, to use |
| 322 `typeNotVoid` rather than | 323 `typeNotVoid` rather than |
| 323 `voidOrType`. | 324 `voidOrType`. |
| 324 * June 5th 2017: Added `typeCast` and | 325 * June 5th 2017: Added `typeCast` and |
| 325 `typeTest` to the locations where void | 326 `typeTest` to the locations where void |
| 326 expressions may occur. | 327 expressions may occur. |
| OLD | NEW |