OLD | NEW |
---|---|
1 \documentclass{article} | 1 \documentclass{article} |
2 \usepackage{epsfig} | 2 \usepackage{epsfig} |
3 \usepackage{color} | 3 \usepackage{color} |
4 \usepackage{dart} | 4 \usepackage{dart} |
5 \usepackage{bnf} | 5 \usepackage{bnf} |
6 \usepackage{hyperref} | 6 \usepackage{hyperref} |
7 \usepackage{lmodern} | 7 \usepackage{lmodern} |
8 \usepackage[T1]{fontenc} | 8 \usepackage[T1]{fontenc} |
9 \newcommand{\code}[1]{{\sf #1}} | 9 \newcommand{\code}[1]{{\sf #1}} |
10 \title{Dart Programming Language Specification \\ | 10 \title{Dart Programming Language Specification \\ |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 | 188 |
189 \subsection{Scoping} | 189 \subsection{Scoping} |
190 \LMLabel{scoping} | 190 \LMLabel{scoping} |
191 | 191 |
192 \LMHash{} | 192 \LMHash{} |
193 A {\em namespace} is a mapping of names denoting declarations to actual declarat ions. Let $NS$ be a namespace. We say that a name $n$ {\em is in }$NS$ if $n$ i s a key of $NS$. We say a declaration $d$ {\em is in }$NS$ if a key of $NS$ maps to $d$. | 193 A {\em namespace} is a mapping of names denoting declarations to actual declarat ions. Let $NS$ be a namespace. We say that a name $n$ {\em is in }$NS$ if $n$ i s a key of $NS$. We say a declaration $d$ {\em is in }$NS$ if a key of $NS$ maps to $d$. |
194 | 194 |
195 \LMHash{} | 195 \LMHash{} |
196 A scope $S_0$ induces a namespace $NS_0$ that maps the simple name of each varia ble, type or function declaration $d$ declared in $S_0$ to $d$. Labels are not i ncluded in the induced namespace of a scope; instead they have their own dedicat ed namespace. | 196 A scope $S_0$ induces a namespace $NS_0$ that maps the simple name of each varia ble, type or function declaration $d$ declared in $S_0$ to $d$. Labels are not i ncluded in the induced namespace of a scope; instead they have their own dedicat ed namespace. |
197 | 197 |
198 \commentary{It is therefore impossible, e.g., to define a class that declares a method and a field with the same name in Dart. Similarly one cannot declare a t op-level function with the same name as a library variable or class. | 198 \commentary{ |
199 } | 199 It is therefore impossible, e.g., to define a class that declares a method and a n instance variable with the same name in Dart. |
Lasse Reichstein Nielsen
2017/01/09 08:55:12
It doesn't have to be an instance variable - the e
eernst
2017/01/09 10:16:52
Actually, my reasoning was "it says `e.g.`, so we
| |
200 Similarly one cannot declare a top-level function with the same name as a librar y variable or a class. | |
201 } | |
200 | 202 |
201 \LMHash{} | 203 \LMHash{} |
202 It is a compile-time error if there is more than one entity with the same name d eclared in the same scope. | 204 It is a compile-time error if there is more than one entity with the same name d eclared in the same scope. |
203 | 205 |
204 \commentary{ | 206 \commentary{ |
205 In some cases, the name of the declaration differs from the identifier used to d eclare it. Setters have names that are distinct from the corresponding getters because they always have an = automatically added at the end, and unary minus ha s the special name unary-. | 207 In some cases, the name of the declaration differs from the identifier used to d eclare it. Setters have names that are distinct from the corresponding getters because they always have an = automatically added at the end, and unary minus ha s the special name unary-. |
206 } | 208 } |
207 | 209 |
208 \LMHash{} | 210 \LMHash{} |
209 Dart is lexically scoped. Scopes may nest. A name or declaration $d$ is {\em available in scope} $S$ if $d$ is in the namespace induced by $S$ or if $d$ is available in the lexically enclosing scope of $S$. We say that a name or declar ation $d$ is {\em in scope} if $d$ is available in the current scope. | 211 Dart is lexically scoped. Scopes may nest. A name or declaration $d$ is {\em available in scope} $S$ if $d$ is in the namespace induced by $S$ or if $d$ is available in the lexically enclosing scope of $S$. We say that a name or declar ation $d$ is {\em in scope} if $d$ is available in the current scope. |
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1051 | 1053 |
1052 %It is a compile-time error if a getter`s formal parameter list is not empty. | 1054 %It is a compile-time error if a getter`s formal parameter list is not empty. |
1053 | 1055 |
1054 \LMHash{} | 1056 \LMHash{} |
1055 The instance getters of a class $C$ are those instance getters declared by $C$, either implicitly or explicitly, and the instance getters inherited by $C$ from its superclass. The static getters of a class $C$ are those static getters decla red by $C$. | 1057 The instance getters of a class $C$ are those instance getters declared by $C$, either implicitly or explicitly, and the instance getters inherited by $C$ from its superclass. The static getters of a class $C$ are those static getters decla red by $C$. |
1056 | 1058 |
1057 \LMHash{} | 1059 \LMHash{} |
1058 It is a compile-time error if a class has both a getter and a method with the sa me name. This restriction holds regardless of whether the getter is defined expl icitly or implicitly, or whether the getter or the method are inherited or not. | 1060 It is a compile-time error if a class has both a getter and a method with the sa me name. This restriction holds regardless of whether the getter is defined expl icitly or implicitly, or whether the getter or the method are inherited or not. |
1059 | 1061 |
1060 \commentary{ | 1062 \commentary{ |
1061 This implies that a getter can never override a method, and a method can never o verride a getter or field. | 1063 This implies that a getter can never override a method, and a method can never o verride a getter or an instance variable. |
Lasse Reichstein Nielsen
2017/01/09 08:55:12
It's really not necessary to mention instance vari
eernst
2017/01/09 10:16:52
Right. I'll keep it to give the hint to readers wh
| |
1062 } | 1064 } |
1063 | 1065 |
1064 \LMHash{} | 1066 \LMHash{} |
1065 It is a static warning if the return type of a getter is \VOID. | 1067 It is a static warning if the return type of a getter is \VOID. |
1066 It is a static warning if a getter $m_1$ overrides (\ref{inheritanceAndOverridi ng}) a getter | 1068 It is a static warning if a getter $m_1$ overrides (\ref{inheritanceAndOverridi ng}) a getter |
1067 $m_2$ and the type of $m_1$ is not a subtype of the type of $m_2$. | 1069 $m_2$ and the type of $m_1$ is not a subtype of the type of $m_2$. |
1068 | 1070 |
1069 \LMHash{} | 1071 \LMHash{} |
1070 It is a static warning if a class declares a static getter named $v$ and also h as a non-static setter named $v=$. It is a static warning if a class $C$ declare s an instance getter named $v$ and an accessible static member named $v$ or $v=$ is declared in a superclass of $C$. These warnings must be issued regardless of whether the getters or setters are declared explicitly or implicitly. | 1072 It is a static warning if a class declares a static getter named $v$ and also h as a non-static setter named $v=$. It is a static warning if a class $C$ declare s an instance getter named $v$ and an accessible static member named $v$ or $v=$ is declared in a superclass of $C$. These warnings must be issued regardless of whether the getters or setters are declared explicitly or implicitly. |
1071 | 1073 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1238 \begin{grammar} | 1240 \begin{grammar} |
1239 {\bf constructorSignature:} | 1241 {\bf constructorSignature:} |
1240 identifier (`{\escapegrammar .}' identifier)? formalParameterList | 1242 identifier (`{\escapegrammar .}' identifier)? formalParameterList |
1241 . | 1243 . |
1242 \end{grammar} | 1244 \end{grammar} |
1243 | 1245 |
1244 \LMHash{} | 1246 \LMHash{} |
1245 A {\em constructor parameter list} is a parenthesized, comma-separated list of f ormal constructor parameters. A {\em formal constructor parameter} is either a f ormal parameter (\ref{formalParameters}) or an initializing formal. An {\em init ializing formal} has the form \code{\THIS{}.$id$}, where $id$ is the name of an instance variable of the immediately enclosing class. It is a compile-time erro r if $id$ is not an instance variable of the immediately enclosing class. It is a compile-time error if an initializing formal is used by a function other than a non-redirecting generative constructor. | 1247 A {\em constructor parameter list} is a parenthesized, comma-separated list of f ormal constructor parameters. A {\em formal constructor parameter} is either a f ormal parameter (\ref{formalParameters}) or an initializing formal. An {\em init ializing formal} has the form \code{\THIS{}.$id$}, where $id$ is the name of an instance variable of the immediately enclosing class. It is a compile-time erro r if $id$ is not an instance variable of the immediately enclosing class. It is a compile-time error if an initializing formal is used by a function other than a non-redirecting generative constructor. |
1246 | 1248 |
1247 \LMHash{} | 1249 \LMHash{} |
1248 If an explicit type is attached to the initializing formal, that is its static t ype. Otherwise, the type of an initializing formal named $id$ is $T_{id}$, where $T_{id}$ is the type of the field named $id$ in the immediately enclosing class . It is a static warning if the static type of $id$ is not assignable to $T_{id} $. | 1250 If an explicit type is attached to the initializing formal, that is its static t ype. |
1251 Otherwise, the type of an initializing formal named $id$ is $T_{id}$, where $T_{ id}$ is the type of the instance variable named $id$ in the immediately enclosin g class. | |
1252 It is a static warning if the static type of $id$ is not assignable to $T_{id}$. | |
1249 | 1253 |
1250 \LMHash{} | 1254 \LMHash{} |
1251 Initializing formals constitute an exception to the rule that every formal param eter introduces a local variable into the formal parameter scope (\ref{formalPar ameters}). | 1255 Initializing formals constitute an exception to the rule that every formal param eter introduces a local variable into the formal parameter scope (\ref{formalPar ameters}). |
1252 When the formal parameter list of a non-redirecting generative constructor conta ins any initializing formals, a new scope is introduced, the {\em formal paramet er initializer scope}, which is the current scope of the initializer list of the constructor, and which is enclosed in the scope where the constructor is declar ed. | 1256 When the formal parameter list of a non-redirecting generative constructor conta ins any initializing formals, a new scope is introduced, the {\em formal paramet er initializer scope}, which is the current scope of the initializer list of the constructor, and which is enclosed in the scope where the constructor is declar ed. |
1253 Each initializing formal in the formal parameter list introduces a final local v ariable into the formal parameter initializer scope, but not into the formal par ameter scope; every other formal parameter introduces a local variable into both the formal parameter scope and the formal parameter initializer scope. | 1257 Each initializing formal in the formal parameter list introduces a final local v ariable into the formal parameter initializer scope, but not into the formal par ameter scope; every other formal parameter introduces a local variable into both the formal parameter scope and the formal parameter initializer scope. |
1254 | 1258 |
1255 \commentary{ | 1259 \commentary{ |
1256 This means that formal parameters, including initializing formals, must have dis tinct names, and that initializing formals are in scope for the initializer list , but they are not in scope for the body of the constructor. | 1260 This means that formal parameters, including initializing formals, must have dis tinct names, and that initializing formals are in scope for the initializer list , but they are not in scope for the body of the constructor. |
1257 When a formal parameter introduces a local variable into two scopes, it is still one variable and hence one storage location. | 1261 When a formal parameter introduces a local variable into two scopes, it is still one variable and hence one storage location. |
1258 The type of the constructor is defined in terms of its formal parameters, includ ing the initializing formals. | 1262 The type of the constructor is defined in terms of its formal parameters, includ ing the initializing formals. |
1259 } | 1263 } |
1260 | 1264 |
1261 \LMHash{} | 1265 \LMHash{} |
1262 Initializing formals are executed during the execution of generative constructor s detailed below. Executing an initializing formal \code{\THIS{}.$id$} causes t he field $id$ of the immediately surrounding class to be assigned the value of t he corresponding actual parameter, unless $id$ is a final variable that has alre ady been initialized, in which case a runtime error occurs. | 1266 Initializing formals are executed during the execution of generative constructor s detailed below. |
1263 | 1267 Executing an initializing formal \code{\THIS{}.$id$} causes the instance variabl e $id$ of the immediately surrounding class to be assigned the value of the corr esponding actual parameter, |
1268 unless $id$ is a final variable that has already been initialized, in which case a runtime error occurs. | |
1264 | 1269 |
1265 \commentary{ | 1270 \commentary{ |
1266 The above rule allows initializing formals to be used as optional parameters: | 1271 The above rule allows initializing formals to be used as optional parameters: |
1267 } | 1272 } |
1268 | 1273 |
1269 \begin{dartCode} | 1274 \begin{dartCode} |
1270 class A \{ | 1275 class A \{ |
1271 int x; | 1276 int x; |
1272 A([this.x]); | 1277 A([this.x]); |
1273 \} | 1278 \} |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1403 but the actual call always happens after all initializers have been processed. | 1408 but the actual call always happens after all initializers have been processed. |
1404 It is not equivalent to moving the super call to the end of the initializer list | 1409 It is not equivalent to moving the super call to the end of the initializer list |
1405 because the argument expressions may have visible side effects | 1410 because the argument expressions may have visible side effects |
1406 which must happen in the order the expressions occur in the program text. | 1411 which must happen in the order the expressions occur in the program text. |
1407 } | 1412 } |
1408 | 1413 |
1409 \LMHash{} | 1414 \LMHash{} |
1410 After the superinitializer has completed, the body of $k$ is executed in a scope where \THIS{} is bound to $i$. | 1415 After the superinitializer has completed, the body of $k$ is executed in a scope where \THIS{} is bound to $i$. |
1411 | 1416 |
1412 \rationale{ | 1417 \rationale{ |
1413 This process ensures that no uninitialized final field is ever seen by code. Not e that \THIS{} is not in scope on the right hand side of an initializer (see \re f{this}) so no instance method can execute during initialization: an instance me thod cannot be directly invoked, nor can \THIS{} be passed into any other code b eing invoked in the initializer. | 1418 This process ensures that no uninitialized final instance variable is ever seen by code. |
1419 Note that \THIS{} is not in scope on the right hand side of an initializer (see \ref{this}) so no instance method can execute during initialization: | |
1420 an instance method cannot be directly invoked, nor can \THIS{} be passed into an y other code being invoked in the initializer. | |
1414 } | 1421 } |
1415 | 1422 |
1416 \LMHash{} | 1423 \LMHash{} |
1417 During the execution of a generative constructor to initialize an instance $i$, | 1424 During the execution of a generative constructor to initialize an instance $i$, |
1418 execution of an initializer of the form \code{\THIS{}.$v$ = $e$} | 1425 execution of an initializer of the form \code{\THIS{}.$v$ = $e$} |
1419 proceeds as follows: | 1426 proceeds as follows: |
1420 | 1427 |
1421 \LMHash{} | 1428 \LMHash{} |
1422 First, the expression $e$ is evaluated to an object $o$. Then, the instance vari able $v$ of $i$ is bound to $o$, unless $v$ is a final variable that has already been initialized, in which case a runtime error occurs. In checked mode, it is a dynamic type error if $o$ is not \NULL{} and the interface of the class of $o$ is not a subtype of the actual type of the field $v$. | 1429 First, the expression $e$ is evaluated to an object $o$. |
1430 Then, the instance variable $v$ of $i$ is bound to $o$, unless $v$ is a final va riable that has already been initialized, in which case a runtime error occurs. | |
Lasse Reichstein Nielsen
2017/01/09 08:55:12
This is statically detectable, so in Strong Mode w
eernst
2017/01/09 10:16:52
Agreed: We should be able to detect statically pre
| |
1431 In checked mode, it is a dynamic type error if $o$ is not \NULL{} and the interf ace of the class of $o$ is not a subtype of the actual type of the instance vari able $v$. | |
1423 | 1432 |
1424 \LMHash{} | 1433 \LMHash{} |
1425 An initializer of the form \code{$v$ = $e$} is equivalent to an initializer of t he form \code{\THIS{}.$v$ = $e$}. | 1434 An initializer of the form \code{$v$ = $e$} is equivalent to an initializer of t he form \code{\THIS{}.$v$ = $e$}. |
1426 | 1435 |
1427 \LMHash{} | 1436 \LMHash{} |
1428 Execution of a superinitializer of the form | 1437 Execution of a superinitializer of the form |
1429 | 1438 |
1430 \SUPER{}$(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$ | 1439 \SUPER{}$(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$ |
1431 | 1440 |
1432 (respectively \SUPER{}$.id(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$ | 1441 (respectively \SUPER{}$.id(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$ |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1821 \rationale { | 1830 \rationale { |
1822 It would be more attractive to give a purely local definition of inheritance, t hat depended only on the members of the direct superclass $S$. However, a class $C$ can inherit a member $m$ that is not a member of its superclass $S$. This can occur when the member $m$ is private | 1831 It would be more attractive to give a purely local definition of inheritance, t hat depended only on the members of the direct superclass $S$. However, a class $C$ can inherit a member $m$ that is not a member of its superclass $S$. This can occur when the member $m$ is private |
1823 to the library $L_1$ of $C$, whereas $S$ comes from a different library $L_2$, b ut | 1832 to the library $L_1$ of $C$, whereas $S$ comes from a different library $L_2$, b ut |
1824 the superclass chain of $S$ includes a class declared in $L_1$. | 1833 the superclass chain of $S$ includes a class declared in $L_1$. |
1825 } | 1834 } |
1826 | 1835 |
1827 \LMHash{} | 1836 \LMHash{} |
1828 A class may override instance members that would otherwise have been inherited f rom its superclass. | 1837 A class may override instance members that would otherwise have been inherited f rom its superclass. |
1829 | 1838 |
1830 \LMHash{} | 1839 \LMHash{} |
1831 Let $C = S_0$ be a class declared in library $L$, and let $\{S_1 \ldots S_k\}$ b e the set of all superclasses of $C$, where $S_i$ is the superclass of $S_{i-1}$ for $i \in 1 .. k$. Let $C$ declare a member $m$, and let $m^\prime$ be a memb er of $S_j, j \in 1 .. k$, that has the same name as $m$, such that $m^\prime$ is accessible to $L$. Then $m$ overrides $m^\prime$ if $m^\prime$ is not alrea dy overridden by a member of at least one of $S_1 \ldots S_{j-1}$ and neither $m $ nor $m^\prime$ are fields. | 1840 Let $C = S_0$ be a class declared in library $L$, and let $\{S_1 \ldots S_k\}$ b e the set of all superclasses of $C$, where $S_i$ is the superclass of $S_{i-1}$ for $i \in 1 .. k$. |
1841 Let $C$ declare a member $m$, and let $m^\prime$ be a member of $S_j, j \in 1 .. k$, that has the same name as $m$, such that $m^\prime$ is accessible to $L$ . | |
1842 Then $m$ overrides $m^\prime$ if $m^\prime$ is not already overridden by a membe r of at least one of $S_1 \ldots S_{j-1}$ and neither $m$ nor $m^\prime$ are ins tance variables. | |
Lasse Reichstein Nielsen
2017/01/09 08:55:11
We are still being inconsistent. Fields are not re
eernst
2017/01/09 10:16:52
Acknowledged.
| |
1832 | 1843 |
1833 %Let $C$ be a class declared in library $L$, with superclass $S$ and let $C$ dec lare an instance member $m$, and assume $S$ declares an instance member $m^\pri me$ with the same name as $m$. Then $m$ {\em overrides} $m^\prime$ iff $m^\prime $ is accessible (\ref{privacy}) to $L$, $m$ has the same name as $m^\prime$ an d neither $m$ nor $m^\prime$ are fields. | 1844 %Let $C$ be a class declared in library $L$, with superclass $S$ and let $C$ dec lare an instance member $m$, and assume $S$ declares an instance member $m^\pri me$ with the same name as $m$. Then $m$ {\em overrides} $m^\prime$ iff $m^\prime $ is accessible (\ref{privacy}) to $L$, $m$ has the same name as $m^\prime$ an d neither $m$ nor $m^\prime$ are fields. |
1834 | 1845 |
1835 \commentary{Fields never override each other. The getters and setters induced by fields do.} | 1846 \commentary{Instance variables never override each other. The getters and setter s induced by instance variables do.} |
1836 | 1847 |
1837 \rationale{Again, a local definition of overriding would be preferable, but fail s to account for library privacy. | 1848 \rationale{Again, a local definition of overriding would be preferable, but fail s to account for library privacy. |
1838 } | 1849 } |
1839 | 1850 |
1840 \LMHash{} | 1851 \LMHash{} |
1841 Whether an override is legal or not is described elsewhere in this specification (see \ref{instanceMethods}, \ref{getters} and \ref{setters}). | 1852 Whether an override is legal or not is described elsewhere in this specification (see \ref{instanceMethods}, \ref{getters} and \ref{setters}). |
1842 | 1853 |
1843 \commentary{For example getters may not legally override methods and vice versa. Setters never override methods or getters, and vice versa, because their names always differ. | 1854 \commentary{For example getters may not legally override methods and vice versa. Setters never override methods or getters, and vice versa, because their names always differ. |
1844 } | 1855 } |
1845 | 1856 |
1846 \rationale{ | 1857 \rationale{ |
1847 It is nevertheless convenient to define the override relation between members in this way, so that we can concisely describe the illegal cases. | 1858 It is nevertheless convenient to define the override relation between members in this way, so that we can concisely describe the illegal cases. |
1848 } | 1859 } |
1849 | 1860 |
1850 \commentary{ | 1861 \commentary{ |
1851 Note that instance variables do not participate in the override relation, but th e getters and setters they induce do. Also, getters don't override setters and v ice versa. Finally, static members never override anything. | 1862 Note that instance variables do not participate in the override relation, but th e getters and setters they induce do. Also, getters don't override setters and v ice versa. Finally, static members never override anything. |
1852 } | 1863 } |
1853 | 1864 |
1854 \LMHash{} | 1865 \LMHash{} |
1855 It is a static warning if a non-abstract class inherits an abstract method. | 1866 It is a static warning if a non-abstract class inherits an abstract method. |
1856 | 1867 |
1857 \commentary { | 1868 \commentary { |
1858 For convenience, here is a summary of the relevant rules. Remember that this is not normative. The controlling language is in the relevant sections of the speci fication. | 1869 For convenience, here is a summary of the relevant rules. Remember that this is not normative. The controlling language is in the relevant sections of the speci fication. |
1859 | 1870 |
1860 \begin{enumerate} | 1871 \begin{enumerate} |
1861 | 1872 |
1862 \item There is only one namespace for getters, setters, methods and constructors (\ref{scoping}). A field $f$ introduces a getter $f$ and a non-final field $f$ also introduces a setter $f=$ (\ref{instanceVariables}, \ref{staticVariables}). When we speak of members here, we mean accessible fields, getters, setters and m ethods (\ref{classes}). | 1873 \item There is only one namespace for getters, setters, methods and constructors (\ref{scoping}). |
1874 An instance or static variable $f$ introduces a getter $f$ and a non-final ins tance or static variable $f$ also introduces a setter $f=$ (\ref{instanceVariabl es}, \ref{staticVariables}). | |
1875 When we speak of members here, we mean accessible instance or static variables , getters, setters, and methods (\ref{classes}). | |
Lasse Reichstein Nielsen
2017/01/09 08:55:12
Yep, inconsistent! We do "member lookup" elsewhere
eernst
2017/01/09 10:16:52
Acknowledged.
| |
1863 \item You cannot have two members with the same name in the same class - be the y declared or inherited (\ref{scoping}, \ref{classes}). | 1876 \item You cannot have two members with the same name in the same class - be the y declared or inherited (\ref{scoping}, \ref{classes}). |
1864 \item Static members are never inherited. | 1877 \item Static members are never inherited. |
1865 \item It is a warning if you have an static member named $m$ in your class or a ny superclass (even though it is not inherited) and an instance member of the s ame name (\ref{instanceMethods}, \ref{getters}, \ref{setters}). | 1878 \item It is a warning if you have an static member named $m$ in your class or a ny superclass (even though it is not inherited) and an instance member of the s ame name (\ref{instanceMethods}, \ref{getters}, \ref{setters}). |
1866 \item It is a warning if you have a static setter $v=$, and an instance member $ v$ (\ref{setters}). | 1879 \item It is a warning if you have a static setter $v=$, and an instance member $ v$ (\ref{setters}). |
1867 \item It is a warning if you have a static getter $v$ and an instance setter $v= $ (\ref{getters}). | 1880 \item It is a warning if you have a static getter $v$ and an instance setter $v= $ (\ref{getters}). |
1868 \item If you define an instance member named $m$, and your superclass has an in stance member of the same name, they override each other. This may or may not be legal. | 1881 \item If you define an instance member named $m$, and your superclass has an in stance member of the same name, they override each other. This may or may not be legal. |
1869 \item \label{typeSigAssignable} | 1882 \item \label{typeSigAssignable} |
1870 If two members override each other, it is a static warning if their type signatu res are not assignable to each other (\ref{instanceMethods}, \ref{getters}, \ref {setters}) (and since these are function types, this means the same as "subtype s of each other"). | 1883 If two members override each other, it is a static warning if their type signatu res are not assignable to each other (\ref{instanceMethods}, \ref{getters}, \ref {setters}) (and since these are function types, this means the same as "subtype s of each other"). |
1871 \item \label{requiredParams} | 1884 \item \label{requiredParams} |
1872 If two members override each other, it is a static warning if the overriding mem ber has more required parameters than the overridden one (\ref{instanceMethods} ). | 1885 If two members override each other, it is a static warning if the overriding mem ber has more required parameters than the overridden one (\ref{instanceMethods} ). |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2105 . | 2118 . |
2106 \end{grammar} | 2119 \end{grammar} |
2107 | 2120 |
2108 \LMHash{} | 2121 \LMHash{} |
2109 A mixin application of the form \code{$S$ \WITH{} $M$;} defines a class $C$ w ith superclass $S$. | 2122 A mixin application of the form \code{$S$ \WITH{} $M$;} defines a class $C$ w ith superclass $S$. |
2110 | 2123 |
2111 \LMHash{} | 2124 \LMHash{} |
2112 A mixin application of the form \code{$S$ \WITH{} $M_1, \ldots, M_k$;} defines a class $C$ whose superclass is the application of the mixin composition (\ref {mixinComposition}) $M_{k-1} * \ldots * M_1$ to $S$. | 2125 A mixin application of the form \code{$S$ \WITH{} $M_1, \ldots, M_k$;} defines a class $C$ whose superclass is the application of the mixin composition (\ref {mixinComposition}) $M_{k-1} * \ldots * M_1$ to $S$. |
2113 | 2126 |
2114 \LMHash{} | 2127 \LMHash{} |
2115 In both cases above, $C$ declares the same instance members as $M$ (respectively , $M_k$). If any of the instance fields of $M$ (respectively, $M_k$) have initia lizers, they are executed in the scope of $M$ (respectively, $M_k$) to initializ e the corresponding fields of $C$. | 2128 In both cases above, $C$ declares the same instance members as $M$ (respectively , $M_k$). |
2129 If any of the instance variables of $M$ (respectively, $M_k$) have initializers, they are executed in the scope of $M$ (respectively, $M_k$) to initialize the c orresponding instance variables of $C$. | |
2116 | 2130 |
2117 \LMHash{} | 2131 \LMHash{} |
2118 Let $L_M$ be the library in which $M$ is declared. | 2132 Let $L_M$ be the library in which $M$ is declared. |
2119 For each generative constructor named $q_i(T_{i1}$ $ a_{i1}, \ldots , T_{ik_i}$ $ a_{ik_i}), i \in 1..n$ of $S$ that is accessible to $L_M$, $C$ has an implicit ly declared constructor named | 2133 For each generative constructor named $q_i(T_{i1}$ $ a_{i1}, \ldots , T_{ik_i}$ $ a_{ik_i}), i \in 1..n$ of $S$ that is accessible to $L_M$, $C$ has an implicit ly declared constructor named |
2120 $q'_i = [C/S]q_i$ of the form | 2134 $q'_i = [C/S]q_i$ of the form |
2121 | 2135 |
2122 $q'_i(a_{i1}, \ldots , a_{ik_i}):\SUPER(a_{i1}, \ldots , a_{ik_i});$. | 2136 $q'_i(a_{i1}, \ldots , a_{ik_i}):\SUPER(a_{i1}, \ldots , a_{ik_i});$. |
2123 | 2137 |
2124 %super.id | 2138 %super.id |
2125 | 2139 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2373 | 2387 |
2374 \rationale{ | 2388 \rationale{ |
2375 It is important that no runtime overhead be incurred by the introduction of meta data that is not actually used. Because metadata only involves constants, the ti me at which it is computed is irrelevant so that implementations may skip the me tadata during ordinary parsing and execution and evaluate it lazily. | 2389 It is important that no runtime overhead be incurred by the introduction of meta data that is not actually used. Because metadata only involves constants, the ti me at which it is computed is irrelevant so that implementations may skip the me tadata during ordinary parsing and execution and evaluate it lazily. |
2376 } | 2390 } |
2377 | 2391 |
2378 \commentary{ | 2392 \commentary{ |
2379 It is possible to associate metadata with constructs that may not be accessible via reflection, such as local variables (though it is conceivable that in the fu ture, richer reflective libraries might provide access to these as well). This is not as useless as it might seem. As noted above, the data can be retrieved st atically if source code is available. | 2393 It is possible to associate metadata with constructs that may not be accessible via reflection, such as local variables (though it is conceivable that in the fu ture, richer reflective libraries might provide access to these as well). This is not as useless as it might seem. As noted above, the data can be retrieved st atically if source code is available. |
2380 } | 2394 } |
2381 | 2395 |
2382 \LMHash{} | 2396 \LMHash{} |
2383 Metadata can appear before a library, part header, class, typedef, type paramete r, constructor, factory, function, field, parameter, or variable declaration and before an import, export or part directive. | 2397 Metadata can appear before a library, part header, class, typedef, type paramete r, constructor, factory, function, parameter, or variable declaration and before an import, export or part directive. |
2384 | 2398 |
2385 \LMHash{} | 2399 \LMHash{} |
2386 The constant expression given in an annotation is type checked and evaluated in the scope surrounding the declaration being annotated. | 2400 The constant expression given in an annotation is type checked and evaluated in the scope surrounding the declaration being annotated. |
2387 | 2401 |
2388 | 2402 |
2389 \section{Expressions} | 2403 \section{Expressions} |
2390 \LMLabel{expressions} | 2404 \LMLabel{expressions} |
2391 | 2405 |
2392 \LMHash{} | 2406 \LMHash{} |
2393 \label{evaluation} | 2407 \label{evaluation} |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2455 \item $c_1$ and $c_2$ are instances of \cd{double} and one of the following holds: | 2469 \item $c_1$ and $c_2$ are instances of \cd{double} and one of the following holds: |
2456 \begin{itemize} | 2470 \begin{itemize} |
2457 \item $c_1$ and $c_2$ are non-zero and \code{$c_1$ == $c_2$}. | 2471 \item $c_1$ and $c_2$ are non-zero and \code{$c_1$ == $c_2$}. |
2458 \item Both $c_1$ and $c_2$ are $+0.0$. | 2472 \item Both $c_1$ and $c_2$ are $+0.0$. |
2459 \item Both $c_1$ and $c_2$ are $-0.0$. | 2473 \item Both $c_1$ and $c_2$ are $-0.0$. |
2460 \item Both $c_1$ and $c_2$ represent a NaN value with the same underlying bit pattern. | 2474 \item Both $c_1$ and $c_2$ represent a NaN value with the same underlying bit pattern. |
2461 \end{itemize} | 2475 \end{itemize} |
2462 OR | 2476 OR |
2463 \item $c_1$ and $c_2$ are constant lists that are defined to be identical in th e specification of literal list expressions (\ref{lists}), OR | 2477 \item $c_1$ and $c_2$ are constant lists that are defined to be identical in th e specification of literal list expressions (\ref{lists}), OR |
2464 \item $c_1$ and $c_2$ are constant maps that are defined to be identical in the specification of literal map expressions (\ref{maps}), OR | 2478 \item $c_1$ and $c_2$ are constant maps that are defined to be identical in the specification of literal map expressions (\ref{maps}), OR |
2465 \item $c_1$ and $c_2$ are constant objects of the same class $C$ and each membe r field of $c_1$ is identical to the corresponding field of $c_2$. OR | 2479 \item $c_1$ and $c_2$ are constant objects of the same class $C$ and each insta nce variable of $c_1$ is identical to the corresponding instance variable of $c_ 2$. OR |
Lasse Reichstein Nielsen
2017/01/09 08:55:12
... and the value of each instance variable of ...
eernst
2017/01/09 10:16:52
Indeed, done!
| |
2466 \item $c_1$ and $c_2$ are the same object. | 2480 \item $c_1$ and $c_2$ are the same object. |
2467 \end{itemize} | 2481 \end{itemize} |
2468 | 2482 |
2469 \commentary{ | 2483 \commentary{ |
2470 The definition of \cd{identity} for doubles differs from that of equality in tha t a NaN is identical to itself, and that negative and positive zero are distinct . | 2484 The definition of \cd{identity} for doubles differs from that of equality in tha t a NaN is identical to itself, and that negative and positive zero are distinct . |
2471 } | 2485 } |
2472 | 2486 |
2473 \rationale{ | 2487 \rationale{ |
2474 The definition of equality for doubles is dictated by the IEEE 754 standard, whi ch posits that NaNs do not obey the law of reflexivity. Given that hardware imp lements these rules, it is necessary to support them for reasons of efficiency. | 2488 The definition of equality for doubles is dictated by the IEEE 754 standard, whi ch posits that NaNs do not obey the law of reflexivity. Given that hardware imp lements these rules, it is necessary to support them for reasons of efficiency. |
2475 | 2489 |
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3528 | 3542 |
3529 in which case let $i$ be the result of evaluating | 3543 in which case let $i$ be the result of evaluating |
3530 | 3544 |
3531 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. | 3545 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. |
3532 | 3546 |
3533 \LMHash{} | 3547 \LMHash{} |
3534 Then: | 3548 Then: |
3535 \begin{itemize} | 3549 \begin{itemize} |
3536 \item If during execution of the program, a constant object expression has alrea dy evaluated to an instance $j$ of class $R$ with type arguments $V_i, 1 \le i \ le m$, then: | 3550 \item If during execution of the program, a constant object expression has alrea dy evaluated to an instance $j$ of class $R$ with type arguments $V_i, 1 \le i \ le m$, then: |
3537 \begin{itemize} | 3551 \begin{itemize} |
3538 \item For each instance variable $f$ of $i$, let $v_{if}$ be the value of the fi eld $f$ in $i$, and let $v_{jf}$ be the value of the field $f$ in $j$. If \code {identical($v_{if}$, $v_{jf}$)} for all fields $f$ in $i$, then the value of $e$ is $j$, otherwise the value of $e$ is $i$. | 3552 \item For each instance variable $f$ of $i$, let $v_{if}$ be the value of the in stance variable $f$ in $i$, and let $v_{jf}$ be the value of the instance variab le $f$ in $j$. |
3553 If \code{identical($v_{if}$, $v_{jf}$)} for all instance variables $f$ in $i$ then the value of $e$ is $j$, otherwise the value of $e$ is $i$. | |
3539 \end{itemize} | 3554 \end{itemize} |
3540 \item Otherwise the value of $e$ is $i$. | 3555 \item Otherwise the value of $e$ is $i$. |
3541 \end{itemize} | 3556 \end{itemize} |
3542 | 3557 |
3543 \commentary{ | 3558 \commentary{ |
3544 In other words, constant objects are canonicalized. In order to determine if an object is actually new, one has to compute it; then it can be compared to any c ached instances. If an equivalent object exists in the cache, we throw away the newly created object and use the cached one. Objects are equivalent if they have identical fields and identical type arguments. Since the constructor cannot ind uce any side effects, the execution of the constructor is unobservable. The con structor need only be executed once per call site, at compile-time. | 3559 In other words, constant objects are canonicalized. |
3560 In order to determine if an object is actually new, one has to compute it; then it can be compared to any cached instances. | |
3561 If an equivalent object exists in the cache, we throw away the newly created obj ect and use the cached one. | |
3562 Objects are equivalent if they have identical type arguments and identical insta nce variables. | |
3563 Since the constructor cannot induce any side effects, the execution of the const ructor is unobservable. | |
3564 The constructor need only be executed once per call site, at compile-time. | |
3545 } | 3565 } |
3546 | 3566 |
3547 \LMHash{} | 3567 \LMHash{} |
3548 The static type of a constant object expression of either the form | 3568 The static type of a constant object expression of either the form |
3549 | 3569 |
3550 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ | 3570 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ |
3551 | 3571 |
3552 or the form | 3572 or the form |
3553 | 3573 |
3554 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ | 3574 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ |
(...skipping 1506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5061 Evaluation of a postfix expression $e$ of the form \code{$v$++}, where $v$ is an identifier, proceeds as follows: | 5081 Evaluation of a postfix expression $e$ of the form \code{$v$++}, where $v$ is an identifier, proceeds as follows: |
5062 | 5082 |
5063 \LMHash{} | 5083 \LMHash{} |
5064 Evaluate $v$ to an object $r$ and let $y$ be a fresh variable bound to $r$. | 5084 Evaluate $v$ to an object $r$ and let $y$ be a fresh variable bound to $r$. |
5065 Evaluate \code{$v$ = $y$ + 1}. | 5085 Evaluate \code{$v$ = $y$ + 1}. |
5066 Then $e$ evaluates to $r$. | 5086 Then $e$ evaluates to $r$. |
5067 | 5087 |
5068 \LMHash{} | 5088 \LMHash{} |
5069 The static type of such an expression is the static type of $v$. | 5089 The static type of such an expression is the static type of $v$. |
5070 | 5090 |
5071 | 5091 \rationale{ |
5072 \rationale{The above ensures that if $v$ is a field, the getter gets called exac tly once. Likewise in the cases below. | 5092 The above ensures that if $v$ is a variable, the getter gets called exactly once . |
5093 Likewise in the cases below. | |
5073 } | 5094 } |
5074 | 5095 |
5075 \LMHash{} | 5096 \LMHash{} |
5076 Evaluation of a postfix expression $e$ of the form \code{$C$.$v$++} | 5097 Evaluation of a postfix expression $e$ of the form \code{$C$.$v$++} |
5077 proceeds as follows: | 5098 proceeds as follows: |
5078 | 5099 |
5079 \LMHash{} | 5100 \LMHash{} |
5080 Evaluate \code{$C$.$v$} to a value $r$ | 5101 Evaluate \code{$C$.$v$} to a value $r$ |
5081 and let $y$ be a fresh variable bound to $r$. | 5102 and let $y$ be a fresh variable bound to $r$. |
5082 Evaluate \code{$C$.$v$ = $y$ + 1}. | 5103 Evaluate \code{$C$.$v$ = $y$ + 1}. |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5427 \LMHash{} | 5448 \LMHash{} |
5428 The is-expression \code{$e$ \IS{}! $T$} is equivalent to \code{!($e$ \IS{} $T$)} . | 5449 The is-expression \code{$e$ \IS{}! $T$} is equivalent to \code{!($e$ \IS{} $T$)} . |
5429 | 5450 |
5430 % Add flow dependent types | 5451 % Add flow dependent types |
5431 | 5452 |
5432 | 5453 |
5433 \LMHash{} | 5454 \LMHash{} |
5434 Let $v$ be a local variable or a formal parameter. An is-expression of the form \code{$v$ \IS{} $T$} shows that $v$ has type $T$ iff $T$ is more specific than the type $S$ of the expression $v$ and both $T \ne \DYNAMIC{}$ and $S \ne \DYN AMIC{}$. | 5455 Let $v$ be a local variable or a formal parameter. An is-expression of the form \code{$v$ \IS{} $T$} shows that $v$ has type $T$ iff $T$ is more specific than the type $S$ of the expression $v$ and both $T \ne \DYNAMIC{}$ and $S \ne \DYN AMIC{}$. |
5435 | 5456 |
5436 \rationale{ | 5457 \rationale{ |
5437 The motivation for the ``shows that v has type T" relation is to reduce spurious warnings thereby enabling a more natural coding style. The rules in the current specification are deliberately kept simple. It would be upwardly compatible to refine these rules in the future; such a refinement would accept more code witho ut warning, but not reject any code now warning-free. | 5458 The motivation for the ``shows that v has type T" relation is to reduce spurious warnings thereby enabling a more natural coding style. |
5459 The rules in the current specification are deliberately kept simple. | |
5460 It would be upwardly compatible to refine these rules in the future; such a refi nement would accept more code without warning, but not reject any code now warni ng-free. | |
5438 | 5461 |
5439 The rule only applies to locals and parameters, as fields could be modified via side-effecting functions or methods that are not accessible to a local analysis. | 5462 The rule only applies to locals and parameters, as instance or static variables could be modified via side-effecting functions or methods that are not accessibl e to a local analysis. |
5440 | 5463 |
5441 It is pointless to deduce a weaker type than what is already known. Furthermore, this would lead to a situation where multiple types are associated with a varia ble at a given point, which complicates the specification. Hence the requirement that $T << S$ (we use $<<$ rather than subtyping because subtyping is not a par tial order). | 5464 It is pointless to deduce a weaker type than what is already known. |
5465 Furthermore, this would lead to a situation where multiple types are associated with a variable at a given point, which complicates the specification. | |
5466 Hence the requirement that $T << S$ (we use $<<$ rather than subtyping because s ubtyping is not a partial order). | |
5442 | 5467 |
5443 We do not want to refine the type of a variable of type \DYNAMIC{}, as this coul d lead to more warnings rather than less. The opposite requirement, that $T \ne \DYNAMIC{}$ is a safeguard lest $S$ ever be $\bot$. | 5468 We do not want to refine the type of a variable of type \DYNAMIC{}, as this coul d lead to more warnings rather than fewer. |
5469 The opposite requirement, that $T \ne \DYNAMIC{}$ is a safeguard lest $S$ ever b e $\bot$. | |
5444 } | 5470 } |
5445 | 5471 |
5446 \LMHash{} | 5472 \LMHash{} |
5447 The static type of an is-expression is \code{bool}. | 5473 The static type of an is-expression is \code{bool}. |
5448 | 5474 |
5449 | 5475 |
5450 \subsection{ Type Cast} | 5476 \subsection{ Type Cast} |
5451 \LMLabel{typeCast} | 5477 \LMLabel{typeCast} |
5452 | 5478 |
5453 \LMHash{} | 5479 \LMHash{} |
(...skipping 2552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8006 | 8032 |
8007 The invariant that each normative paragraph is associated with a line | 8033 The invariant that each normative paragraph is associated with a line |
8008 containing the text \LMHash{} should be maintained. Extra occurrences | 8034 containing the text \LMHash{} should be maintained. Extra occurrences |
8009 of \LMHash{} can be added if needed, e.g., in order to make | 8035 of \LMHash{} can be added if needed, e.g., in order to make |
8010 individual \item{}s in itemized lists addressable. Each \LM.. command | 8036 individual \item{}s in itemized lists addressable. Each \LM.. command |
8011 must occur on a separate line. \LMHash{} must occur immediately | 8037 must occur on a separate line. \LMHash{} must occur immediately |
8012 before the associated paragraph, and \LMLabel must occur immediately | 8038 before the associated paragraph, and \LMLabel must occur immediately |
8013 after the associated \section{}, \subsection{} etc. | 8039 after the associated \section{}, \subsection{} etc. |
8014 | 8040 |
8015 ---------------------------------------------------------------------- | 8041 ---------------------------------------------------------------------- |
OLD | NEW |