Skip to content

Commit 6aa7e67

Browse files
authored
Update on top of #941: Some review responses got lost, and flatten(S) must be changed in some locations (#948)
Correct `flatten{S}` to `T_v` in several locations. Update commentary to match changes to return rules. Perform smaller corrections based on review of #941.
1 parent 8924565 commit 6aa7e67

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

accepted/future-releases/nnbd/feature-specification.md

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Status: Draft
1111
static rules for return statements, and dynamic semantics of return in
1212
asynchronous non-generators.
1313
- Add rule that the use of expressions of type `void*` is restricted in
14-
the same way as expressions of type `void`.
14+
the same way as the use of expressions of type `void`.
1515

1616
2020.04.30
1717
- Specify static analysis of `e1 == e2`.
@@ -292,7 +292,8 @@ The function **futureValueType** is defined as follows:
292292

293293
_Note that it is a compile-time error unless the return type of an asynchronous
294294
non-generator function is a supertype of `Future<Never>`, which means that
295-
the last case will only be applied when `S` is a non-`void` top type._
295+
the last case will only be applied when `S` is `Object` or a non-`void` top
296+
type._
296297

297298
### Return statements
298299

@@ -306,46 +307,54 @@ about synchronous non-generator functions, the text is changed as follows:
306307
```
307308
It is a compile-time error if $s$ is \code{\RETURN{} $e$;},
308309
$T$ is neither \VOID{} nor \DYNAMIC,
309-
and $S$ is \VOID{} or \code{\VOID*}.
310+
and $S$ is \VOID.
310311
```
311312

312313
_Comparing to Dart before null-safety, this means that it is no longer allowed
313-
to "return void to null" in a regular function._
314+
to return a void expression in a regular function if the return type is
315+
`Null`._
314316

315-
At [this location](https://github.com/dart-lang/language/blob/65b8267be0ebb9b3f0849e2061e6132021a4827d/specification/dartLangSpec.tex#L15525)
317+
At [this location](https://github.com/dart-lang/language/blob/65b8267be0ebb9b3f0849e2061e6132021a4827d/specification/dartLangSpec.tex#L15507)
316318
about an asynchronous non-generator function with future value type `$T_v$`,
317319
the text is changed as follows:
318320

319321
```
322+
It is a compile-time error if $s$ is \code{\RETURN{};},
323+
unless $T_v$
324+
is \VOID, \DYNAMIC, or \code{Null}.
325+
%
326+
It is a compile-time error if $s$ is \code{\RETURN{} $e$;},
327+
$T_v$ is \VOID,
328+
and \flatten{S} is neither \VOID, \DYNAMIC, \code{Null}.
329+
%
320330
It is a compile-time error if $s$ is \code{\RETURN{} $e$;},
321331
$T_v$ is neither \VOID{} nor \DYNAMIC,
322-
and \flatten{S} is \VOID{} or \code{\VOID*}.
323-
```
324-
325-
_Comparing to Dart before null-safety, this means that it is no longer allowed
326-
to "return void to null" in an `async` function, nor to "return a void future
327-
to null"._
328-
329-
The next sentence is changed as follows:
330-
331-
```
332+
and \flatten{S} is \VOID.
333+
%
332334
It is a compile-time error if $s$ is \code{\RETURN{} $e$;},
333335
\flatten{S} is not \VOID,
334336
$S$ is not assignable to $T_v$,
335337
and flatten{S} is not a subtype of $T_v$.
336338
```
337339

338-
_Comparing to Dart before null-safety, this means that it is now allowed
339-
to return a future when the future value type is a suitable future; for
340-
instance, we can have `return Future<int>.value(42)` in an `async` function
341-
with declared return type `Future<Future<int>>`. Conversely, it is no longer
342-
allowed to return a `Future<dynamic>` or `FutureOr<dynamic>` when the future
343-
value type is `Future<U>` for some `U` which is not a top type._
340+
_Comparing to Dart before null-safety, this means that it is no longer allowed
341+
to return an expression whose flattened static type is `void` in an `async`
342+
function with future value type `Null`; nor is it allowed, in an `async`
343+
function with future value type `void`, to return an expression whose flattened
344+
static type is not `void`, `void*`, `dynamic`, or `Null`. Conversely, it is
345+
allowed to return a future when the future value type is a suitable future;
346+
for instance, we can have `return Future<int>.value(42)` in an `async` function
347+
with declared return type `Future<Future<int>>`. Finally, let `S` be
348+
`Future<dynamic>` or `FutureOr<dynamic>`; it is then no longer allowed to
349+
return an expression with static type `S`, unless the future value type is a
350+
supertype of `S`. This differs from Dart before null-safety in that it was
351+
allowed to return an expression of these types with a declared return type
352+
of the form `Future<T>` for any `T`._
344353

345354
The dynamic semantics specified at
346355
[this location](https://github.com/dart-lang/language/blob/65b8267be0ebb9b3f0849e2061e6132021a4827d/specification/dartLangSpec.tex#L15597)
347356
is changed as follows, where `$f$` is the enclosing function with declared
348-
return type `$T$`, and `$e$` is the returned expression with static type `$S$`:
357+
return type `$T$`, and `$e$` is the returned expression:
349358

350359
```
351360
When $f$ is a synchronous non-generator, evaluation proceeds as follows:

0 commit comments

Comments
 (0)