Skip to content

Commit ee8256c

Browse files
committed
Adjust generator element type, cf. #3148
1 parent bb001dc commit ee8256c

File tree

1 file changed

+37
-27
lines changed

1 file changed

+37
-27
lines changed

specification/dartLangSpec.tex

+37-27
Original file line numberDiff line numberDiff line change
@@ -2073,30 +2073,38 @@ \section{Functions}
20732073
a function marked \code{\SYNC*} or \code{\ASYNC*} is \VOID.
20742074

20752075
\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$.
20792093
%
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$
20822096
(\ref{interfaceSuperinterfaces})
20832097
then the element type of $f$ is $U$.
20842098
%
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$
20872101
then the element type of $f$ is $U$.
20882102
%
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})
20912106
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.}
21002108

21012109

21022110
\subsection{Function Declarations}
@@ -12463,10 +12471,10 @@ \subsection{Function Invocation}
1246312471
If $f$ is marked \code{\SYNC*} (\ref{functions}),
1246412472
then a fresh instance (\ref{generativeConstructors}) $i$
1246512473
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}).
1247012478

1247112479
\commentary{%
1247212480
A Dart implementation will need to provide
@@ -12549,8 +12557,10 @@ \subsection{Function Invocation}
1254912557
If $f$ is marked \ASYNC{} (\ref{functions}),
1255012558
then a fresh instance (\ref{generativeConstructors}) $o$
1255112559
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$.
1255412564
Then the body of $f$ is executed until it either suspends or completes,
1255512565
at which point $o$ is returned.
1255612566
\commentary{%
@@ -12576,10 +12586,10 @@ \subsection{Function Invocation}
1257612586
If $f$ is marked \code{\ASYNC*} (\ref{functions}),
1257712587
then a fresh instance (\ref{generativeConstructors}) $s$
1257812588
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}).
1258312593
When $s$ is listened to, execution of the body of $f$ will begin.
1258412594
When execution of the body of $f$ completes:
1258512595
\begin{itemize}

0 commit comments

Comments
 (0)