Skip to content

Commit af8e291

Browse files
lrhncommit-bot@chromium.org
authored andcommitted
Respecify where type promotion happens.
This makes some parts of the specification explicit, and rephrases it so that it is easier to recognize the separate cases. Change-Id: Ifdbb5c11ec3b3fe80737642f230ee291a18a5841 Reviewed-on: https://dart-review.googlesource.com/c/80824 Commit-Queue: Lasse R.H. Nielsen <lrn@google.com> Reviewed-by: Erik Ernst <eernst@google.com>
1 parent 393fe44 commit af8e291

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

docs/language/dartLangSpec.tex

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7779,16 +7779,17 @@ \subsection{Conditional}
77797779
Otherwise the value of $c$ is the result of evaluating the expression $e_3$.
77807780
77817781
\LMHash{}
7782-
If all of the following hold:
7782+
If $e_1$ shows that a local variable $v$ has type $T$,
7783+
then the type of $v$ is known to be $T$ in $e_2$,
7784+
unless any of the following are true:
77837785
\begin{itemize}
7784-
\item $e_1$ shows that a local variable $v$ has type $T$.
7785-
\item $v$ is not potentially mutated in $e_2$ or within a function.
7786-
\item If the variable $v$ is accessed by a function in $e_2$ then
7787-
$v$ is not potentially mutated anywhere in the scope of $v$.
7786+
\item $v$ is potentially mutated in $e_2$,
7787+
\item $v$ is potentially mutated within a function other
7788+
than the one where $v$ is declared, or
7789+
\item $v$ is accessed by a function defined in $e_2$ and
7790+
$v$ is potentially mutated anywhere in the scope of $v$.
77887791
\end{itemize}
77897792
7790-
then the type of $v$ is known to be $T$ in $e_2$.
7791-
77927793
\LMHash{}
77937794
It is a compile-time error if the static type of $e_1$ may not be assigned to \code{bool}.
77947795
The static type of $c$ is the least upper bound (\ref{leastUpperBounds}) of the static type of $e_2$ and the static type of $e_3$.
@@ -7853,18 +7854,30 @@ \subsection{Logical Boolean Expressions}
78537854
if both of the following conditions hold:
78547855
\begin{itemize}
78557856
\item Either $e_1$ shows that $v$ has type $T$ or $e_2$ shows that $v$ has type $T$.
7856-
\item $v$ is not mutated in $e_2$ or within a function.
7857+
\item $v$ is not mutated in $e_2$ or within a function other than the one where $v$ is declared.
78577858
\end{itemize}
78587859
78597860
\LMHash{}
7860-
Furthermore, if all of the following hold:
7861+
If $e_1$ shows that a local variable $v$ has type $T$,
7862+
then the type of $v$ is known to be $T$ in $e_2$,
7863+
unless any of the following are true:
78617864
\begin{itemize}
7862-
\item $e_1$ shows that $v$ has type $T$.
7863-
\item $v$ is not mutated in either $e_1$, $e_2$ or within a function.
7864-
\item If $v$ is accessed by a function in $e_2$ then
7865-
$v$ is not potentially mutated anywhere in the scope of $v$.
7865+
%% The first item here is unnecessary for soundness,
7866+
%% and is retained mainly for backwards compatibility.
7867+
%% If $e_1$ shows that $v$ has type $T$, then any assignment
7868+
%% in $e_1$ does not invalidate that.
7869+
%% Removing the line is visible in the semantics, though, because:
7870+
%% num x;
7871+
%% (x ??= 42) != null && x is int & x.toRadixString(16) != ""
7872+
%% is allowed without the line, and disallowed with.
7873+
%% At time of writing, the analyzer disallows the code.
7874+
\item $v$ is potentially mutated in $e_1$,
7875+
\item $v$ is potentially mutated in $e_2$,
7876+
\item $v$ is potentially mutated within a function other
7877+
than the one where $v$ is declared, or
7878+
\item $v$ is accessed by a function defined in $e_2$ and
7879+
$v$ is potentially mutated anywhere in the scope of $v$.
78667880
\end{itemize}
7867-
then the type of $v$ is known to be $T$ in $e_2$.
78687881
78697882
\LMHash{}
78707883
It is a compile-time error if the static type of $e_1$ may not be assigned to \code{bool} or if the static type of $e_2$ may not be assigned to \code{bool}.
@@ -9023,14 +9036,16 @@ \subsection{If}
90239036
It is a compile-time error if the type of the expression $b$ may not be assigned to \code{bool}.
90249037
90259038
\LMHash{}
9026-
If:
9039+
If $b$ shows that a local variable $v$ has type $T$,
9040+
then the type of $v$ is known to be $T$ in $s_2$,
9041+
unless any of the following are true
90279042
\begin{itemize}
9028-
\item $b$ shows that a local variable $v$ has type $T$.
9029-
\item $v$ is not potentially mutated in $s_1$ or within a function.
9030-
\item If $v$ is accessed by a function in $s_1$ then
9031-
$v$ is not potentially mutated anywhere in the scope of $v$.
9043+
\item $v$ is potentially mutated in $s_1$,
9044+
\item $v$ is potentially mutated within a function other
9045+
than the one where $v$ is declared, or
9046+
\item $v$ is accessed by a function defined in $s_1$ and
9047+
$v$ is potentially mutated anywhere in the scope of $v$.
90329048
\end{itemize}
9033-
then the type of $v$ is known to be $T$ in $s_1$.
90349049
90359050
\LMHash{}
90369051
An if statement of the form \code{\IF{} ($e$) $s$} is equivalent to the if statement \code{\IF{} ($e$) $s$ \ELSE{} \{\}}.

0 commit comments

Comments
 (0)