From 2ec72c15af8526f10487986ffef0cce51b1dc2c9 Mon Sep 17 00:00:00 2001 From: Erik Ernst Date: Tue, 17 Dec 2024 14:37:27 +0100 Subject: [PATCH 1/2] Adjust function literal return type inference to avoid spurious null --- resources/type-system/inference.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/resources/type-system/inference.md b/resources/type-system/inference.md index 05590bc3aa..4e921f1b9d 100644 --- a/resources/type-system/inference.md +++ b/resources/type-system/inference.md @@ -6,6 +6,11 @@ Status: Draft ## CHANGELOG +2024.12.17 + - Change the function literal return type inference rules to ignore + `return;` statements in generators (it doesn't actually cause null to be + returned). + 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 @@ -324,7 +329,8 @@ schema. `e`, using the local type inference algorithm described below with typing context `K`, and update `T` to be `UP(flatten(S), T)` if the enclosing function is `async`, or `UP(S, T)` otherwise. - - For each `return;` statement in the block, update `T` to be `UP(Null, T)`. + - If the enclosing function is not marked `sync*` or `async*`: For each + `return;` statement in the block, update `T` to be `UP(Null, T)`. - For each `yield e;` statement in the block, let `S` be the inferred type of `e`, using the local type inference algorithm described below with typing context `K`, and update `T` to be `UP(S, T)`. From b3d397e304738edd9b2f35cd27b7be2dda419c6f Mon Sep 17 00:00:00 2001 From: Erik Ernst Date: Mon, 6 Jan 2025 18:11:12 +0100 Subject: [PATCH 2/2] Review response --- resources/type-system/inference.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/resources/type-system/inference.md b/resources/type-system/inference.md index 4e921f1b9d..66f89fdd85 100644 --- a/resources/type-system/inference.md +++ b/resources/type-system/inference.md @@ -345,6 +345,11 @@ schema. `Stream`; let `E` be the type such that `Stream` is a super-interface of `S`; and update `T` to be `UP(E, T)`. +In these rules, 'in the block' refers to return and yield statements that +will complete the execution of the function literal under inference, not +the ones, if any, that will complete the execution of a nested function +body. + The **actual returned type** of the function literal is the value of `T` after all `return` and `yield` statements in the block body have been considered.