@@ -1383,19 +1383,25 @@ \section{Variables}
1383
1383
}
1384
1384
1385
1385
\LMHash{}%
1386
- A \IndexCustom{final variable}{variable!final }
1386
+ An \IndexCustom{immutable variable}{variable!immutable }
1387
1387
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
1389
1389
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
1391
1391
the modifier \FINAL{} or the modifier \CONST.
1392
1392
A \IndexCustom{mutable variable}{variable!mutable}
1393
- is a variable which is not final .
1393
+ is a variable which is not immutable .
1394
1394
1395
1395
1396
1396
\subsection{Implicitly Induced Getters and Setters}
1397
1397
\LMLabel{implicitlyInducedGettersAndSetters}
1398
1398
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
+
1399
1405
\LMHash{}%
1400
1406
The following rules on implicitly induced getters and setters
1401
1407
apply to all non-local variable declarations.
@@ -1406,6 +1412,7 @@ \subsection{Implicitly Induced Getters and Setters}
1406
1412
}
1407
1413
1408
1414
\LMHash{}%
1415
+ \Case{Getter: Variable with declared type}
1409
1416
Consider a variable declaration of one of the forms
1410
1417
1411
1418
\begin{itemize}
@@ -1423,8 +1430,10 @@ \subsection{Implicitly Induced Getters and Setters}
1423
1430
whose invocation evaluates as described below
1424
1431
(\ref{evaluationOfImplicitVariableGetters}).
1425
1432
In these cases the declared type of \id{} is $T$.
1433
+ \EndCase
1426
1434
1427
1435
\LMHash{}%
1436
+ \Case{Getter: Variable with no declared type}
1428
1437
A variable declaration of one of the forms
1429
1438
1430
1439
\begin{itemize}
@@ -1449,12 +1458,15 @@ \subsection{Implicitly Induced Getters and Setters}
1449
1458
For example, an instance variable declaration of the form
1450
1459
\code{\VAR\,\,x;} could have been transformed into
1451
1460
\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$.%
1455
1465
}
1466
+ \EndCase
1456
1467
1457
1468
\LMHash{}%
1469
+ \Case{Setter: Mutable variable with declared type}
1458
1470
A mutable variable declaration of one of the forms
1459
1471
1460
1472
\begin{itemize}
@@ -1468,6 +1480,31 @@ \subsection{Implicitly Induced Getters and Setters}
1468
1480
whose execution sets the value of \id{} to the incoming argument $x$.
1469
1481
1470
1482
\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}
1471
1508
A variable declaration of the form
1472
1509
\code{\STATIC?\,\,\LATE\,\,\FINAL\,\,$T$\,\,\id;}
1473
1510
implicitly induces a setter (\ref{setters}) with the header
@@ -1486,28 +1523,10 @@ \subsection{Implicitly Induced Getters and Setters}
1486
1523
The property that the variable is never mutated after initialization
1487
1524
is enforced dynamically rather than statically.%
1488
1525
}
1526
+ \EndCase
1489
1527
1490
1528
\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}
1511
1530
A variable declaration of the form
1512
1531
\code{\STATIC?\,\,\LATE\,\,\FINAL\,\,\id;}
1513
1532
implicitly induces a setter with the header
@@ -1518,6 +1537,7 @@ \subsection{Implicitly Induced Getters and Setters}
1518
1537
An execution of the setter
1519
1538
in a situation where the variable \id{} has been bound to an object
1520
1539
will incur a dynamic error.
1540
+ \EndCase
1521
1541
1522
1542
\LMHash{}%
1523
1543
The scope into which the implicit getters and setters are introduced
@@ -1532,14 +1552,13 @@ \subsection{Implicitly Induced Getters and Setters}
1532
1552
the body scope of the immediately enclosing class.
1533
1553
1534
1554
\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.
1543
1562
1544
1563
\LMHash{}%
1545
1564
Let \id{} be a variable declared by a variable declaration
@@ -1558,11 +1577,12 @@ \subsection{Implicitly Induced Getters and Setters}
1558
1577
is also initialized in the initializer list of $k$
1559
1578
(\ref{initializerLists}).
1560
1579
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,
1562
1581
so unless a setter named \code{\id=} can be found by lexical lookup
1563
1582
(\ref{lexicalLookup}),
1564
1583
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=},
1566
1586
it is a compile-time error to assign to \id.
1567
1587
1568
1588
Similarly, assignment to a non-late final instance variable \id{}
@@ -1589,10 +1609,10 @@ \subsection{Implicitly Induced Getters and Setters}
1589
1609
1590
1610
\commentary{%
1591
1611
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,
1594
1614
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.
1596
1616
For example, it is an error if a final instance variable
1597
1617
is not initialized by one of the above mechanisms.%
1598
1618
}
@@ -1621,6 +1641,7 @@ \subsection{Implicitly Induced Getters and Setters}
1621
1641
}
1622
1642
1623
1643
\LMHash{}%
1644
+ \BlindDefineSymbol{\id, o}%
1624
1645
Initialization of an instance variable \id{}
1625
1646
with an initializing expression $e$
1626
1647
proceeds as follows:
@@ -1687,7 +1708,7 @@ \subsection{Evaluation of Implicit Variable Getters}
1687
1708
if the variable \code{x} has been bound to an object
1688
1709
when its getter is invoked for the first time,
1689
1710
$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 .%
1691
1712
}
1692
1713
1693
1714
\commentary{%
@@ -1810,7 +1831,8 @@ \subsection{Evaluation of Implicit Variable Getters}
1810
1831
the implicitly induced getter of \id{} is a late-initialized getter.
1811
1832
This determines the semantics of an invocation.
1812
1833
\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.%
1814
1836
}
1815
1837
\item \emph{Constant variable.}
1816
1838
If $d$ declares a constant variable with the initializing expression $e$,
@@ -17996,10 +18018,10 @@ \subsubsection{For-in}
17996
18018
17997
18019
\commentary{%
17998
18020
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 ,
18001
18023
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 >}.%
18003
18025
}
18004
18026
18005
18027
@@ -18023,7 +18045,7 @@ \subsubsection{Asynchronous For-in}
18023
18045
% This error can occur due to implicit casts and null.
18024
18046
It is a dynamic type error if $o$ is not an instance of
18025
18047
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.
18027
18049
18028
18050
\LMHash{}%
18029
18051
The stream associated with the innermost enclosing asynchronous for loop,
0 commit comments