54
54
% been eliminated (it is spelled out each time which modifiers must be
55
55
% present or not present). The concept is confusing now where a variable can
56
56
% be late and final, and assignments to it are allowed by the static analysis.
57
+ % - Change the definition of the 'element type of a generator function', due to
58
+ % soundness issue with the current definition.
57
59
%
58
60
% Mar 2023
59
61
% - Clarify how line breaks are handled in a multi-line string literal. Rename
@@ -2076,30 +2078,40 @@ \section{Functions}
2076
2078
a function marked \code{\SYNC*} or \code{\ASYNC*} is \VOID.
2077
2079
2078
2080
\LMHash{}%
2079
- We define the notion of the
2080
- \IndexCustom{element type of a generator}{function!generator!element type}
2081
- as follows:
2081
+ We define the
2082
+ \Index{union-free type derived from}
2083
+ a type $T$ as follows:
2084
+ If $T$ is of the form \code{$S$?}\ or the form \code{FutureOr<$S$>}
2085
+ then the union-free type derived from $T$ is
2086
+ the union-free type derived from $S$.
2087
+ Otherwise, the union-free type derived from $T$ is $T$.
2088
+ \commentary{%
2089
+ For example, the union-free type derived from
2090
+ \code{FutureOr<int?>?} is \code{int}.%
2091
+ }
2092
+
2093
+ \LMHash{}%
2094
+ We define the
2095
+ \IndexCustom{element type of a generator function}{%
2096
+ function!generator!element type}
2097
+ $f$ as follows:
2098
+ %
2099
+ Let $S$ be the union-free type derived from the declared return type of $f$.
2082
2100
%
2083
- If the function $f$ is a synchronous generator
2084
- whose declared return type implements \code{Iterable<$U$>} for some $U$
2101
+ If $f$ is a synchronous generator and
2102
+ $S$ implements \code{Iterable<$U$>} for some $U$
2085
2103
(\ref{interfaceSuperinterfaces})
2086
2104
then the element type of $f$ is $U$.
2087
2105
%
2088
- If the function $f$ is an asynchronous generator
2089
- whose declared return type implements \code{Stream<$U$>} for some $U$
2106
+ If $f$ is an asynchronous generator and
2107
+ $S$ implements \code{Stream<$U$>} for some $U$
2090
2108
then the element type of $f$ is $U$.
2091
2109
%
2092
- Otherwise, if the function $f$ is a generator
2093
- (\commentary{synchronous or asynchronous})
2110
+ Otherwise, if $f$ is a generator (synchronous or asynchronous)
2111
+ and $S$ is a supertype of \code{Object}
2112
+ (\commentary{which includes \code{Object} itself})
2094
2113
then the element type of $f$ is \DYNAMIC.
2095
-
2096
- \commentary{%
2097
- %% TODO(eernst): Come nnbd, change `a top type' to \DYNAMIC.
2098
- In the latter case the return type is a top type,
2099
- because the declaration of $f$ would otherwise be a compile-time error.
2100
- This implies that there is no information about
2101
- the type of elements that the generator will yield.%
2102
- }
2114
+ \commentary{No further cases are possible.}
2103
2115
2104
2116
2105
2117
\subsection{Function Declarations}
@@ -11642,7 +11654,7 @@ \subsection{Function Expressions}
11642
11654
11643
11655
\LMHash{}%
11644
11656
We say that $S$ is the
11645
- \IndexCustom{future type of a type}{type!future type of }
11657
+ \IndexCustom{future type derived from a type}{type!future type derived from }
11646
11658
$T$ in the following cases, using the first applicable case:
11647
11659
11648
11660
\begin{itemize}
@@ -11657,10 +11669,10 @@ \subsection{Function Expressions}
11657
11669
11658
11670
\LMHash{}%
11659
11671
When none of these cases are applicable,
11660
- we say that $T$ does not have a future type.
11672
+ we say that $T$ does not derive a future type.
11661
11673
11662
11674
\commentary{%
11663
- Note that if $T$ has a future type $F$ then \SubtypeNE{T}{F},
11675
+ Note that if $T$ derives a future type $F$ then \SubtypeNE{T}{F},
11664
11676
and $F$ is always of the form \code{$G$<...>} or \code{$G$<...>?},
11665
11677
where $G$ is \code{Future} or \code{FutureOr}.%
11666
11678
}
@@ -11677,17 +11689,17 @@ \subsection{Function Expressions}
11677
11689
\item If $T$ is \code{$X$\,\&\,$S$}
11678
11690
for some type variable $X$ and type $S$ then
11679
11691
\begin{itemize}
11680
- \item if $S$ has future type $U$
11692
+ \item if $S$ derives a future type $U$
11681
11693
then \DefEquals{\flatten{T}}{\code{\flatten{U}}}.
11682
11694
\item otherwise,
11683
11695
\DefEquals{\flatten{T}}{\code{\flatten{X}}}.
11684
11696
\end{itemize}
11685
11697
11686
- \item If $T$ has future type \code{Future<$S$>}
11698
+ \item If $T$ derives a future type \code{Future<$S$>}
11687
11699
or \code{FutureOr<$S$>}
11688
11700
then \DefEquals{\flatten{T}}{S}.
11689
11701
11690
- \item If $T$ has future type \code{Future<$S$>?}\ or
11702
+ \item If $T$ derives a future type \code{Future<$S$>?}\ or
11691
11703
\code{FutureOr<$S$>?}\ then \DefEquals{\flatten{T}}{\code{$S$?}}.
11692
11704
11693
11705
\item Otherwise, \DefEquals{\flatten{T}}{T}.
@@ -12464,10 +12476,10 @@ \subsection{Function Invocation}
12464
12476
If $f$ is marked \code{\SYNC*} (\ref{functions}),
12465
12477
then a fresh instance (\ref{generativeConstructors}) $i$
12466
12478
implementing \code{Iterable<$U$>} is immediately returned,
12467
- where $U$ is determined as follows:
12468
- Let $T$ be the actual return type of $f$ (\ref{actualTypes}).
12469
- If $T$ is \code{Iterable<$S$>} for some type $S$, then $U$ is $S$,
12470
- otherwise $U$ is \code{Object} .
12479
+ where $U$ is the actual type
12480
+ (\ref{actualTypes})
12481
+ corresponding to the element type of $f$
12482
+ (\ref{functions}) .
12471
12483
12472
12484
\commentary{%
12473
12485
A Dart implementation will need to provide
@@ -12550,8 +12562,10 @@ \subsection{Function Invocation}
12550
12562
If $f$ is marked \ASYNC{} (\ref{functions}),
12551
12563
then a fresh instance (\ref{generativeConstructors}) $o$
12552
12564
is associated with the invocation,
12553
- where the dynamic type of $o$ implements \code{Future<$flatten(T)$>},
12554
- and $T$ is the actual return type of $f$ (\ref{actualTypes}).
12565
+ where the dynamic type of $o$ implements \code{Future<T>},
12566
+ where $T$ is the actual type
12567
+ (\ref{actualTypes})
12568
+ corresponding to the future value type of $f$.
12555
12569
Then the body of $f$ is executed until it either suspends or completes,
12556
12570
at which point $o$ is returned.
12557
12571
\commentary{%
@@ -12577,10 +12591,10 @@ \subsection{Function Invocation}
12577
12591
If $f$ is marked \code{\ASYNC*} (\ref{functions}),
12578
12592
then a fresh instance (\ref{generativeConstructors}) $s$
12579
12593
implementing \code{Stream<$U$>} is immediately returned,
12580
- where $U$ is determined as follows:
12581
- Let $T$ be the actual return type of $f$ (\ref{actualTypes}).
12582
- If $T$ is \code{Stream<$S$>} for some type $S$, then $U$ is $S$,
12583
- otherwise $U$ is \code{Object} .
12594
+ where $U$ is the actual type
12595
+ (\ref{actualTypes})
12596
+ corresponding to the element type of $f$
12597
+ (\ref{functions}) .
12584
12598
When $s$ is listened to, execution of the body of $f$ will begin.
12585
12599
When execution of the body of $f$ completes:
12586
12600
\begin{itemize}
0 commit comments