Skip to content

Commit 0bd2e86

Browse files
committed
Small adjustments to Variables
1 parent 19abe46 commit 0bd2e86

File tree

1 file changed

+20
-52
lines changed

1 file changed

+20
-52
lines changed

specification/dartLangSpec.tex

Lines changed: 20 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,10 +1381,8 @@ \section{Variables}
13811381
A \IndexCustom{mutable variable}{variable!mutable}
13821382
is a variable which is not final.
13831383

1384-
%% Note that the following relies on the assumption that inference has
1385-
%% already taken place, including member signature inference. For instance,
1386-
%% if `var x;` is an instance variable declaration that overrides `T get x;`
1387-
%% then we treat `var x;` as if it had been `T x;`.
1384+
\subsection{Implicitly Induced Getters and Setters}
1385+
\LMLabel{implicitlyInducedGettersAndSetters}
13881386

13891387
\LMHash{}%
13901388
The following rules on implicitly induced getters and setters
@@ -1685,7 +1683,7 @@ \subsection{Evaluation of Implicit Variable Getters}
16851683
will evaluate to the object stored in \id.
16861684
Otherwise
16871685
(\commentary{when no value has been stored in this variable}),
1688-
the getter invocation will throw.
1686+
the getter invocation incurs a dynamic error.
16891687
\EndCase
16901688

16911689
\LMHash{}%
@@ -1742,7 +1740,17 @@ \subsection{Evaluation of Implicit Variable Getters}
17421740
and the most recent invocation of the getter \code{i}
17431741
returns 10.
17441742
This makes \code{i + 1} evaluate to 11,
1745-
which is stored in the variable.%
1743+
which is stored in the variable.
1744+
Finally, the invocation of the getter \code{i} in \code{main}
1745+
completes returning 11.%
1746+
}
1747+
1748+
\commentary{%
1749+
Note that this is a change from the semantics older versions of Dart:
1750+
Throwing an exception during initializer evaluation no longer sets the
1751+
variable to \code{null},
1752+
and reading the variable during initializer evaluation
1753+
no longer causes a dynamic error.%
17461754
}
17471755
\item \emph{Constant variable.}
17481756
If $d$ is of one of the forms
@@ -1784,7 +1792,9 @@ \subsection{Evaluation of Implicit Variable Getters}
17841792
in a situation where no object has been stored in the variable \id{}
17851793
will incur a dynamic error.
17861794
\end{itemize}
1787-
\EndCase
1795+
1796+
% Reduce whitespace after itemized list: This is just an end symbol.
1797+
\vspace{-\baselineskip}\EndCase
17881798

17891799

17901800
\section{Functions}
@@ -24454,41 +24464,9 @@ \subsubsection{Late fields and variables}
2445424464

2445524465
!!!TODO!!!
2445624466

24457-
A variable which is marked as \LATE{} ...
24458-
24459-
A read of a field or variable which is marked as \LATE{} which has not yet been
24460-
written to causes the initializer expression of the variable to be evaluated to
24461-
a value, assigned to the variable or field, and returned as the value of the
24462-
read.
24463-
24464-
\begin{itemize}
24465-
\item If there is no initializer expression, the read causes a runtime error to be
24466-
thrown.
24467-
\item Evaluating the initializer expression may validly cause a write to the field
24468-
or variable, assuming that the field or variable is not final. In this
24469-
case, the variable assumes the written value. The final value of the
24470-
initializer expression overwrites any intermediate written values.
24471-
\item Evaluating the initializer expression may cause an exception to be thrown.
24472-
If the variable was written to before the exception was thrown, the value of
24473-
the variable on subsequent reads is the last written value. If the variable
24474-
was not written before the exception was thrown, then the next read attempts
24475-
to evaluate the initializer expression again.
24476-
\item If a variable or field is read from during the process of evaluating its own
24477-
initializer expression, and no write to the variable has occurred, the read
24478-
is treated as a first read and the initializer expression is evaluated
24479-
again.
24480-
\end{itemize}
24481-
24482-
Let $D$ be a \LATE{} and \FINAL{} non-local variable declaration named \code{v}
24483-
without an initializing expression.
24484-
It is a run-time error, to invoke the setter \code{v=} which is
24485-
implicitly induced by $D$ if a value has previously been assigned to \code{v}
24486-
(which could be due to an initializing formal or a constructor initializer
24487-
list, or due to an invocation of the setter).
24488-
24489-
Let $D$ be a \LATE{} and \FINAL{} local variable declaration named \code{v}. It is a
24490-
run-time error, to assign a value to \code{v} if a value has previously
24491-
been assigned to \code{v}.
24467+
Let $D$ be a \LATE{} and \FINAL{} local variable declaration named \code{v}.
24468+
It is a run-time error, to assign a value to \code{v}
24469+
if a value has previously been assigned to \code{v}.
2449224470

2449324471
Note that this includes the implicit initializing writes induced by
2449424472
evaluating the initializer during a read. Hence, the following program
@@ -24502,16 +24480,6 @@ \subsubsection{Late fields and variables}
2450224480
\}
2450324481
\end{dartCode}
2450424482

24505-
A toplevel or class variable with an initializer is evaluated as if it
24506-
was marked \LATE. Note that this is a change from pre-NNBD semantics in that:
24507-
24508-
\begin{itemize}
24509-
\item Throwing an exception during initializer evaluation no longer sets the
24510-
variable to \code{null}
24511-
\item Reading the variable during initializer evaluation is no longer checked for,
24512-
and does not cause an error.
24513-
\end{itemize}
24514-
2451524483
\subsubsection{Boolean conditional evaluation}
2451624484

2451724485
The requirement that the condition in a boolean conditional control expression

0 commit comments

Comments
 (0)