@@ -1759,30 +1759,38 @@ \section{Functions}
1759
1759
a function marked \code{\SYNC*} or \code{\ASYNC*} is \VOID.
1760
1760
1761
1761
\LMHash{}%
1762
- We define the notion of the
1763
- \IndexCustom{element type of a generator}{function!generator!element type}
1764
- as follows:
1762
+ We define the
1763
+ \Index{union-free type}
1764
+ of a type $T$ as follows:
1765
+ If $T$ is of the form \code{$S$?}\ or the form \code{FutureOr<$S$>}
1766
+ then the union-free type of $T$ is the union-free type of $S$.
1767
+ Otherwise, the union-free type of $T$ is $T$.
1768
+ \commentary{%
1769
+ For example, the union-free type of \code{FutureOr<int?>?} is \code{int}.%
1770
+ }
1771
+
1772
+ \LMHash{}%
1773
+ We define the
1774
+ \IndexCustom{element type of a generator function}{%
1775
+ function!generator!element type}
1776
+ $f$ as follows:
1777
+ %
1778
+ Let $S$ be the union-free type of the declared return type of $f$.
1765
1779
%
1766
- If the function $f$ is a synchronous generator
1767
- whose declared return type implements \code{Iterable<$U$>} for some $U$
1780
+ If $f$ is a synchronous generator and
1781
+ $S$ implements \code{Iterable<$U$>} for some $U$
1768
1782
(\ref{interfaceSuperinterfaces})
1769
1783
then the element type of $f$ is $U$.
1770
1784
%
1771
- If the function $f$ is an asynchronous generator
1772
- whose declared return type implements \code{Stream<$U$>} for some $U$
1785
+ If $f$ is an asynchronous generator and
1786
+ $S$ implements \code{Stream<$U$>} for some $U$
1773
1787
then the element type of $f$ is $U$.
1774
1788
%
1775
- Otherwise, if the function $f$ is a generator
1776
- (\commentary{synchronous or asynchronous})
1789
+ Otherwise, if $f$ is a generator (synchronous or asynchronous)
1790
+ and $S$ is a supertype of \code{Object}
1791
+ (\commentary{which includes \code{Object} itself})
1777
1792
then the element type of $f$ is \DYNAMIC.
1778
-
1779
- \commentary{%
1780
- %% TODO(eernst): Come nnbd, change `a top type' to \DYNAMIC.
1781
- In the latter case the return type is a top type,
1782
- because the declaration of $f$ would otherwise be a compile-time error.
1783
- This implies that there is no information about
1784
- the type of elements that the generator will yield.%
1785
- }
1793
+ \commentary{No further cases are possible.}
1786
1794
1787
1795
1788
1796
\subsection{Function Declarations}
@@ -12136,10 +12144,10 @@ \subsection{Function Invocation}
12136
12144
If $f$ is marked \code{\SYNC*} (\ref{functions}),
12137
12145
then a fresh instance (\ref{generativeConstructors}) $i$
12138
12146
implementing \code{Iterable<$U$>} is immediately returned,
12139
- where $U$ is determined as follows:
12140
- Let $T$ be the actual return type of $f$ (\ref{actualTypes}).
12141
- If $T$ is \code{Iterable<$S$>} for some type $S$, then $U$ is $S$,
12142
- otherwise $U$ is \code{Object} .
12147
+ where $U$ is the actual type
12148
+ (\ref{actualTypes})
12149
+ corresponding to the element type of $f$
12150
+ (\ref{functions}) .
12143
12151
12144
12152
\commentary{%
12145
12153
A Dart implementation will need to provide
@@ -12222,8 +12230,10 @@ \subsection{Function Invocation}
12222
12230
If $f$ is marked \ASYNC{} (\ref{functions}),
12223
12231
then a fresh instance (\ref{generativeConstructors}) $o$
12224
12232
is associated with the invocation,
12225
- where the dynamic type of $o$ implements \code{Future<$flatten(T)$>},
12226
- and $T$ is the actual return type of $f$ (\ref{actualTypes}).
12233
+ where the dynamic type of $o$ implements \code{Future<T>},
12234
+ where $T$ is the actual type
12235
+ (\ref{actualTypes})
12236
+ corresponding to the future value type of $f$.
12227
12237
Then the body of $f$ is executed until it either suspends or completes,
12228
12238
at which point $o$ is returned.
12229
12239
\commentary{%
@@ -12249,10 +12259,10 @@ \subsection{Function Invocation}
12249
12259
If $f$ is marked \code{\ASYNC*} (\ref{functions}),
12250
12260
then a fresh instance (\ref{generativeConstructors}) $s$
12251
12261
implementing \code{Stream<$U$>} is immediately returned,
12252
- where $U$ is determined as follows:
12253
- Let $T$ be the actual return type of $f$ (\ref{actualTypes}).
12254
- If $T$ is \code{Stream<$S$>} for some type $S$, then $U$ is $S$,
12255
- otherwise $U$ is \code{Object} .
12262
+ where $U$ is the actual type
12263
+ (\ref{actualTypes})
12264
+ corresponding to the element type of $f$
12265
+ (\ref{functions}) .
12256
12266
When $s$ is listened to, execution of the body of $f$ will begin.
12257
12267
When execution of the body of $f$ completes:
12258
12268
\begin{itemize}
0 commit comments