Skip to content

Commit e709c07

Browse files
committed
Further improvements (introduce cases for different kinds of variables)
1 parent 7ca582c commit e709c07

File tree

1 file changed

+68
-46
lines changed

1 file changed

+68
-46
lines changed

specification/dartLangSpec.tex

Lines changed: 68 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,19 +1383,25 @@ \section{Variables}
13831383
}
13841384

13851385
\LMHash{}%
1386-
A \IndexCustom{final variable}{variable!final}
1386+
An \IndexCustom{immutable variable}{variable!immutable}
13871387
is a variable whose binding is fixed upon initialization;
1388-
a final variable \id{} will always refer to the same object
1388+
an immutable variable \id{} will always refer to the same object
13891389
after \id{} has been initialized.
1390-
A variable is final if{}f its declaration includes
1390+
A variable is immutable if{}f its declaration includes
13911391
the modifier \FINAL{} or the modifier \CONST.
13921392
A \IndexCustom{mutable variable}{variable!mutable}
1393-
is a variable which is not final.
1393+
is a variable which is not immutable.
13941394

13951395

13961396
\subsection{Implicitly Induced Getters and Setters}
13971397
\LMLabel{implicitlyInducedGettersAndSetters}
13981398

1399+
%% TODO(eernst): When inference is specified, we should be able to conclude
1400+
%% that the cases with no declared type do not exist after type inference
1401+
%% (for instance `var x;` or `var x = e;`), and then we can replace all rules
1402+
%% about such cases by commentary saying that they may exist in the input,
1403+
%% but they are gone after type inference.
1404+
13991405
\LMHash{}%
14001406
The following rules on implicitly induced getters and setters
14011407
apply to all non-local variable declarations.
@@ -1406,6 +1412,7 @@ \subsection{Implicitly Induced Getters and Setters}
14061412
}
14071413

14081414
\LMHash{}%
1415+
\Case{Getter: Variable with declared type}
14091416
Consider a variable declaration of one of the forms
14101417

14111418
\begin{itemize}
@@ -1423,8 +1430,10 @@ \subsection{Implicitly Induced Getters and Setters}
14231430
whose invocation evaluates as described below
14241431
(\ref{evaluationOfImplicitVariableGetters}).
14251432
In these cases the declared type of \id{} is $T$.
1433+
\EndCase
14261434

14271435
\LMHash{}%
1436+
\Case{Getter: Variable with no declared type}
14281437
A variable declaration of one of the forms
14291438

14301439
\begin{itemize}
@@ -1449,12 +1458,15 @@ \subsection{Implicitly Induced Getters and Setters}
14491458
For example, an instance variable declaration of the form
14501459
\code{\VAR\,\,x;} could have been transformed into
14511460
\code{$T$\,\,x;} based on member signatures named \code{x} in superinterfaces
1452-
of the enclosing class.
1453-
Hence, the type \DYNAMIC{} is only used as mentioned above when
1454-
type inference fails to provide a different type.%
1461+
of the enclosing class, and
1462+
\code{\VAR\,x\,\,=\,\,$e$;} could have been transformed into
1463+
\code{$T$\,x\,\,=\,\,$e$;}
1464+
where $T$ is the static type of $e$.%
14551465
}
1466+
\EndCase
14561467

14571468
\LMHash{}%
1469+
\Case{Setter: Mutable variable with declared type}
14581470
A mutable variable declaration of one of the forms
14591471

14601472
\begin{itemize}
@@ -1468,6 +1480,31 @@ \subsection{Implicitly Induced Getters and Setters}
14681480
whose execution sets the value of \id{} to the incoming argument $x$.
14691481

14701482
\LMHash{}%
1483+
\Case{Setter: Mutable variable with no declared type, with initialization}
1484+
A mutable variable declaration of the form
1485+
\code{\STATIC?\,\,\LATE?\,\,\VAR\,\,\id{} = $e$;}
1486+
implicitly induces a setter with the header
1487+
\code{\VOID\,\,\SET\,\,\id(\DYNAMIC\,\,$x$)},
1488+
whose execution sets the value of \id{} to the incoming argument $x$.
1489+
\EndCase
1490+
1491+
\LMHash{}%
1492+
\Case{Setter: Mutable variable with no declared type, no initialization}
1493+
A mutable variable declaration of the form
1494+
\code{\STATIC?\,\,\LATE?\,\,\VAR\,\,\id;}
1495+
implicitly induces a setter with the header
1496+
\code{\VOID\,\,\SET\,\,\id(\DYNAMIC\,\,$x$)},
1497+
whose execution sets the value of \id{} to the incoming argument $x$.
1498+
1499+
\commentary{%
1500+
It is again assumed that type inference has taken place already,
1501+
which could change \code{\VAR\,\,x;} to \code{$T$\,\,x;}
1502+
and hence take us to an earlier case.%
1503+
}
1504+
\EndCase
1505+
1506+
\LMHash{}%
1507+
\Case{Setter: Late-final variable with declared type}
14711508
A variable declaration of the form
14721509
\code{\STATIC?\,\,\LATE\,\,\FINAL\,\,$T$\,\,\id;}
14731510
implicitly induces a setter (\ref{setters}) with the header
@@ -1486,28 +1523,10 @@ \subsection{Implicitly Induced Getters and Setters}
14861523
The property that the variable is never mutated after initialization
14871524
is enforced dynamically rather than statically.%
14881525
}
1526+
\EndCase
14891527

14901528
\LMHash{}%
1491-
A mutable variable declaration of the form
1492-
\code{\STATIC?\,\,\LATE?\,\,\VAR\,\,\id;}
1493-
implicitly induces a setter with the header
1494-
\code{\VOID\,\,\SET\,\,\id(\DYNAMIC\,\,$x$)},
1495-
whose execution sets the value of \id{} to the incoming argument $x$.
1496-
1497-
\commentary{%
1498-
It is again assumed that type inference has taken place already,
1499-
which could change \code{\VAR\,\,x;} to \code{$T$\,\,x;}
1500-
and hence take us to an earlier case.%
1501-
}
1502-
1503-
\LMHash{}%
1504-
A mutable variable declaration of the form
1505-
\code{\STATIC?\,\,\LATE?\,\,\VAR\,\,\id{} = $e$;}
1506-
implicitly induces a setter with the header
1507-
\code{\VOID\,\,\SET\,\,\id(\DYNAMIC\,\,$x$)},
1508-
whose execution sets the value of \id{} to the incoming argument $x$.
1509-
1510-
\LMHash{}%
1529+
\Case{Setter: Late-final variable with no declared type, no initialization}
15111530
A variable declaration of the form
15121531
\code{\STATIC?\,\,\LATE\,\,\FINAL\,\,\id;}
15131532
implicitly induces a setter with the header
@@ -1518,6 +1537,7 @@ \subsection{Implicitly Induced Getters and Setters}
15181537
An execution of the setter
15191538
in a situation where the variable \id{} has been bound to an object
15201539
will incur a dynamic error.
1540+
\EndCase
15211541

15221542
\LMHash{}%
15231543
The scope into which the implicit getters and setters are introduced
@@ -1532,14 +1552,13 @@ \subsection{Implicitly Induced Getters and Setters}
15321552
the body scope of the immediately enclosing class.
15331553

15341554
\LMHash{}%
1535-
A mutable library variable introduces a setter into
1536-
the library scope of the enclosing library.
1537-
A mutable class variable introduces a static setter into
1538-
the body scope of the immediately enclosing class.
1539-
An instance variable that introduces a setter
1540-
(\commentary{it can be non-final, or late and final})
1541-
introduces an instance setter into
1542-
the body scope of the immediately enclosing class.
1555+
A non-local variable introduces a setter if{}f it is mutable or late and final.
1556+
A library variable which introduces a setter will introduce
1557+
a library setter into the enclosing library scope.
1558+
A class variable which introduces a setter will introduce
1559+
a static setter into the body scope of the immediately enclosing class.
1560+
An instance variable that introduces a setter will introduce
1561+
an instance setter into the body scope of the immediately enclosing class.
15431562

15441563
\LMHash{}%
15451564
Let \id{} be a variable declared by a variable declaration
@@ -1558,11 +1577,12 @@ \subsection{Implicitly Induced Getters and Setters}
15581577
is also initialized in the initializer list of $k$
15591578
(\ref{initializerLists}).
15601579

1561-
A non-late static final variable \id{} does not induce a setter,
1580+
A non-late static immutable variable \id{} does not induce a setter,
15621581
so unless a setter named \code{\id=} can be found by lexical lookup
15631582
(\ref{lexicalLookup}),
15641583
or lexical lookup yields nothing, and the location has access to \THIS,
1565-
and the enclosing class or mixin has a setter named \code{\id=},
1584+
and the interface of the enclosing class or mixin has
1585+
a setter named \code{\id=},
15661586
it is a compile-time error to assign to \id.
15671587

15681588
Similarly, assignment to a non-late final instance variable \id{}
@@ -1589,10 +1609,10 @@ \subsection{Implicitly Induced Getters and Setters}
15891609

15901610
\commentary{%
15911611
Note that there are many situations where such a variable declaration
1592-
is a compile-time error
1593-
in which case we do not specify any of its properties,
1612+
is a compile-time error.
1613+
In this case we do not specify any of its properties,
15941614
and in particular it makes no sense to say
1595-
that it has a particular initial value.
1615+
that it has a specific initial value.
15961616
For example, it is an error if a final instance variable
15971617
is not initialized by one of the above mechanisms.%
15981618
}
@@ -1621,6 +1641,7 @@ \subsection{Implicitly Induced Getters and Setters}
16211641
}
16221642

16231643
\LMHash{}%
1644+
\BlindDefineSymbol{\id, o}%
16241645
Initialization of an instance variable \id{}
16251646
with an initializing expression $e$
16261647
proceeds as follows:
@@ -1687,7 +1708,7 @@ \subsection{Evaluation of Implicit Variable Getters}
16871708
if the variable \code{x} has been bound to an object
16881709
when its getter is invoked for the first time,
16891710
$e$ will never be executed.
1690-
In other words, the initializing expression can be pre-empted.%
1711+
In other words, the initializing expression can be pre-empted by an assignment.%
16911712
}
16921713

16931714
\commentary{%
@@ -1810,7 +1831,8 @@ \subsection{Evaluation of Implicit Variable Getters}
18101831
the implicitly induced getter of \id{} is a late-initialized getter.
18111832
This determines the semantics of an invocation.
18121833
\commentary{%
1813-
Note that these static variables can be \emph{implicitly} late-initialized.%
1834+
Note that these static variables can be \emph{implicitly} late-initialized,
1835+
in the sense that they do not have the modifier \LATE.%
18141836
}
18151837
\item \emph{Constant variable.}
18161838
If $d$ declares a constant variable with the initializing expression $e$,
@@ -17996,10 +18018,10 @@ \subsubsection{For-in}
1799618018

1799718019
\commentary{%
1799818020
It follows that it is a compile-time error
17999-
if $D$ is empty and \id{} is a final variable;
18000-
and it is a dynamic error if $e$ has a top type,
18021+
if $D$ is empty and \id{} is an immutable variable;
18022+
and it is a dynamic error if $e$ has type \DYNAMIC,
1800118023
but $e$ evaluates to an instance of a type
18002-
which is not a subtype of \code{Iterable<dynamic>}.%
18024+
which is not a subtype of \code{Iterable<\DYNAMIC>}.%
1800318025
}
1800418026

1800518027

@@ -18023,7 +18045,7 @@ \subsubsection{Asynchronous For-in}
1802318045
% This error can occur due to implicit casts and null.
1802418046
It is a dynamic type error if $o$ is not an instance of
1802518047
a class that implements \code{Stream}.
18026-
It is a compile-time error if $D$ is empty and \id{} is a final variable.
18048+
It is a compile-time error if $D$ is empty and \id{} is an immutable variable.
1802718049

1802818050
\LMHash{}%
1802918051
The stream associated with the innermost enclosing asynchronous for loop,

0 commit comments

Comments
 (0)