@@ -1393,19 +1393,25 @@ \section{Variables}
1393
1393
}
1394
1394
1395
1395
\LMHash{}%
1396
- A \IndexCustom{final variable}{variable!final }
1396
+ An \IndexCustom{immutable variable}{variable!immutable }
1397
1397
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
1399
1399
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
1401
1401
the modifier \FINAL{} or the modifier \CONST.
1402
1402
A \IndexCustom{mutable variable}{variable!mutable}
1403
- is a variable which is not final .
1403
+ is a variable which is not immutable .
1404
1404
1405
1405
1406
1406
\subsection{Implicitly Induced Getters and Setters}
1407
1407
\LMLabel{implicitlyInducedGettersAndSetters}
1408
1408
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
+
1409
1415
\LMHash{}%
1410
1416
The following rules on implicitly induced getters and setters
1411
1417
apply to all non-local variable declarations.
@@ -1416,6 +1422,7 @@ \subsection{Implicitly Induced Getters and Setters}
1416
1422
}
1417
1423
1418
1424
\LMHash{}%
1425
+ \Case{Getter: Variable with declared type}
1419
1426
Consider a variable declaration of one of the forms
1420
1427
1421
1428
\begin{itemize}
@@ -1433,8 +1440,10 @@ \subsection{Implicitly Induced Getters and Setters}
1433
1440
whose invocation evaluates as described below
1434
1441
(\ref{evaluationOfImplicitVariableGetters}).
1435
1442
In these cases the declared type of \id{} is $T$.
1443
+ \EndCase
1436
1444
1437
1445
\LMHash{}%
1446
+ \Case{Getter: Variable with no declared type}
1438
1447
A variable declaration of one of the forms
1439
1448
1440
1449
\begin{itemize}
@@ -1459,12 +1468,15 @@ \subsection{Implicitly Induced Getters and Setters}
1459
1468
For example, an instance variable declaration of the form
1460
1469
\code{\VAR\,\,x;} could have been transformed into
1461
1470
\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$.%
1465
1475
}
1476
+ \EndCase
1466
1477
1467
1478
\LMHash{}%
1479
+ \Case{Setter: Mutable variable with declared type}
1468
1480
A mutable variable declaration of one of the forms
1469
1481
1470
1482
\begin{itemize}
@@ -1478,6 +1490,31 @@ \subsection{Implicitly Induced Getters and Setters}
1478
1490
whose execution sets the value of \id{} to the incoming argument $x$.
1479
1491
1480
1492
\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}
1481
1518
A variable declaration of the form
1482
1519
\code{\STATIC?\,\,\LATE\,\,\FINAL\,\,$T$\,\,\id;}
1483
1520
implicitly induces a setter (\ref{setters}) with the header
@@ -1496,28 +1533,10 @@ \subsection{Implicitly Induced Getters and Setters}
1496
1533
The property that the variable is never mutated after initialization
1497
1534
is enforced dynamically rather than statically.%
1498
1535
}
1536
+ \EndCase
1499
1537
1500
1538
\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}
1521
1540
A variable declaration of the form
1522
1541
\code{\STATIC?\,\,\LATE\,\,\FINAL\,\,\id;}
1523
1542
implicitly induces a setter with the header
@@ -1528,6 +1547,7 @@ \subsection{Implicitly Induced Getters and Setters}
1528
1547
An execution of the setter
1529
1548
in a situation where the variable \id{} has been bound to an object
1530
1549
will incur a dynamic error.
1550
+ \EndCase
1531
1551
1532
1552
\LMHash{}%
1533
1553
The scope into which the implicit getters and setters are introduced
@@ -1542,14 +1562,13 @@ \subsection{Implicitly Induced Getters and Setters}
1542
1562
the body scope of the immediately enclosing class.
1543
1563
1544
1564
\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.
1553
1572
1554
1573
\LMHash{}%
1555
1574
Let \id{} be a variable declared by a variable declaration
@@ -1568,11 +1587,12 @@ \subsection{Implicitly Induced Getters and Setters}
1568
1587
is also initialized in the initializer list of $k$
1569
1588
(\ref{initializerLists}).
1570
1589
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,
1572
1591
so unless a setter named \code{\id=} can be found by lexical lookup
1573
1592
(\ref{lexicalLookup}),
1574
1593
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=},
1576
1596
it is a compile-time error to assign to \id.
1577
1597
1578
1598
Similarly, assignment to a non-late final instance variable \id{}
@@ -1599,10 +1619,10 @@ \subsection{Implicitly Induced Getters and Setters}
1599
1619
1600
1620
\commentary{%
1601
1621
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,
1604
1624
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.
1606
1626
For example, it is an error if a final instance variable
1607
1627
is not initialized by one of the above mechanisms.%
1608
1628
}
@@ -1631,6 +1651,7 @@ \subsection{Implicitly Induced Getters and Setters}
1631
1651
}
1632
1652
1633
1653
\LMHash{}%
1654
+ \BlindDefineSymbol{\id, o}%
1634
1655
Initialization of an instance variable \id{}
1635
1656
with an initializing expression $e$
1636
1657
proceeds as follows:
@@ -1697,7 +1718,7 @@ \subsection{Evaluation of Implicit Variable Getters}
1697
1718
if the variable \code{x} has been bound to an object
1698
1719
when its getter is invoked for the first time,
1699
1720
$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 .%
1701
1722
}
1702
1723
1703
1724
\commentary{%
@@ -1820,7 +1841,8 @@ \subsection{Evaluation of Implicit Variable Getters}
1820
1841
the implicitly induced getter of \id{} is a late-initialized getter.
1821
1842
This determines the semantics of an invocation.
1822
1843
\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.%
1824
1846
}
1825
1847
\item \emph{Constant variable.}
1826
1848
If $d$ declares a constant variable with the initializing expression $e$,
@@ -18150,10 +18172,10 @@ \subsubsection{For-in}
18150
18172
18151
18173
\commentary{%
18152
18174
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 ,
18155
18177
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 >}.%
18157
18179
}
18158
18180
18159
18181
@@ -18177,7 +18199,7 @@ \subsubsection{Asynchronous For-in}
18177
18199
% This error can occur due to implicit casts and null.
18178
18200
It is a dynamic type error if $o$ is not an instance of
18179
18201
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.
18181
18203
18182
18204
\LMHash{}%
18183
18205
The stream associated with the innermost enclosing asynchronous for loop,
0 commit comments