Skip to content

Commit b75387a

Browse files
committed
Further improvements (introduce cases for different kinds of variables)
1 parent c2b14a6 commit b75387a

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
@@ -1393,19 +1393,25 @@ \section{Variables}
13931393
}
13941394

13951395
\LMHash{}%
1396-
A \IndexCustom{final variable}{variable!final}
1396+
An \IndexCustom{immutable variable}{variable!immutable}
13971397
is a variable whose binding is fixed upon initialization;
1398-
a final variable \id{} will always refer to the same object
1398+
an immutable variable \id{} will always refer to the same object
13991399
after \id{} has been initialized.
1400-
A variable is final if{}f its declaration includes
1400+
A variable is immutable if{}f its declaration includes
14011401
the modifier \FINAL{} or the modifier \CONST.
14021402
A \IndexCustom{mutable variable}{variable!mutable}
1403-
is a variable which is not final.
1403+
is a variable which is not immutable.
14041404

14051405

14061406
\subsection{Implicitly Induced Getters and Setters}
14071407
\LMLabel{implicitlyInducedGettersAndSetters}
14081408

1409+
%% TODO(eernst): When inference is specified, we should be able to conclude
1410+
%% that the cases with no declared type do not exist after type inference
1411+
%% (for instance `var x;` or `var x = e;`), and then we can replace all rules
1412+
%% about such cases by commentary saying that they may exist in the input,
1413+
%% but they are gone after type inference.
1414+
14091415
\LMHash{}%
14101416
The following rules on implicitly induced getters and setters
14111417
apply to all non-local variable declarations.
@@ -1416,6 +1422,7 @@ \subsection{Implicitly Induced Getters and Setters}
14161422
}
14171423

14181424
\LMHash{}%
1425+
\Case{Getter: Variable with declared type}
14191426
Consider a variable declaration of one of the forms
14201427

14211428
\begin{itemize}
@@ -1433,8 +1440,10 @@ \subsection{Implicitly Induced Getters and Setters}
14331440
whose invocation evaluates as described below
14341441
(\ref{evaluationOfImplicitVariableGetters}).
14351442
In these cases the declared type of \id{} is $T$.
1443+
\EndCase
14361444

14371445
\LMHash{}%
1446+
\Case{Getter: Variable with no declared type}
14381447
A variable declaration of one of the forms
14391448

14401449
\begin{itemize}
@@ -1459,12 +1468,15 @@ \subsection{Implicitly Induced Getters and Setters}
14591468
For example, an instance variable declaration of the form
14601469
\code{\VAR\,\,x;} could have been transformed into
14611470
\code{$T$\,\,x;} based on member signatures named \code{x} in superinterfaces
1462-
of the enclosing class.
1463-
Hence, the type \DYNAMIC{} is only used as mentioned above when
1464-
type inference fails to provide a different type.%
1471+
of the enclosing class, and
1472+
\code{\VAR\,x\,\,=\,\,$e$;} could have been transformed into
1473+
\code{$T$\,x\,\,=\,\,$e$;}
1474+
where $T$ is the static type of $e$.%
14651475
}
1476+
\EndCase
14661477

14671478
\LMHash{}%
1479+
\Case{Setter: Mutable variable with declared type}
14681480
A mutable variable declaration of one of the forms
14691481

14701482
\begin{itemize}
@@ -1478,6 +1490,31 @@ \subsection{Implicitly Induced Getters and Setters}
14781490
whose execution sets the value of \id{} to the incoming argument $x$.
14791491

14801492
\LMHash{}%
1493+
\Case{Setter: Mutable variable with no declared type, with initialization}
1494+
A mutable variable declaration of the form
1495+
\code{\STATIC?\,\,\LATE?\,\,\VAR\,\,\id{} = $e$;}
1496+
implicitly induces a setter with the header
1497+
\code{\VOID\,\,\SET\,\,\id(\DYNAMIC\,\,$x$)},
1498+
whose execution sets the value of \id{} to the incoming argument $x$.
1499+
\EndCase
1500+
1501+
\LMHash{}%
1502+
\Case{Setter: Mutable variable with no declared type, no initialization}
1503+
A mutable variable declaration of the form
1504+
\code{\STATIC?\,\,\LATE?\,\,\VAR\,\,\id;}
1505+
implicitly induces a setter with the header
1506+
\code{\VOID\,\,\SET\,\,\id(\DYNAMIC\,\,$x$)},
1507+
whose execution sets the value of \id{} to the incoming argument $x$.
1508+
1509+
\commentary{%
1510+
It is again assumed that type inference has taken place already,
1511+
which could change \code{\VAR\,\,x;} to \code{$T$\,\,x;}
1512+
and hence take us to an earlier case.%
1513+
}
1514+
\EndCase
1515+
1516+
\LMHash{}%
1517+
\Case{Setter: Late-final variable with declared type}
14811518
A variable declaration of the form
14821519
\code{\STATIC?\,\,\LATE\,\,\FINAL\,\,$T$\,\,\id;}
14831520
implicitly induces a setter (\ref{setters}) with the header
@@ -1496,28 +1533,10 @@ \subsection{Implicitly Induced Getters and Setters}
14961533
The property that the variable is never mutated after initialization
14971534
is enforced dynamically rather than statically.%
14981535
}
1536+
\EndCase
14991537

15001538
\LMHash{}%
1501-
A mutable variable declaration of the form
1502-
\code{\STATIC?\,\,\LATE?\,\,\VAR\,\,\id;}
1503-
implicitly induces a setter with the header
1504-
\code{\VOID\,\,\SET\,\,\id(\DYNAMIC\,\,$x$)},
1505-
whose execution sets the value of \id{} to the incoming argument $x$.
1506-
1507-
\commentary{%
1508-
It is again assumed that type inference has taken place already,
1509-
which could change \code{\VAR\,\,x;} to \code{$T$\,\,x;}
1510-
and hence take us to an earlier case.%
1511-
}
1512-
1513-
\LMHash{}%
1514-
A mutable variable declaration of the form
1515-
\code{\STATIC?\,\,\LATE?\,\,\VAR\,\,\id{} = $e$;}
1516-
implicitly induces a setter with the header
1517-
\code{\VOID\,\,\SET\,\,\id(\DYNAMIC\,\,$x$)},
1518-
whose execution sets the value of \id{} to the incoming argument $x$.
1519-
1520-
\LMHash{}%
1539+
\Case{Setter: Late-final variable with no declared type, no initialization}
15211540
A variable declaration of the form
15221541
\code{\STATIC?\,\,\LATE\,\,\FINAL\,\,\id;}
15231542
implicitly induces a setter with the header
@@ -1528,6 +1547,7 @@ \subsection{Implicitly Induced Getters and Setters}
15281547
An execution of the setter
15291548
in a situation where the variable \id{} has been bound to an object
15301549
will incur a dynamic error.
1550+
\EndCase
15311551

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

15441564
\LMHash{}%
1545-
A mutable library variable introduces a setter into
1546-
the library scope of the enclosing library.
1547-
A mutable class variable introduces a static setter into
1548-
the body scope of the immediately enclosing class.
1549-
An instance variable that introduces a setter
1550-
(\commentary{it can be non-final, or late and final})
1551-
introduces an instance setter into
1552-
the body scope of the immediately enclosing class.
1565+
A non-local variable introduces a setter if{}f it is mutable or late and final.
1566+
A library variable which introduces a setter will introduce
1567+
a library setter into the enclosing library scope.
1568+
A class variable which introduces a setter will introduce
1569+
a static setter into the body scope of the immediately enclosing class.
1570+
An instance variable that introduces a setter will introduce
1571+
an instance setter into the body scope of the immediately enclosing class.
15531572

15541573
\LMHash{}%
15551574
Let \id{} be a variable declared by a variable declaration
@@ -1568,11 +1587,12 @@ \subsection{Implicitly Induced Getters and Setters}
15681587
is also initialized in the initializer list of $k$
15691588
(\ref{initializerLists}).
15701589

1571-
A non-late static final variable \id{} does not induce a setter,
1590+
A non-late static immutable variable \id{} does not induce a setter,
15721591
so unless a setter named \code{\id=} can be found by lexical lookup
15731592
(\ref{lexicalLookup}),
15741593
or lexical lookup yields nothing, and the location has access to \THIS,
1575-
and the enclosing class or mixin has a setter named \code{\id=},
1594+
and the interface of the enclosing class or mixin has
1595+
a setter named \code{\id=},
15761596
it is a compile-time error to assign to \id.
15771597

15781598
Similarly, assignment to a non-late final instance variable \id{}
@@ -1599,10 +1619,10 @@ \subsection{Implicitly Induced Getters and Setters}
15991619

16001620
\commentary{%
16011621
Note that there are many situations where such a variable declaration
1602-
is a compile-time error
1603-
in which case we do not specify any of its properties,
1622+
is a compile-time error.
1623+
In this case we do not specify any of its properties,
16041624
and in particular it makes no sense to say
1605-
that it has a particular initial value.
1625+
that it has a specific initial value.
16061626
For example, it is an error if a final instance variable
16071627
is not initialized by one of the above mechanisms.%
16081628
}
@@ -1631,6 +1651,7 @@ \subsection{Implicitly Induced Getters and Setters}
16311651
}
16321652

16331653
\LMHash{}%
1654+
\BlindDefineSymbol{\id, o}%
16341655
Initialization of an instance variable \id{}
16351656
with an initializing expression $e$
16361657
proceeds as follows:
@@ -1697,7 +1718,7 @@ \subsection{Evaluation of Implicit Variable Getters}
16971718
if the variable \code{x} has been bound to an object
16981719
when its getter is invoked for the first time,
16991720
$e$ will never be executed.
1700-
In other words, the initializing expression can be pre-empted.%
1721+
In other words, the initializing expression can be pre-empted by an assignment.%
17011722
}
17021723

17031724
\commentary{%
@@ -1820,7 +1841,8 @@ \subsection{Evaluation of Implicit Variable Getters}
18201841
the implicitly induced getter of \id{} is a late-initialized getter.
18211842
This determines the semantics of an invocation.
18221843
\commentary{%
1823-
Note that these static variables can be \emph{implicitly} late-initialized.%
1844+
Note that these static variables can be \emph{implicitly} late-initialized,
1845+
in the sense that they do not have the modifier \LATE.%
18241846
}
18251847
\item \emph{Constant variable.}
18261848
If $d$ declares a constant variable with the initializing expression $e$,
@@ -18150,10 +18172,10 @@ \subsubsection{For-in}
1815018172

1815118173
\commentary{%
1815218174
It follows that it is a compile-time error
18153-
if $D$ is empty and \id{} is a final variable;
18154-
and it is a dynamic error if $e$ has a top type,
18175+
if $D$ is empty and \id{} is an immutable variable;
18176+
and it is a dynamic error if $e$ has type \DYNAMIC,
1815518177
but $e$ evaluates to an instance of a type
18156-
which is not a subtype of \code{Iterable<dynamic>}.%
18178+
which is not a subtype of \code{Iterable<\DYNAMIC>}.%
1815718179
}
1815818180

1815918181

@@ -18177,7 +18199,7 @@ \subsubsection{Asynchronous For-in}
1817718199
% This error can occur due to implicit casts and null.
1817818200
It is a dynamic type error if $o$ is not an instance of
1817918201
a class that implements \code{Stream}.
18180-
It is a compile-time error if $D$ is empty and \id{} is a final variable.
18202+
It is a compile-time error if $D$ is empty and \id{} is an immutable variable.
1818118203

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

0 commit comments

Comments
 (0)