Skip to content

Commit cf28fdd

Browse files
committed
Adjust generator element type, cf. #3148
1 parent 35c9062 commit cf28fdd

File tree

1 file changed

+37
-27
lines changed

1 file changed

+37
-27
lines changed

specification/dartLangSpec.tex

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,30 +1759,38 @@ \section{Functions}
17591759
a function marked \code{\SYNC*} or \code{\ASYNC*} is \VOID.
17601760

17611761
\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$.
17651779
%
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$
17681782
(\ref{interfaceSuperinterfaces})
17691783
then the element type of $f$ is $U$.
17701784
%
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$
17731787
then the element type of $f$ is $U$.
17741788
%
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})
17771792
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.}
17861794

17871795

17881796
\subsection{Function Declarations}
@@ -12136,10 +12144,10 @@ \subsection{Function Invocation}
1213612144
If $f$ is marked \code{\SYNC*} (\ref{functions}),
1213712145
then a fresh instance (\ref{generativeConstructors}) $i$
1213812146
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}).
1214312151

1214412152
\commentary{%
1214512153
A Dart implementation will need to provide
@@ -12222,8 +12230,10 @@ \subsection{Function Invocation}
1222212230
If $f$ is marked \ASYNC{} (\ref{functions}),
1222312231
then a fresh instance (\ref{generativeConstructors}) $o$
1222412232
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$.
1222712237
Then the body of $f$ is executed until it either suspends or completes,
1222812238
at which point $o$ is returned.
1222912239
\commentary{%
@@ -12249,10 +12259,10 @@ \subsection{Function Invocation}
1224912259
If $f$ is marked \code{\ASYNC*} (\ref{functions}),
1225012260
then a fresh instance (\ref{generativeConstructors}) $s$
1225112261
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}).
1225612266
When $s$ is listened to, execution of the body of $f$ will begin.
1225712267
When execution of the body of $f$ completes:
1225812268
\begin{itemize}

0 commit comments

Comments
 (0)