From c0c4dd1b0e978881b5cfd7738dc6eab7f5855a04 Mon Sep 17 00:00:00 2001 From: Erik Ernst Date: Thu, 9 Jul 2026 15:43:37 +0200 Subject: [PATCH 1/2] Change inference.md as needed for 4718 --- resources/type-system/inference.md | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/resources/type-system/inference.md b/resources/type-system/inference.md index 66f89fdd85..0c80b79fe6 100644 --- a/resources/type-system/inference.md +++ b/resources/type-system/inference.md @@ -6,6 +6,10 @@ Status: Draft ## CHANGELOG +2026.07.09 + - Remove a spurious `Null` from the element type inferred for a generator + function literal when the end of the body is reachable. + 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 @@ -318,13 +322,20 @@ inferred type of the expression body, using the local type inference algorithm described below with a typing context as computed above. The actual returned type of a function literal with a block body is computed as -follows. Let `T` be `Never` if every control path through the block exits the -block without reaching the end of the block, as computed by the **definite -completion** analysis specified elsewhere. Let `T` be `Null` if any control -path reaches the end of the block without exiting the block, as computed by the -**definite completion** analysis specified elsewhere. Let `K` be the typing -context for the function body as computed above from the imposed return type -schema. +follows. + + - When the function literal is a generator, let `T` be `Never`. + - When the function literal is not a generator: + - Let `T` be `Never` if every control path through the block exits the + block without reaching the end of the block, as computed by the + **definite completion** analysis specified elsewhere. + - Let `T` be `Null` if any control path reaches the end of the block + without exiting the block, as computed by the **definite completion** + analysis specified elsewhere. + +Let `K` be the typing context for the function body as computed above from the +imposed return type schema. + - For each `return 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(flatten(S), T)` if the enclosing From 5582868b649a97ebf02345ba5122ffbb48ed8d56 Mon Sep 17 00:00:00 2001 From: Erik Ernst Date: Fri, 10 Jul 2026 15:01:55 +0200 Subject: [PATCH 2/2] Trailing space --- resources/type-system/inference.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/type-system/inference.md b/resources/type-system/inference.md index 0c80b79fe6..2b438f9381 100644 --- a/resources/type-system/inference.md +++ b/resources/type-system/inference.md @@ -332,7 +332,7 @@ follows. - Let `T` be `Null` if any control path reaches the end of the block without exiting the block, as computed by the **definite completion** analysis specified elsewhere. - + Let `K` be the typing context for the function body as computed above from the imposed return type schema.