You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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>
\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.
7857
7858
\end{itemize}
7858
7859
7859
7860
\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:
7861
7864
\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$.
7866
7880
\end{itemize}
7867
-
then the type of $v$ is known to be $T$ in $e_2$.
7868
7881
7869
7882
\LMHash{}
7870
7883
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}
9023
9036
It is a compile-time error if the type of the expression $b$ may not be assigned to \code{bool}.
9024
9037
9025
9038
\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
9027
9042
\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$.
9032
9048
\end{itemize}
9033
-
then the type of $v$ is known to be $T$ in $s_1$.
9034
9049
9035
9050
\LMHash{}
9036
9051
An if statement of the form \code{\IF{} ($e$) $s$} is equivalent to the if statement \code{\IF{} ($e$) $s$\ELSE{} \{\}}.
0 commit comments