@@ -2073,30 +2073,38 @@ \section{Functions}
2073
2073
a function marked \code{\SYNC*} or \code{\ASYNC*} is \VOID.
2074
2074
2075
2075
\LMHash{}%
2076
- We define the notion of the
2077
- \IndexCustom{element type of a generator}{function!generator!element type}
2078
- as follows:
2076
+ We define the
2077
+ \Index{union-free type}
2078
+ of a type $T$ as follows:
2079
+ If $T$ is of the form \code{$S$?}\ or the form \code{FutureOr<$S$>}
2080
+ then the union-free type of $T$ is the union-free type of $S$.
2081
+ Otherwise, the union-free type of $T$ is $T$.
2082
+ \commentary{%
2083
+ For example, the union-free type of \code{FutureOr<int?>?} is \code{int}.%
2084
+ }
2085
+
2086
+ \LMHash{}%
2087
+ We define the
2088
+ \IndexCustom{element type of a generator function}{%
2089
+ function!generator!element type}
2090
+ $f$ as follows:
2091
+ %
2092
+ Let $S$ be the union-free type of the declared return type of $f$.
2079
2093
%
2080
- If the function $f$ is a synchronous generator
2081
- whose declared return type implements \code{Iterable<$U$>} for some $U$
2094
+ If $f$ is a synchronous generator and
2095
+ $S$ implements \code{Iterable<$U$>} for some $U$
2082
2096
(\ref{interfaceSuperinterfaces})
2083
2097
then the element type of $f$ is $U$.
2084
2098
%
2085
- If the function $f$ is an asynchronous generator
2086
- whose declared return type implements \code{Stream<$U$>} for some $U$
2099
+ If $f$ is an asynchronous generator and
2100
+ $S$ implements \code{Stream<$U$>} for some $U$
2087
2101
then the element type of $f$ is $U$.
2088
2102
%
2089
- Otherwise, if the function $f$ is a generator
2090
- (\commentary{synchronous or asynchronous})
2103
+ Otherwise, if $f$ is a generator (synchronous or asynchronous)
2104
+ and $S$ is a supertype of \code{Object}
2105
+ (\commentary{which includes \code{Object} itself})
2091
2106
then the element type of $f$ is \DYNAMIC.
2092
-
2093
- \commentary{%
2094
- %% TODO(eernst): Come nnbd, change `a top type' to \DYNAMIC.
2095
- In the latter case the return type is a top type,
2096
- because the declaration of $f$ would otherwise be a compile-time error.
2097
- This implies that there is no information about
2098
- the type of elements that the generator will yield.%
2099
- }
2107
+ \commentary{No further cases are possible.}
2100
2108
2101
2109
2102
2110
\subsection{Function Declarations}
@@ -12463,10 +12471,10 @@ \subsection{Function Invocation}
12463
12471
If $f$ is marked \code{\SYNC*} (\ref{functions}),
12464
12472
then a fresh instance (\ref{generativeConstructors}) $i$
12465
12473
implementing \code{Iterable<$U$>} is immediately returned,
12466
- where $U$ is determined as follows:
12467
- Let $T$ be the actual return type of $f$ (\ref{actualTypes}).
12468
- If $T$ is \code{Iterable<$S$>} for some type $S$, then $U$ is $S$,
12469
- otherwise $U$ is \code{Object} .
12474
+ where $U$ is the actual type
12475
+ (\ref{actualTypes})
12476
+ corresponding to the element type of $f$
12477
+ (\ref{functions}) .
12470
12478
12471
12479
\commentary{%
12472
12480
A Dart implementation will need to provide
@@ -12549,8 +12557,10 @@ \subsection{Function Invocation}
12549
12557
If $f$ is marked \ASYNC{} (\ref{functions}),
12550
12558
then a fresh instance (\ref{generativeConstructors}) $o$
12551
12559
is associated with the invocation,
12552
- where the dynamic type of $o$ implements \code{Future<$flatten(T)$>},
12553
- and $T$ is the actual return type of $f$ (\ref{actualTypes}).
12560
+ where the dynamic type of $o$ implements \code{Future<T>},
12561
+ where $T$ is the actual type
12562
+ (\ref{actualTypes})
12563
+ corresponding to the future value type of $f$.
12554
12564
Then the body of $f$ is executed until it either suspends or completes,
12555
12565
at which point $o$ is returned.
12556
12566
\commentary{%
@@ -12576,10 +12586,10 @@ \subsection{Function Invocation}
12576
12586
If $f$ is marked \code{\ASYNC*} (\ref{functions}),
12577
12587
then a fresh instance (\ref{generativeConstructors}) $s$
12578
12588
implementing \code{Stream<$U$>} is immediately returned,
12579
- where $U$ is determined as follows:
12580
- Let $T$ be the actual return type of $f$ (\ref{actualTypes}).
12581
- If $T$ is \code{Stream<$S$>} for some type $S$, then $U$ is $S$,
12582
- otherwise $U$ is \code{Object} .
12589
+ where $U$ is the actual type
12590
+ (\ref{actualTypes})
12591
+ corresponding to the element type of $f$
12592
+ (\ref{functions}) .
12583
12593
When $s$ is listened to, execution of the body of $f$ will begin.
12584
12594
When execution of the body of $f$ completes:
12585
12595
\begin{itemize}
0 commit comments