@@ -1402,6 +1402,13 @@ \section{Variables}
1402
1402
That is, any kind of variable which is not a local variable.%
1403
1403
}
1404
1404
1405
+ \LMHash{}%
1406
+ A \IndexCustom{non-local variable}{variable!non-local}
1407
+ is a library variable, a class variable, or an instance variable.
1408
+ \commentary{%
1409
+ That is, any kind of variable which is not a local variable.%
1410
+ }
1411
+
1405
1412
\LMHash{}%
1406
1413
A \IndexCustom{constant variable}{variable!constant}
1407
1414
is a variable whose declaration includes the modifier \CONST.
@@ -1532,13 +1539,10 @@ \subsection{Implicitly Induced Getters and Setters}
1532
1539
A variable declaration of the form
1533
1540
\code{\STATIC?\,\,\LATE?\,\,\VAR\,\,\id{} = $e$;}
1534
1541
implicitly induces a setter with the header
1535
- \code{\VOID\,\,\SET\,\,\id(\DYNAMIC \,\,$x$)},
1542
+ \code{\VOID\,\,\SET\,\,\id($T$ \,\,$x$)},
1536
1543
whose execution sets the value of \id{} to the incoming argument $x$.
1537
-
1538
- \commentary{%
1539
- Type inference could have provided a type different from \DYNAMIC{}
1540
- (\ref{overview}).%
1541
- }
1544
+ The type $T$ is obtained from type inference
1545
+ (\ref{overview}).
1542
1546
\EndCase
1543
1547
1544
1548
\LMHash{}%
@@ -1563,7 +1567,7 @@ \subsection{Implicitly Induced Getters and Setters}
1563
1567
A variable declaration of the form
1564
1568
\code{\STATIC?\,\,\LATE\,\,\FINAL\,\,$T$\,\,\id;}
1565
1569
implicitly induces a setter (\ref{setters}) with the header
1566
- \code{\VOID\,\,\SET\,\,\id($T$ \,\,$x$)}.
1570
+ \code{\VOID\,\,\SET\,\,\id(\DYNAMIC \,\,$x$)}.
1567
1571
If this setter is executed
1568
1572
in a situation where the variable \id{} has not been bound,
1569
1573
it will bind \id{} to the object that $x$ is bound to.
@@ -1887,7 +1891,39 @@ \subsection{Evaluation of Implicit Variable Getters}
1887
1891
\commentary{%
1888
1892
Note that these static or library variables can be \emph{implicitly}
1889
1893
late-initialized, in the sense that they do not have
1890
- the modifier \LATE.%
1894
+ the modifier \LATE.
1895
+
1896
+ An initializing expression can have side effects
1897
+ that are significant during initialization.
1898
+ For example:%
1899
+ }
1900
+
1901
+ \begin{dartCode}
1902
+ bool b = \TRUE;
1903
+ int i = (() => (b = !b) ? (i = 10) : i + 1 )();
1904
+ \\
1905
+ \VOID{} main() \{
1906
+ print(i); // '11'.
1907
+ \}
1908
+ \end{dartCode}
1909
+
1910
+ \commentary{%
1911
+ In this example, \code{main} invokes
1912
+ the implicitly induced getter named \code{i},
1913
+ and no value has been stored in the variable \code{i} at this point.
1914
+ Hence, evaluation of the initializing expression proceeds.
1915
+ This causes \code{b} to be toggled to \FALSE,
1916
+ which again causes \code{i + 1} to be evaluated.
1917
+ This causes the getter \code{i} to be invoked again,
1918
+ and it is still true that no value has been stored in the variable,
1919
+ so the initializing expression is evaluated again.
1920
+ This toggles \code{b} to \TRUE,
1921
+ which causes \code{i = 10} to be evaluated,
1922
+ which causes the implicitly induced setter named \code{i=} to be invoked,
1923
+ and the most recent invocation of the getter \code{i}
1924
+ returns 10.
1925
+ This makes \code{i + 1} evaluate to 11,
1926
+ which is stored in the variable.%
1891
1927
}
1892
1928
\item \emph{Constant variable.}
1893
1929
If $d$ declares a constant variable with the initializing expression $e$,
@@ -1915,6 +1951,7 @@ \subsection{Evaluation of Implicit Variable Getters}
1915
1951
the implicitly induced getter is a late-uninitialized getter.
1916
1952
This determines the semantics of an invocation.
1917
1953
\end{itemize}
1954
+ \EndCase
1918
1955
1919
1956
% Reduce whitespace after itemized list: This is just an end symbol.
1920
1957
\vspace{-\baselineskip}\EndCase
@@ -3947,6 +3984,11 @@ \subsection{Instance Variables}
3947
3984
is considered to be covariant-by-declaration
3948
3985
(\ref{covariantParameters}).
3949
3986
3987
+ \LMHash{}%
3988
+ A \Error{compile-time error} occurs if an instance variable declaration
3989
+ includes the modifier \COVARIANT,
3990
+ but it does not implicitly induce a setter.
3991
+
3950
3992
\commentary{%
3951
3993
The modifier \COVARIANT{} on an instance variable has no other effects.
3952
3994
In particular, the return type of the implicitly induced getter
@@ -8582,7 +8624,7 @@ \subsection{Constants}
8582
8624
that is not qualified by a deferred prefix,
8583
8625
is a potentially constant and constant expression.
8584
8626
\commentary{%
8585
- For example, if class $C$ declares a constant static variable $v$,
8627
+ For example, if class $C$ declares a constant class variable $v$,
8586
8628
\code{$C$.$v$} is a constant.
8587
8629
The same is true if $C$ is accessed via a prefix $p$;
8588
8630
\code{$p$.$C$.$v$} is a constant unless $p$ is a deferred prefix.%
@@ -13350,11 +13392,13 @@ \subsubsection{Unqualified Invocation}
13350
13392
\vspace{-2ex}
13351
13393
\EndCase
13352
13394
13395
+ \LMHash{}%
13353
13396
\Case{Lexical lookup yields an import prefix}
13354
13397
When the lexical lookup of \id{} yields an import prefix,
13355
13398
a \Error{compile-time error} occurs.
13356
13399
\EndCase
13357
13400
13401
+ \LMHash{}%
13358
13402
\Case{Lexical lookup yields nothing}
13359
13403
When the lexical lookup of \id{} yields nothing,
13360
13404
$i$ is treated as
@@ -17024,21 +17068,23 @@ \subsection{Postfix Expressions}
17024
17068
All but the latter three are specified elsewhere.
17025
17069
17026
17070
\LMHash{}%
17027
- \Case{Null checks }
17071
+ \Case{Non-null assertions }
17028
17072
Consider an expression $e$ of the form \code{$e_1$\!!}\ where
17029
17073
$e_1$ is derived from \syntax{<primary> <selector>*}.
17030
17074
17031
17075
\LMHash{}%
17032
17076
Let $S$ be the static type of $e_1$.
17033
17077
A warning occurs if $S$ is non-nullable.
17034
- \commentary{In this case, the null check is redundant.}
17078
+ \commentary{In this case, the non- null assertion is redundant.}
17035
17079
The static type of $e$ is \NonNullType{$S$}.
17036
17080
17037
17081
\LMHash{}%
17038
17082
$e$ is evaluated as follows: $e_1$ is evaluated to an object $o$.
17039
17083
If $o$ is the null object then a dynamic error occurs,
17040
17084
otherwise $e$ evaluates to $o$.
17085
+ \EndCase
17041
17086
17087
+ \LMHash{}%
17042
17088
\Case{Constructor Invocations}
17043
17089
Consider a \synt{constructorInvocation} $e$ of the form
17044
17090
\code{$n$<\metavar{typeArguments}>.\id(\metavar{arguments})}.
@@ -17908,7 +17954,7 @@ \subsection{Type Test}
17908
17954
such a refinement would accept more code without errors,
17909
17955
but not reject any code now error-free.
17910
17956
17911
- The rule only applies to locals and parameters,
17957
+ The rule only applies to local variables (including formal parameters) ,
17912
17958
as non-local variables could be modified
17913
17959
via side-effecting functions or methods that are not accessible
17914
17960
to a local analysis.
@@ -19545,6 +19591,7 @@ \subsection{Return}
19545
19591
The case where the evaluation of $e$ throws is covered by the general rule
19546
19592
which propagates the throwing completion from $e$ to $s$ to the function body.%
19547
19593
}
19594
+ \EndCase
19548
19595
19549
19596
\LMHash{}%
19550
19597
\Case{Asynchronous non-generator functions}
@@ -24733,18 +24780,6 @@ \subsubsection{Null promotion}
24733
24780
These are extended as per
24734
24781
[separate proposal](https://github.com/dart-lang/language/blob/master/resources/type-system/flow-analysis.md).
24735
24782
24736
- \paragraph{Constant instances}
24737
-
24738
- !!!TODO!!!
24739
-
24740
-
24741
- \subsubsection{Null check operator}
24742
-
24743
- When evaluating an expression of the form \code{$e$!},
24744
- where $e$ evaluates to a value $v$,
24745
- a dynamic type error occurs if $v$ is \code{null},
24746
- and otherwise the expression evaluates to $v$.
24747
-
24748
24783
\subsubsection{Null aware operator}
24749
24784
\LMLabel{nullShorteningTransformation}
24750
24785
@@ -24895,20 +24930,9 @@ \subsubsection{Null aware operator}
24895
24930
24896
24931
\subsubsection{Late fields and variables}
24897
24932
24898
- A non-local \LATE{} variable declaration $D$ implicitly induces a getter
24899
- into the enclosing scope. It also induces an implicit setter iff one of the
24900
- following conditions is satisfied:
24901
-
24902
- - $D$ is non-final.
24903
- - $D$ is late, final, and has no initializing expression.
24904
-
24905
- The late final variable declaration with no initializer is permitted, and
24906
- introduces a variable which may be assigned to so long as the variable is not
24907
- known to be definitely assigned. The property that the variable is never
24908
- mutated after initialization is enforced dynamically rather than statically.
24933
+ !!!TODO!!!
24909
24934
24910
- An instance variable declaration may be declared \COVARIANT{} iff it introduces
24911
- an implicit setter.
24935
+ A variable which is marked as \LATE{} ...
24912
24936
24913
24937
A read of a field or variable which is marked as \LATE{} which has not yet been
24914
24938
written to causes the initializer expression of the variable to be evaluated to
@@ -24956,7 +24980,7 @@ \subsubsection{Late fields and variables}
24956
24980
\}
24957
24981
\end{dartCode}
24958
24982
24959
- A toplevel or static variable with an initializer is evaluated as if it
24983
+ A toplevel or class variable with an initializer is evaluated as if it
24960
24984
was marked \LATE. Note that this is a change from pre-NNBD semantics in that:
24961
24985
24962
24986
\begin{itemize}
0 commit comments