Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify the evaluation order for collection literal elements #2175

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 11 additions & 8 deletions specification/dartLangSpec.tex
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
% that `o` is desugared as `o.call` when the context type is a function type.
% - Clarify the treatment of `covariant` parameters in the interface of a class
% that inherits an implementation where those parameters are not covariant.
% - Clarify the order of evaluation of object sequences (which are used with
% collection literals).
%
% 2.14
% - Add constraint on type of parameter which is covariant-by-declaration in
Expand Down Expand Up @@ -9683,7 +9685,8 @@ \subsubsection{Collection Literal Element Evaluation}
The sequence of objects $s_{\metavar{object}}$
obtained by evaluating $s_{\metavar{syntax}}$
is the concatenation of the sequences of objects
obtained by evaluating each element $\ell_j$, $j \in 1 .. k$:
obtained by evaluating each element $\ell_j$, $j \in 1 .. k$,
in that order:
$s_{\metavar{object}}=\EvaluateElement{\ell_1}+\ldots+\EvaluateElement{\ell_k}$,
where \EvaluateElement{\ell_j} denotes the object sequence yielded by
evaluation of a single collection literal element $\ell_j$.
Expand Down Expand Up @@ -9773,7 +9776,7 @@ \subsubsection{Collection Literal Element Evaluation}
\vspace{-2ex}\begin{minipage}[t]{\textwidth}
\begin{normativeDartCode}
$S_{\metavar{spread}}$ spread = $o_{\metavar{spread}}$;
\VAR{} $s$ = \LiteralSequence;
\VAR{} $s$ = \LiteralSequence{};
\FOR{} (\VAR{} v \IN{} spread) \{
Value value = v;
$s := s + \LiteralSequence{\code{value}}$;
Expand Down Expand Up @@ -9805,7 +9808,7 @@ \subsubsection{Collection Literal Element Evaluation}
\vspace{-2ex}\begin{minipage}[t]{\textwidth}
\begin{normativeDartCode}
$S_{\metavar{spread}}$ spread = $o_{\metavar{spread}}$;
\VAR{} $s$ = \LiteralSequence;
\VAR{} $s$ = \LiteralSequence{};
\FOR{} (\VAR{} v \IN{} spread) \{
Key key = v.key;
Value value = v.value;
Expand Down Expand Up @@ -9891,7 +9894,7 @@ \subsubsection{Collection Literal Element Evaluation}

\vspace{-2ex}\begin{minipage}[t]{\textwidth}
\begin{normativeDartCode}
\VAR{} $s$ = \LiteralSequence;
\VAR{} $s$ = \LiteralSequence{};
\AWAIT? \FOR{} ($P$) \{
$s := s + \EvaluateElement{\ell_1}$;
\}
Expand Down Expand Up @@ -10016,12 +10019,12 @@ \subsubsection{List Literal Inference}
the errors that would occur with the corresponding \FOR{} statement
\code{\AWAIT?\,\,\FOR\,\,($P$)\,\,\{\}},
located in the same scope as $\ell$.
Moreover, the errors and type analysis of $\ell$ is performed
Moreover, the errors and type analysis of $\ell_1$ is performed
as if it occurred in the body scope of said \FOR{} statement.
\commentary{%
For instance, if $P$ is of the form
\code{\VAR\,\,v\,\,\IN\,\,$e_1$}
then the variable \code{v} is in scope for $\ell$.%
then the variable \code{v} is in scope for $\ell_1$.%
}

Inference for the parts
Expand Down Expand Up @@ -10651,13 +10654,13 @@ \subsubsection{Set and Map Literal Inference}
the errors that would occur with the corresponding \FOR{} statement
\code{\AWAIT?\,\,\FOR\,\,($P$)\,\,\{\}},
located in the same scope as $\ell$.
Moreover, the errors and type analysis of $\ell$ is performed
Moreover, the errors and type analysis of $\ell_1$ is performed
as if it occurred in the body scope of said \FOR{} statement.

\commentary{%
For instance, if $P$ is of the form
\code{\VAR\,\,v\,\,\IN\,\,$e_1$}
then the variable \code{v} is in scope for $\ell$.%
then the variable \code{v} is in scope for $\ell_1$.%
}

Inference for the parts
Expand Down