@@ -352,15 +352,15 @@ and the values emitted by generator functions._
352
352
353
353
Let ` K ` be the value context schema for the function body as computed above
354
354
from the imposed return type schema.
355
- _ When we refer to the _ inferred type _ of an expression with a typing context,
356
- it is the type inferred using the local type inference algorithm
357
- described below._
355
+ _ When we refer to the inferred type of an expression with a typing context,
356
+ it is the static type of the expression inferred using the local type inference
357
+ algorithm described below._
358
358
359
359
The actual value type of a function literal with an expression body, ` => e ` ,
360
360
_ (which cannot be a generator function)_ is computed as follows:
361
361
- If the enclosing function is marked ` async ` ,
362
- let ` T ` be the inferred type of the returned expession with ` FutureOr<K> `
363
- as typing context.
362
+ then let ` T ` be the inferred type of the returned expession with
363
+ ` FutureOr<K> ` as typing context.
364
364
The actual value type is ** flatten** (` T ` ).
365
365
- If the enclosing function is not marked ` async ` , let ` T ` be the inferred
366
366
type of the returned expression with typing context ` K ` .
@@ -380,17 +380,16 @@ to find a value type `V` for that statement.
380
380
381
381
- If the enclosing function is a non-` async ` non-generator function,
382
382
the relevant statements are ` return; ` or ` return e; ` statements.
383
- - For a ` return; ` statement, let ` V ` be ` Null ` .
384
- - For a ` return e; ` statement, let ` V ` be the inferred type of ` e ` with
385
- ` K ` as context type scheme, using the local type inference algorithm
386
- described below.
383
+ * For a ` return; ` statement, let ` V ` be ` Null ` .
384
+ * For a ` return e; ` statement, let ` V ` be the inferred type of ` e ` with
385
+ ` K ` as context type scheme.
387
386
388
387
- If the enclosing function is marked ` async ` , the relevant statements
389
- are ` return; ` and ` return e; ` statements.
388
+ are ` return; ` and ` return e; ` statements.
390
389
* For a ` return; ` statement, let ` V ` be ` Null ` .
391
- * For a ` return e; ` statement, let ` S ` be the inferred type of ` e `
392
- with typing context ` _ ` if ` K ` is ` _ ` ,
393
- and with typing context ` FutureOr<K> ` if ` K ` is not ` _ ` ,
390
+ * For a ` return e; ` statement,
391
+ then let ` S ` be the inferred type of ` e ` with typing context
392
+ ` FutureOr<K> ` .
394
393
Let ` V ` be ** flatten** (` S ` ).
395
394
396
395
- If the enclosing function is marked ` sync* ` , the relevant statements
@@ -417,7 +416,7 @@ to find a value type `V` for that statement.
417
416
` Stream<Object?> ` , so either ` S ` implements ` Stream ` ,
418
417
or it is one of ` dynamic ` or ` Never ` ._
419
418
420
- After processing each relevant statement, update ` T ` to be ** UP** (` T ` , ` V ` ).
419
+ After processing each relevant statement, update ` T ` to be ** UP** (` V ` , ` T ` ).
421
420
422
421
The ** actual value type** of the function literal is the value of ` T ` after
423
422
all relevant ` return ` and ` yield ` statements in the block body have been
@@ -426,12 +425,17 @@ processed.
426
425
Let ` T ` be the ** actual value type** of a function literal as computed above.
427
426
Let ` R ` be the greatest closure of the typing context ` K ` as computed above.
428
427
428
+ _ Then compute the actual value/element type, ` S ` , to use in the inferred return
429
+ type of the function literal, based on the _ actual value type_ , but bounded
430
+ by the _ typing context_ , if any._
431
+
429
432
With null safety, if ` R ` is ` void ` , let ` S ` be ` void `
430
433
_ (without null-safety: no special treatment is applicable to ` void ` )_ .
431
434
432
- Otherwise (_ without null safety or if ` R ` is not ` void ` _ ),
433
- if ` T <: R ` then let ` S ` be ` T ` , else let ` S ` be ` R ` . The
434
- inferred return type of the function literal is then defined as follows:
435
+ Otherwise (_ if ` R ` is not ` void ` , or without null safety_ ),
436
+ if ` T <: R ` then let ` S ` be ` T ` , else let ` S ` be ` R ` .
437
+
438
+ The inferred return type of the function literal is then defined as follows:
435
439
436
440
- If the function literal is marked ` async ` then the inferred return type is
437
441
` Future<S> ` .
0 commit comments