diff --git a/resources/type-system/inference.md b/resources/type-system/inference.md index f33b439e78..49d954b3d6 100644 --- a/resources/type-system/inference.md +++ b/resources/type-system/inference.md @@ -6,6 +6,10 @@ Status: Draft ## CHANGELOG +2023.06.15 + - Adjust function literal return type inference to avoid spurious application + of `flatten`. + 2022.05.12 - Define the notions of "constraint solution for a set of type variables" and "Grounded constraint solution for a set of type variables". These @@ -345,15 +349,22 @@ all `return` and `yield` statements in the block body have been considered. Let `T` be the **actual returned type** of a function literal as computed above. Let `R` be the greatest closure of the typing context `K` as computed above. +*Now compute `S`, which is the future value type of an `async` function, the +element type of a generator function, and the return type of other functions.* + With null safety: if `R` is `void`, or the function literal is marked `async` and `R` is `FutureOr`, let `S` be `void` (without null-safety: no special treatment is applicable to `void`). -Otherwise, if `T <: R` then let `S` be `T`. Otherwise, let `S` be `R`. The -inferred return type of the function literal is then defined as follows: +If the previous paragraph did not yield a value for `S`: When the function is +marked `async`: if `T <: futureValueType(R)` then let `S` be `T`; otherwise let +`S` be `futureValueType(R)`. When the function is not marked `async`: if `T <: +R` then let `S` be `T`; otherwise let `S` be `R`. + +The inferred return type of the function literal is then defined as follows: - If the function literal is marked `async` then the inferred return type is - `Future`. + `Future`. - If the function literal is marked `async*` then the inferred return type is `Stream`. - If the function literal is marked `sync*` then the inferred return type is