@@ -6,6 +6,11 @@ Status: Draft
66
77## CHANGELOG
88
9+ 2026.03.31
10+ - Change the function literal return type inference rules to handle
11+ generator return types which are not of the form ` Iterable<...> `
12+ or ` Stream<...> ` .
13+
9142024.12.17
1015 - Change the function literal return type inference rules to ignore
1116 ` return; ` statements in generators (it doesn't actually cause null to be
@@ -268,6 +273,9 @@ has no declared type, it is treated as if it was declared with type `dynamic`.
268273Inference for each returned expression in the body of the function literal is
269274done in an empty typing context (see below).
270275
276+ Function literals which are inferred in a non-empty typing context where the
277+ context type is not a function type are inferred in the empty typing context.
278+
271279Function literals which are inferred in an non-empty typing context where the
272280context type is a function type are inferred as described below.
273281
@@ -287,13 +295,19 @@ function literal is done using a context type derived from the imposed return
287295type schema ` S ` as follows:
288296 - If the function expression is neither ` async ` nor a generator, then the
289297 context type is ` S ` .
290- - If the function expression is declared ` async* ` and ` S ` is of the form
291- ` Stream<S1> ` for some ` S1 ` , then the context type is ` S1 ` .
292- - If the function expression is declared ` sync* ` and ` S ` is of the form
293- ` Iterable<S1> ` for some ` S1 ` , then the context type is ` S1 ` .
294- - Otherwise, without null safety, the context type is ` FutureOr<flatten(T)> `
295- where ` T ` is the imposed return type schema; with null safety, the context
296- type is ` FutureOr<futureValueTypeSchema(S)> ` .
298+ - If the function expression is declared ` async* ` and the element type of
299+ ` S ` as the return type of an asynchronous function is ` S1 ` , then the
300+ context type is ` S1 ` .
301+ - If the function expression is declared ` sync* ` and the element type of
302+ ` S ` as the return type of a synchronous function is ` S1 ` , then the
303+ context type is ` S1 ` .
304+ - If the function expression is declared ` async ` , without null safety, the
305+ context type is ` FutureOr<flatten(T)> ` where ` T ` is the imposed return
306+ type schema; with null safety, the context type is
307+ ` FutureOr<futureValueTypeSchema(S)> ` .
308+ - Otherwise, the context type is ` _ ` . * For example, a ` sync* ` function
309+ literal could have an imposed return type schema ` S ` which is ` int ` ,
310+ and ` int ` doesn't have an element type.*
297311
298312The function ** futureValueTypeSchema** is defined as follows:
299313
0 commit comments