Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: docs/language/dartLangSpec.tex

Issue 646003002: Introduced hash valued location markers in the spec (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revised after 2nd review Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « docs/language/dart.sty ('k') | tests/standalone/io/addlatexhash_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 \documentclass{article} 1 \documentclass{article}
2 \usepackage{epsfig} 2 \usepackage{epsfig}
3 \usepackage{color}
3 \usepackage{dart} 4 \usepackage{dart}
4 \usepackage{bnf} 5 \usepackage{bnf}
5 \usepackage{hyperref} 6 \usepackage{hyperref}
7 \usepackage{lmodern}
6 \newcommand{\code}[1]{{\sf #1}} 8 \newcommand{\code}[1]{{\sf #1}}
7 \title{Dart Programming Language Specification \\ 9 \title{Dart Programming Language Specification \\
8 {\large Version 1.6}} 10 {\large Version 1.6}}
9 %\author{The Dart Team} 11 %\author{The Dart Team}
12
13 % For information about Location Markers (and in particular the
14 % commands \LMHash and \LMLabel), see the long comment at the
15 % end of this file.
16
10 \begin{document} 17 \begin{document}
11 \maketitle 18 \maketitle
12 \tableofcontents 19 \tableofcontents
13 20
14 21
15 \newpage 22 \newpage
16 23
17 \pagestyle{myheadings} 24 \pagestyle{myheadings}
18 \markright{Dart Programming Language Specification} 25 \markright{Dart Programming Language Specification}
19 26
20 % begin Ecma boilerplate 27 % begin Ecma boilerplate
21 \section{Scope} 28 \section{Scope}
22 \label{ecmaScope} 29 \LMLabel{ecmaScope}
23 30
31 \LMHash{}
24 This Ecma standard specifies the syntax and semantics of the Dart programming la nguage. It does not specify the APIs of the Dart libraries except where those l ibrary elements are essential to the correct functioning of the language itself (e.g., the existence of class \cd{Object} with methods such as \cd{noSuchMethod} , \cd{runtimeType}). 32 This Ecma standard specifies the syntax and semantics of the Dart programming la nguage. It does not specify the APIs of the Dart libraries except where those l ibrary elements are essential to the correct functioning of the language itself (e.g., the existence of class \cd{Object} with methods such as \cd{noSuchMethod} , \cd{runtimeType}).
25 33
26 \section{Conformance} 34 \section{Conformance}
27 \label{ecmaConformance} 35 \LMLabel{ecmaConformance}
28 36
37 \LMHash{}
29 A conforming implementation of the Dart programming language must provide and s upport all the APIs (libraries, types, functions, getters, setters, whether top -level, static, instance or local) mandated in this specification. 38 A conforming implementation of the Dart programming language must provide and s upport all the APIs (libraries, types, functions, getters, setters, whether top -level, static, instance or local) mandated in this specification.
30 39
40 \LMHash{}
31 A conforming implementation is permitted to provide additional APIs, but not add itional syntax. 41 A conforming implementation is permitted to provide additional APIs, but not add itional syntax.
32 42
33 % A claim of conformance with this Ecma Standard shall specify? 43 % A claim of conformance with this Ecma Standard shall specify?
34 44
35 \section{Normative References} 45 \section{Normative References}
36 \label{ecmaNormativeReferences} 46 \LMLabel{ecmaNormativeReferences}
37 47
48 \LMHash{}
38 The following referenced documents are indispensable for the application of this document. For dated references, only the edition cited applies. For undated ref erences, the latest edition of the referenced document (including any amendments ) applies. 49 The following referenced documents are indispensable for the application of this document. For dated references, only the edition cited applies. For undated ref erences, the latest edition of the referenced document (including any amendments ) applies.
39 50
40 \begin{enumerate} 51 \begin{enumerate}
41 \item 52 \item
42 The Unicode Standard, Version 5.0, as amended by Unicode 5.1.0, or successor. 53 The Unicode Standard, Version 5.0, as amended by Unicode 5.1.0, or successor.
43 \item 54 \item
44 Dart API Reference, https://api.dartlang.org/ 55 Dart API Reference, https://api.dartlang.org/
45 \end{enumerate} 56 \end{enumerate}
46 57
47 58
48 \section{Terms and Definitions} 59 \section{Terms and Definitions}
49 \label{ecmaTermsAndDefinitions} 60 \LMLabel{ecmaTermsAndDefinitions}
50 61
62 \LMHash{}
51 Terms and definitions used in this specification are given in the body of the sp ecification proper. Such terms are highlighted in italics when they are introduc ed, e.g., `we use the term {\em verbosity} to refer to the property of excess ve rbiage'. 63 Terms and definitions used in this specification are given in the body of the sp ecification proper. Such terms are highlighted in italics when they are introduc ed, e.g., `we use the term {\em verbosity} to refer to the property of excess ve rbiage'.
52 % End Ecma Boilerplate 64 % End Ecma Boilerplate
53 65
54 66
55 \section{Notation} 67 \section{Notation}
56 \label{notation} 68 \LMLabel{notation}
57 69
70 \LMHash{}
58 We distinguish between normative and non-normative text. Normative text defines the rules of Dart. It is given in this font. At this time, non-normative text in cludes: 71 We distinguish between normative and non-normative text. Normative text defines the rules of Dart. It is given in this font. At this time, non-normative text in cludes:
59 \begin{itemize} 72 \begin{itemize}
60 \item[Rationale] Discussion of the motivation for language design decisions appe ars in italics. \rationale{Distinguishing normative from non-normative helps cla rify what part of the text is binding and what part is merely expository.} 73 \item[Rationale] Discussion of the motivation for language design decisions appe ars in italics. \rationale{Distinguishing normative from non-normative helps cla rify what part of the text is binding and what part is merely expository.}
61 \item[Commentary] Comments such as ``\commentary{The careful reader will have n oticed that the name Dart has four characters}'' serve to illustrate or clarify the specification, but are redundant with the normative text. \commentary{The d ifference between commentary and rationale can be subtle.} \rationale{ Commentar y is more general than rationale, and may include illustrative examples or clari fications. } 74 \item[Commentary] Comments such as ``\commentary{The careful reader will have n oticed that the name Dart has four characters}'' serve to illustrate or clarify the specification, but are redundant with the normative text. \commentary{The d ifference between commentary and rationale can be subtle.} \rationale{ Commentar y is more general than rationale, and may include illustrative examples or clari fications. }
62 \item[Open questions] (\Q{in this font}). Open questions are points that are uns ettled in the mind of the author(s) of the specification; expect them (the quest ions, not the authors; precision is important in a specification) to be eliminat ed in the final specification. \Q{Should the text at the end of the previous bul let be rationale or commentary?} 75 \item[Open questions] (\Q{in this font}). Open questions are points that are uns ettled in the mind of the author(s) of the specification; expect them (the quest ions, not the authors; precision is important in a specification) to be eliminat ed in the final specification. \Q{Should the text at the end of the previous bul let be rationale or commentary?}
63 \end{itemize} 76 \end{itemize}
64 77
78 \LMHash{}
65 Reserved words and built-in identifiers (\ref{identifierReference}) appear in { \bf bold}. 79 Reserved words and built-in identifiers (\ref{identifierReference}) appear in { \bf bold}.
66 80
67 \commentary{ 81 \commentary{
68 Examples would be \SWITCH{} or \CLASS{}. 82 Examples would be \SWITCH{} or \CLASS{}.
69 } 83 }
70 84
71 85
86 \LMHash{}
72 Grammar productions are given in a common variant of EBNF. The left hand side o f a production ends with a colon. On the right hand side, alternation is repres ented by vertical bars, and sequencing by spacing. As in PEGs, alternation give s priority to the left. Optional elements of a production are suffixed by a ques tion mark like so: \code{anElephant?}. Appending a star to an element of a prod uction means it may be repeated zero or more times. Appending a plus sign to a production means it occurs one or more times. Parentheses are used for grouping. Negation is represented by prefixing an element of a production with a tilde. Negation is similar to the not combinator of PEGs, but it consumes input if it m atches. In the context of a lexical production it consumes a single character if there is one; otherwise, a single token if there is one. 87 Grammar productions are given in a common variant of EBNF. The left hand side o f a production ends with a colon. On the right hand side, alternation is repres ented by vertical bars, and sequencing by spacing. As in PEGs, alternation give s priority to the left. Optional elements of a production are suffixed by a ques tion mark like so: \code{anElephant?}. Appending a star to an element of a prod uction means it may be repeated zero or more times. Appending a plus sign to a production means it occurs one or more times. Parentheses are used for grouping. Negation is represented by prefixing an element of a production with a tilde. Negation is similar to the not combinator of PEGs, but it consumes input if it m atches. In the context of a lexical production it consumes a single character if there is one; otherwise, a single token if there is one.
73 88
74 \commentary{ An example would be:} 89 \commentary{ An example would be:}
75 90
76 \begin{grammar} 91 \begin{grammar}
77 {\sf 92 {\sf
78 {\bf AProduction:}AnAlternative; 93 {\bf AProduction:}AnAlternative;
79 AnotherAlternative; 94 AnotherAlternative;
80 OneThing After Another; 95 OneThing After Another;
81 ZeroOrMoreThings*; 96 ZeroOrMoreThings*;
82 OneOrMoreThings+; 97 OneOrMoreThings+;
83 AnOptionalThing?; 98 AnOptionalThing?;
84 (Some Grouped Things); 99 (Some Grouped Things);
85 \~{}NotAThing; 100 \~{}NotAThing;
86 A\_LEXICAL\_THING 101 A\_LEXICAL\_THING
87 . 102 .
88 } 103 }
89 \end{grammar} 104 \end{grammar}
90 105
91 % need a match anything or a production that does that, so we can correct bugs w rt use 106 % need a match anything or a production that does that, so we can correct bugs w rt use
92 % ~. ~ does not actually parse stuff - it just looks ahead and checks. To get th e effect of 107 % ~. ~ does not actually parse stuff - it just looks ahead and checks. To get th e effect of
93 % parsing anything but X, one needs ~X ANYTHING, not just ~X. There are bugs in the 108 % parsing anything but X, one needs ~X ANYTHING, not just ~X. There are bugs in the
94 % grammar related to this. 109 % grammar related to this.
95 % The alternative is to define ~X as anything but X, or to introduce an anthingB ut(X) 110 % The alternative is to define ~X as anything but X, or to introduce an anthingB ut(X)
96 % combinator, such as !X 111 % combinator, such as !X
97 112
113 \LMHash{}
98 Both syntactic and lexical productions are represented this way. Lexical product ions are distinguished by their names. The names of lexical productions consist exclusively of upper case characters and underscores. As always, within grammat ical productions, whitespace and comments between elements of the production are implicitly ignored unless stated otherwise. 114 Both syntactic and lexical productions are represented this way. Lexical product ions are distinguished by their names. The names of lexical productions consist exclusively of upper case characters and underscores. As always, within grammat ical productions, whitespace and comments between elements of the production are implicitly ignored unless stated otherwise.
99 Punctuation tokens appear in quotes. 115 Punctuation tokens appear in quotes.
100 116
117 \LMHash{}
101 Productions are embedded, as much as possible, in the discussion of the construc ts they represent. 118 Productions are embedded, as much as possible, in the discussion of the construc ts they represent.
102 119
120 \LMHash{}
103 A list $x_1, \ldots, x_n$ denotes any list of $n$ elements of the form $x_i, 1 \ le i \le n$. Note that $n$ may be zero, in which case the list is empty. We use such lists extensively throughout this specification. 121 A list $x_1, \ldots, x_n$ denotes any list of $n$ elements of the form $x_i, 1 \ le i \le n$. Note that $n$ may be zero, in which case the list is empty. We use such lists extensively throughout this specification.
104 122
123 \LMHash{}
105 The notation $[x_1, \ldots, x_n/y_1, \ldots, y_n]E$ denotes a copy of $E$ in whi ch all occurrences of $y_i, 1 \le i \le n$ have been replaced with $x_i$. 124 The notation $[x_1, \ldots, x_n/y_1, \ldots, y_n]E$ denotes a copy of $E$ in whi ch all occurrences of $y_i, 1 \le i \le n$ have been replaced with $x_i$.
106 125
126 \LMHash{}
107 We sometimes abuse list or map literal syntax, writing $[o_1, \ldots, o_n]$ (re spectively $\{k_1: o_1, \ldots, k_n: o_n\}$) where the $o_i$ and $k_i$ may be ob jects rather than expressions. The intent is to denote a list (respectively map) object whose elements are the $o_i$ (respectively, whose keys are the $k_i$ and values are the $o_i$). 127 We sometimes abuse list or map literal syntax, writing $[o_1, \ldots, o_n]$ (re spectively $\{k_1: o_1, \ldots, k_n: o_n\}$) where the $o_i$ and $k_i$ may be ob jects rather than expressions. The intent is to denote a list (respectively map) object whose elements are the $o_i$ (respectively, whose keys are the $k_i$ and values are the $o_i$).
108 128
129 \LMHash{}
109 The specifications of operators often involve statements such as $x$ $op$ $y$ is equivalent to the method invocation $x.op(y)$. Such specifications should be un derstood as a shorthand for: 130 The specifications of operators often involve statements such as $x$ $op$ $y$ is equivalent to the method invocation $x.op(y)$. Such specifications should be un derstood as a shorthand for:
110 \begin{itemize} 131 \begin{itemize}
111 \item 132 \item
112 $x$ $op$ $y$ is equivalent to the method invocation $x.op^\prime(y)$, assuming the class of $x$ actually declared a non-operator method named $op^\prime$ defin ing the same function as the operator $op$. 133 $x$ $op$ $y$ is equivalent to the method invocation $x.op^\prime(y)$, assuming the class of $x$ actually declared a non-operator method named $op^\prime$ defin ing the same function as the operator $op$.
113 \end{itemize} 134 \end{itemize}
114 135
115 \rationale{This circumlocution is required because x.op(y), where op is an oper ator, is not legal syntax. However, it is painfully verbose, and we prefer to st ate this rule once here, and use a concise and clear notation across the specifi cation. 136 \rationale{This circumlocution is required because x.op(y), where op is an oper ator, is not legal syntax. However, it is painfully verbose, and we prefer to st ate this rule once here, and use a concise and clear notation across the specifi cation.
116 } 137 }
117 138
139 \LMHash{}
118 When the specification refers to the order given in the program, it means the or der of the program source code text, scanning left-to-right and top-to-bottom. 140 When the specification refers to the order given in the program, it means the or der of the program source code text, scanning left-to-right and top-to-bottom.
119 141
142 \LMHash{}
120 References to otherwise unspecified names of program entities (such as classes o r functions) are interpreted as the names of members of the Dart core library. 143 References to otherwise unspecified names of program entities (such as classes o r functions) are interpreted as the names of members of the Dart core library.
121 144
122 \commentary{ 145 \commentary{
123 Examples would be the classes \code{Object} and \code{Type} representing the roo t of the class hierarchy and the reification of runtime types respectively. 146 Examples would be the classes \code{Object} and \code{Type} representing the roo t of the class hierarchy and the reification of runtime types respectively.
124 } 147 }
125 148
126 \section{Overview} 149 \section{Overview}
127 \label{overview} 150 \LMLabel{overview}
128 151
152 \LMHash{}
129 Dart is a class-based, single-inheritance, pure object-oriented programming lang uage. Dart is optionally typed (\ref{types}) and supports reified generics. The run-time type of every object is represented as an instance of class \code{Type} which can be obtained by calling the getter \code{runtimeType} declared in cl ass \code{Object}, the root of the Dart class hierarchy. 153 Dart is a class-based, single-inheritance, pure object-oriented programming lang uage. Dart is optionally typed (\ref{types}) and supports reified generics. The run-time type of every object is represented as an instance of class \code{Type} which can be obtained by calling the getter \code{runtimeType} declared in cl ass \code{Object}, the root of the Dart class hierarchy.
130 154
155 \LMHash{}
131 Dart programs may be statically checked. The static checker will report some vio lations of the type rules, but such violations do not abort compilation or precl ude execution. 156 Dart programs may be statically checked. The static checker will report some vio lations of the type rules, but such violations do not abort compilation or precl ude execution.
132 157
158 \LMHash{}
133 Dart programs may be executed in one of two modes: production mode or checked mo de. In production mode, static type annotations (\ref{staticTypes}) have absolut ely no effect on execution with the exception of reflection and structural type tests. 159 Dart programs may be executed in one of two modes: production mode or checked mo de. In production mode, static type annotations (\ref{staticTypes}) have absolut ely no effect on execution with the exception of reflection and structural type tests.
134 160
135 \commentary{ 161 \commentary{
136 Reflection, by definition, examines the program structure. If we provide reflect ive access to the type of a declaration, or to source code, it will inevitably p roduce results that depend on the types used in the underlying code. 162 Reflection, by definition, examines the program structure. If we provide reflect ive access to the type of a declaration, or to source code, it will inevitably p roduce results that depend on the types used in the underlying code.
137 163
138 Type tests also examine the types in a program explicitly. Nevertheless, in most cases, these will not depend on type annotations. The exceptions to this rule a re type tests involving function types. Function types are structural, and so de pend on the types declared for their parameters and on their return types. 164 Type tests also examine the types in a program explicitly. Nevertheless, in most cases, these will not depend on type annotations. The exceptions to this rule a re type tests involving function types. Function types are structural, and so de pend on the types declared for their parameters and on their return types.
139 } 165 }
140 166
167 \LMHash{}
141 In checked mode, assignments are dynamically checked, and certain violations of the type system raise exceptions at run time. 168 In checked mode, assignments are dynamically checked, and certain violations of the type system raise exceptions at run time.
142 169
143 \commentary{ 170 \commentary{
144 The coexistence between optional typing and reification is based on the followin g: 171 The coexistence between optional typing and reification is based on the followin g:
145 \begin{enumerate} 172 \begin{enumerate}
146 \item Reified type information reflects the types of objects at runtime and may always be queried by dynamic typechecking constructs (the analogs of instanceOf, casts, typecase etc. in other languages). Reified type information includes cla ss declarations, the runtime type (aka class) of an object, and type arguments t o constructors. 173 \item Reified type information reflects the types of objects at runtime and may always be queried by dynamic typechecking constructs (the analogs of instanceOf, casts, typecase etc. in other languages). Reified type information includes cla ss declarations, the runtime type (aka class) of an object, and type arguments t o constructors.
147 \item Static type annotations determine the types of variables and function decl arations (including methods and constructors). 174 \item Static type annotations determine the types of variables and function decl arations (including methods and constructors).
148 \item Production mode respects optional typing. Static type annotations do not a ffect runtime behavior. 175 \item Production mode respects optional typing. Static type annotations do not a ffect runtime behavior.
149 \item Checked mode utilizes static type annotations and dynamic type information aggressively yet selectively to provide early error detection during developmen t. 176 \item Checked mode utilizes static type annotations and dynamic type information aggressively yet selectively to provide early error detection during developmen t.
150 \end{enumerate} 177 \end{enumerate}
151 } 178 }
152 179
180 \LMHash{}
153 Dart programs are organized in a modular fashion into units called {\em librarie s} (\ref{librariesAndScripts}). Libraries are units of encapsulation and may be mutually recursive. 181 Dart programs are organized in a modular fashion into units called {\em librarie s} (\ref{librariesAndScripts}). Libraries are units of encapsulation and may be mutually recursive.
154 182
155 \commentary{However they are not first class. To get multiple copies of a libra ry running simultaneously, one needs to spawn an isolate. 183 \commentary{However they are not first class. To get multiple copies of a libra ry running simultaneously, one needs to spawn an isolate.
156 } 184 }
157 185
158 \subsection{Scoping} 186 \subsection{Scoping}
159 \label{scoping} 187 \LMLabel{scoping}
160 188
189 \LMHash{}
161 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$. 190 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$.
162 191
192 \LMHash{}
163 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. 193 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.
164 194
165 \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. 195 \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.
166 } 196 }
167 197
198 \LMHash{}
168 It is a compile-time error if there is more than one entity with the same name d eclared in the same scope. 199 It is a compile-time error if there is more than one entity with the same name d eclared in the same scope.
169 200
170 \commentary{ 201 \commentary{
171 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-. 202 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-.
172 } 203 }
173 204
205 \LMHash{}
174 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. 206 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.
175 207
176 208
209 \LMHash{}
177 If a declaration $d$ named $n$ is in the namespace induced by a scope $S$, then $d$ {\em hides} any declaration named $n$ that is available in the lexically en closing scope of $S$. 210 If a declaration $d$ named $n$ is in the namespace induced by a scope $S$, then $d$ {\em hides} any declaration named $n$ that is available in the lexically en closing scope of $S$.
178 211
179 \commentary { 212 \commentary {
180 A consequence of these rules is that it is possible to hide a type with a method or variable. 213 A consequence of these rules is that it is possible to hide a type with a method or variable.
181 Naming conventions usually prevent such abuses. Nevertheless,the following progr am is legal: 214 Naming conventions usually prevent such abuses. Nevertheless,the following progr am is legal:
182 } 215 }
183 216
184 \begin{dartCode} 217 \begin{dartCode}
185 \CLASS{} HighlyStrung \{ 218 \CLASS{} HighlyStrung \{
186 String() $=>$ "?"; 219 String() $=>$ "?";
187 \} 220 \}
188 \end{dartCode} 221 \end{dartCode}
189 222
223 \LMHash{}
190 Names may be introduced into a scope by declarations within the scope or by ot her mechanisms such as imports or inheritance. 224 Names may be introduced into a scope by declarations within the scope or by ot her mechanisms such as imports or inheritance.
191 225
192 \rationale{ 226 \rationale{
193 The interaction of lexical scoping and inheritance is a subtle one. Ultimately, the question is whether lexical scoping takes precedence over inheritance or vi ce versa. Dart chooses the former. 227 The interaction of lexical scoping and inheritance is a subtle one. Ultimately, the question is whether lexical scoping takes precedence over inheritance or vi ce versa. Dart chooses the former.
194 228
195 Allowing inherited names to take precedence over locally declared names can crea te unexpected situations as code evolves. Specifically, the behavior of code in a subclass can change without warning if a new name is introduced in a supercla ss. Consider: 229 Allowing inherited names to take precedence over locally declared names can crea te unexpected situations as code evolves. Specifically, the behavior of code in a subclass can change without warning if a new name is introduced in a supercla ss. Consider:
196 } 230 }
197 231
198 \begin{dartCode} 232 \begin{dartCode}
199 \LIBRARY{} L1; 233 \LIBRARY{} L1;
(...skipping 20 matching lines...) Expand all
220 These considerations become even more important if one introduces constructs suc h as nested classes, which might be considered in future versions of the languag e. 254 These considerations become even more important if one introduces constructs suc h as nested classes, which might be considered in future versions of the languag e.
221 255
222 Good tooling should of course endeavor to inform programmers of such situations (discreetly). For example, an identifier that is both inherited and lexically vi sible could be highlighted (via underlining or colorization). Better yet, tight integration of source control with language aware tools would detect such change s when they occur. 256 Good tooling should of course endeavor to inform programmers of such situations (discreetly). For example, an identifier that is both inherited and lexically vi sible could be highlighted (via underlining or colorization). Better yet, tight integration of source control with language aware tools would detect such change s when they occur.
223 257
224 } 258 }
225 259
226 260
227 261
228 262
229 \subsection{Privacy} 263 \subsection{Privacy}
230 \label{privacy} 264 \LMLabel{privacy}
231 265
266 \LMHash{}
232 Dart supports two levels of privacy: {\em public} and {\em private}. A declarat ion is {\em private} iff its name is private, otherwise it is {\em public.} A name $q$ is private iff any one of the identifiers that comprise $q$ is private, otherwise it is {\em public.} An identifier is private iff it 267 Dart supports two levels of privacy: {\em public} and {\em private}. A declarat ion is {\em private} iff its name is private, otherwise it is {\em public.} A name $q$ is private iff any one of the identifiers that comprise $q$ is private, otherwise it is {\em public.} An identifier is private iff it
233 begins with an underscore (the \_ character) otherwise it is {\em public.} 268 begins with an underscore (the \_ character) otherwise it is {\em public.}
234 269
270 \LMHash{}
235 A declaration $m$ is {\em accessible to library $L$} if $m$ is declared in $L$ or if $m$ is public. 271 A declaration $m$ is {\em accessible to library $L$} if $m$ is declared in $L$ or if $m$ is public.
236 272
237 \commentary{ 273 \commentary{
238 This means private declarations may only be accessed within the library in which they are declared. 274 This means private declarations may only be accessed within the library in which they are declared.
239 } 275 }
240 276
277 \LMHash{}
241 Privacy applies only to declarations within a library, not to library declaratio ns themselves. 278 Privacy applies only to declarations within a library, not to library declaratio ns themselves.
242 279
243 \rationale{Libraries do not reference each other by name and so the idea of a pr ivate library is meaningless. 280 \rationale{Libraries do not reference each other by name and so the idea of a pr ivate library is meaningless.
244 Thus, if the name of a library begins with an underscore, it has no effect on th e accessibility of the library or its members. 281 Thus, if the name of a library begins with an underscore, it has no effect on th e accessibility of the library or its members.
245 } 282 }
246 283
247 \rationale{Privacy is, at this point, a static notion tied to a particular piece of code (a library). It is designed to support software engineering concerns ra ther than security concerns. Untrusted code should always run in an another isol ate. It is possible that libraries will become first class objects and privacy will be a dynamic notion tied to a library instance. 284 \rationale{Privacy is, at this point, a static notion tied to a particular piece of code (a library). It is designed to support software engineering concerns ra ther than security concerns. Untrusted code should always run in an another isol ate. It is possible that libraries will become first class objects and privacy will be a dynamic notion tied to a library instance.
248 285
249 Privacy is indicated by the name of a declaration - hence privacy and naming are not orthogonal. This has the advantage that both humans and machines can recogn ize access to private declarations at the point of use without knowledge of the context from which the declaration is derived.} 286 Privacy is indicated by the name of a declaration - hence privacy and naming are not orthogonal. This has the advantage that both humans and machines can recogn ize access to private declarations at the point of use without knowledge of the context from which the declaration is derived.}
250 287
251 \subsection{Concurrency} 288 \subsection{Concurrency}
252 289
290 \LMHash{}
253 Dart code is always single threaded. There is no shared-state concurrency in Dar t. Concurrency is supported via actor-like entities called {\em isolates}. 291 Dart code is always single threaded. There is no shared-state concurrency in Dar t. Concurrency is supported via actor-like entities called {\em isolates}.
254 292
293 \LMHash{}
255 An isolate is a unit of concurrency. It has its own memory and its own thread of control. Isolates communicate by message passing (\ref{sendingMessages}). No st ate is ever shared between isolates. Isolates are created by spawning (\ref{spaw ningAnIsolate}). 294 An isolate is a unit of concurrency. It has its own memory and its own thread of control. Isolates communicate by message passing (\ref{sendingMessages}). No st ate is ever shared between isolates. Isolates are created by spawning (\ref{spaw ningAnIsolate}).
256 295
257 296
258 \section{Errors and Warnings} 297 \section{Errors and Warnings}
259 \label{errorsAndWarnings} 298 \LMLabel{errorsAndWarnings}
260 299
300 \LMHash{}
261 This specification distinguishes between several kinds of errors. 301 This specification distinguishes between several kinds of errors.
262 302
303 \LMHash{}
263 {\em Compile-time errors} are errors that preclude execution. A compile-time err or must be reported by a Dart compiler before the erroneous code is executed. 304 {\em Compile-time errors} are errors that preclude execution. A compile-time err or must be reported by a Dart compiler before the erroneous code is executed.
264 305
265 \rationale{A Dart implementation has considerable freedom as to when compilation takes place. Modern programming language implementations often interleave compi lation and execution, so that compilation of a method may be delayed, e.g., unt il it is first invoked. Consequently, compile-time errors in a method $m$ may be reported as late as the time of $m$'s first invocation. 306 \rationale{A Dart implementation has considerable freedom as to when compilation takes place. Modern programming language implementations often interleave compi lation and execution, so that compilation of a method may be delayed, e.g., unt il it is first invoked. Consequently, compile-time errors in a method $m$ may be reported as late as the time of $m$'s first invocation.
266 307
267 As a web language, Dart is often loaded directly from source, with no intermedia te binary representation. In the interests of rapid loading, Dart implementation s may choose to avoid full parsing of method bodies, for example. This can be do ne by tokenizing the input and checking for balanced curly braces on method body entry. In such an implementation, even syntax errors will be detected only when the method needs to be executed, at which time it will be compiled (JITed). 308 As a web language, Dart is often loaded directly from source, with no intermedia te binary representation. In the interests of rapid loading, Dart implementation s may choose to avoid full parsing of method bodies, for example. This can be do ne by tokenizing the input and checking for balanced curly braces on method body entry. In such an implementation, even syntax errors will be detected only when the method needs to be executed, at which time it will be compiled (JITed).
268 309
269 In a development environment a compiler should of course report compilation erro rs eagerly so as to best serve the programmer. 310 In a development environment a compiler should of course report compilation erro rs eagerly so as to best serve the programmer.
270 } 311 }
271 312
313 \LMHash{}
272 If an uncaught compile-time error occurs within the code of a running isolate $A $, $A$ is immediately suspended. The only circumstance where a compile-time err or could be caught would be via code run reflectively, where the mirror system c an catch it. 314 If an uncaught compile-time error occurs within the code of a running isolate $A $, $A$ is immediately suspended. The only circumstance where a compile-time err or could be caught would be via code run reflectively, where the mirror system c an catch it.
273 315
274 \rationale{Typically, once a compile-time error is thrown and $A$ is suspended, $A$ will then be terminated. However, this depends on the overall environment. 316 \rationale{Typically, once a compile-time error is thrown and $A$ is suspended, $A$ will then be terminated. However, this depends on the overall environment.
275 A Dart engine runs in the context of an {\em embedder}, 317 A Dart engine runs in the context of an {\em embedder},
276 a program that interfaces between the engine and the surrounding computing envir onment. The embedder will often be a web browser, but need not be; it may be a C ++ program on the server for example. When an isolate fails with a compile-time error as described above, control returns to the embedder, along with an excepti on describing the problem. This is necessary so that the embedder can clean up resources etc. It is then the embedder's decision whether to terminate the isola te or not. 318 a program that interfaces between the engine and the surrounding computing envir onment. The embedder will often be a web browser, but need not be; it may be a C ++ program on the server for example. When an isolate fails with a compile-time error as described above, control returns to the embedder, along with an excepti on describing the problem. This is necessary so that the embedder can clean up resources etc. It is then the embedder's decision whether to terminate the isola te or not.
277 } 319 }
278 320
321 \LMHash{}
279 {\em Static warnings} are those errors reported by the static checker. They hav e no effect on execution. Many, but not all, static warnings relate to types, in which case they are known as {\em static type warnings.} Static warnings must b e provided by Dart compilers used during development such as those incorporated in IDEs or otherwise intended to be used by developers for developing code. Comp ilers that are part of runtime execution environments such as virtual machines s hould not issue static warnings. 322 {\em Static warnings} are those errors reported by the static checker. They hav e no effect on execution. Many, but not all, static warnings relate to types, in which case they are known as {\em static type warnings.} Static warnings must b e provided by Dart compilers used during development such as those incorporated in IDEs or otherwise intended to be used by developers for developing code. Comp ilers that are part of runtime execution environments such as virtual machines s hould not issue static warnings.
280 323
324 \LMHash{}
281 {\em Dynamic type errors} are type errors reported in checked mode. 325 {\em Dynamic type errors} are type errors reported in checked mode.
282 326
327 \LMHash{}
283 {\em Run-time errors} are exceptions raised during execution. Whenever we say th at an exception $ex$ is {\em raised} or {\em thrown}, we mean that a throw expre ssion (\ref{throw}) of the form: \code{\THROW{} $ex$;} was implicitly evaluated or that a rethrow statement (\ref{rethrow}) of the form \code{\RETHROW} was exe cuted. When we say that {\em a} $C$ {\em is thrown}, where $C$ is a class, we me an that an instance of class $C$ is thrown. 328 {\em Run-time errors} are exceptions raised during execution. Whenever we say th at an exception $ex$ is {\em raised} or {\em thrown}, we mean that a throw expre ssion (\ref{throw}) of the form: \code{\THROW{} $ex$;} was implicitly evaluated or that a rethrow statement (\ref{rethrow}) of the form \code{\RETHROW} was exe cuted. When we say that {\em a} $C$ {\em is thrown}, where $C$ is a class, we me an that an instance of class $C$ is thrown.
284 329
330 \LMHash{}
285 If an uncaught exception is thrown by a running isolate $A$, $A$ is immediately suspended. 331 If an uncaught exception is thrown by a running isolate $A$, $A$ is immediately suspended.
286 332
287 333
288 \section{Variables} 334 \section{Variables}
289 \label{variables} 335 \LMLabel{variables}
290 336
337 \LMHash{}
291 Variables are storage locations in memory. 338 Variables are storage locations in memory.
292 339
293 \begin{grammar} 340 \begin{grammar}
294 {\bf variableDeclaration:} 341 {\bf variableDeclaration:}
295 declaredIdentifier (`,' identifier)* 342 declaredIdentifier (`,' identifier)*
296 . 343 .
297 344
298 {\bf declaredIdentifier:} 345 {\bf declaredIdentifier:}
299 metadata finalConstVarOrType identifier 346 metadata finalConstVarOrType identifier
300 . 347 .
(...skipping 17 matching lines...) Expand all
318 365
319 {\bf initializedIdentifierList:} 366 {\bf initializedIdentifierList:}
320 initializedIdentifier (`,' initializedIdentifier)* 367 initializedIdentifier (`,' initializedIdentifier)*
321 . 368 .
322 369
323 370
324 371
325 372
326 \end{grammar} 373 \end{grammar}
327 374
375 \LMHash{}
328 A variable that has not been initialized has the initial value \NULL{} (\ref{nul l}). 376 A variable that has not been initialized has the initial value \NULL{} (\ref{nul l}).
329 377
378 \LMHash{}
330 A variable declared at the top-level of a library is referred to as either a {\e m library variable} or simply a top-level variable. 379 A variable declared at the top-level of a library is referred to as either a {\e m library variable} or simply a top-level variable.
331 380
381 \LMHash{}
332 A {\em static variable} is a variable that is not associated with a particular i nstance, but rather with an entire library or class. Static variables include l ibrary variables and class variables. Class variables are variables whose declar ation is immediately nested inside a class declaration and includes the modifier \STATIC{}. A library variable is implicitly static. It is a compile-time error to preface a top-level variable declaration with the built-in identifier (\ref{ identifierReference}) \STATIC{}. 382 A {\em static variable} is a variable that is not associated with a particular i nstance, but rather with an entire library or class. Static variables include l ibrary variables and class variables. Class variables are variables whose declar ation is immediately nested inside a class declaration and includes the modifier \STATIC{}. A library variable is implicitly static. It is a compile-time error to preface a top-level variable declaration with the built-in identifier (\ref{ identifierReference}) \STATIC{}.
333 383
384 \LMHash{}
334 Static variable declarations are initialized lazily. When a static variable $v$ is read, iff it has not yet been assigned, it is set to the result of evaluatin g its initializer. The precise rules are given in section \ref{evaluationOfImpli citVariableGetters}. 385 Static variable declarations are initialized lazily. When a static variable $v$ is read, iff it has not yet been assigned, it is set to the result of evaluatin g its initializer. The precise rules are given in section \ref{evaluationOfImpli citVariableGetters}.
335 386
336 \rationale{The lazy semantics are given because we do not want a language where one tends to define expensive initialization computations, causing long applicat ion startup times. This is especially crucial for Dart, which must support the c oding of client applications. 387 \rationale{The lazy semantics are given because we do not want a language where one tends to define expensive initialization computations, causing long applicat ion startup times. This is especially crucial for Dart, which must support the c oding of client applications.
337 } 388 }
338 389
390 \LMHash{}
339 A {\em final variable} is a variable whose binding is fixed upon initialization; a final variable $v$ will always refer to the same object after $v$ has been in itialized. The declaration of a final variable must include the modifier \FINAL {}. 391 A {\em final variable} is a variable whose binding is fixed upon initialization; a final variable $v$ will always refer to the same object after $v$ has been in itialized. The declaration of a final variable must include the modifier \FINAL {}.
340 392
393 \LMHash{}
341 It is a static warning if a final instance variable that has been initialized at its point of declaration is also initialized in a constructor. 394 It is a static warning if a final instance variable that has been initialized at its point of declaration is also initialized in a constructor.
342 % It is a static warning if a final instance variable that has been initialized by means of an initializing formal of a constructor is also initialized elsewhe re in the same constructor. 395 % It is a static warning if a final instance variable that has been initialized by means of an initializing formal of a constructor is also initialized elsewhe re in the same constructor.
343 It is a compile-time error if a local variable $v$ is final and $v$ is not initi alized at its point of declaration. 396 It is a compile-time error if a local variable $v$ is final and $v$ is not initi alized at its point of declaration.
344 397
345 \commentary{ 398 \commentary{
346 399
347 A library or static variable is guaranteed to have an initializer at its declara tion by the grammar. 400 A library or static variable is guaranteed to have an initializer at its declara tion by the grammar.
348 401
349 Attempting to assign to a final variable anywhere except in its declaration or i n a constructor header will cause a runtime error to be thrown as discussed bel ow. The assignment will also give rise to a static warning. Any repeated assignm ent to a final variable will also lead to a runtime error. 402 Attempting to assign to a final variable anywhere except in its declaration or i n a constructor header will cause a runtime error to be thrown as discussed bel ow. The assignment will also give rise to a static warning. Any repeated assignm ent to a final variable will also lead to a runtime error.
350 403
351 Taken as a whole, the rules ensure that any attempt to execute multiple assignme nts to a final variable will yield static warnings and repeated assignments will fail dynamically. 404 Taken as a whole, the rules ensure that any attempt to execute multiple assignme nts to a final variable will yield static warnings and repeated assignments will fail dynamically.
352 } 405 }
353 406
407 \LMHash{}
354 A {\em constant variable} is a variable whose declaration includes the modifier \CONST{}. A constant variable is always implicitly final. A constant variable mu st be initialized to a compile-time constant (\ref{constants}) or a compile-time error occurs. 408 A {\em constant variable} is a variable whose declaration includes the modifier \CONST{}. A constant variable is always implicitly final. A constant variable mu st be initialized to a compile-time constant (\ref{constants}) or a compile-time error occurs.
355 409
410 \LMHash{}
356 We say that a variable $v$ is {\em potentially mutated} in some scope $s$ if $v$ is not final or constant and an assignment to $v$ occurs in $s$. 411 We say that a variable $v$ is {\em potentially mutated} in some scope $s$ if $v$ is not final or constant and an assignment to $v$ occurs in $s$.
357 412
413 \LMHash{}
358 If a variable declaration does not explicitly specify a type, the type of the de clared variable(s) is \DYNAMIC{}, the unknown type (\ref{typeDynamic}). 414 If a variable declaration does not explicitly specify a type, the type of the de clared variable(s) is \DYNAMIC{}, the unknown type (\ref{typeDynamic}).
359 415
416 \LMHash{}
360 A variable is {\em mutable} if it is not final. 417 A variable is {\em mutable} if it is not final.
361 Static and instance variable declarations always induce implicit getters. If the variable is mutable it also introduces an implicit setter. 418 Static and instance variable declarations always induce implicit getters. If the variable is mutable it also introduces an implicit setter.
362 The scope into which the implicit getters and setters are introduced depends on the kind of variable declaration involved. 419 The scope into which the implicit getters and setters are introduced depends on the kind of variable declaration involved.
363 420
421 \LMHash{}
364 A library variable introduces a getter into the top level scope of the enclosing library. A static class variable introduces a static getter into the immediatel y enclosing class. An instance variable introduces an instance getter into the i mmediately enclosing class. 422 A library variable introduces a getter into the top level scope of the enclosing library. A static class variable introduces a static getter into the immediatel y enclosing class. An instance variable introduces an instance getter into the i mmediately enclosing class.
365 423
424 \LMHash{}
366 A mutable library variable introduces a setter into the top level scope of the e nclosing library. A mutable static class variable introduces a static setter int o the immediately enclosing class. A mutable instance variable introduces an ins tance setter into the immediately enclosing class. 425 A mutable library variable introduces a setter into the top level scope of the e nclosing library. A mutable static class variable introduces a static setter int o the immediately enclosing class. A mutable instance variable introduces an ins tance setter into the immediately enclosing class.
367 426
427 \LMHash{}
368 Local variables are added to the innermost enclosing scope. They do not induce getters and setters. A local variable may only be referenced at a source code l ocation that is after its initializer, if any, is complete, or a compile-time er ror occurs. The error may be reported either at the point where the premature r eference occurs, or at the variable declaration. 428 Local variables are added to the innermost enclosing scope. They do not induce getters and setters. A local variable may only be referenced at a source code l ocation that is after its initializer, if any, is complete, or a compile-time er ror occurs. The error may be reported either at the point where the premature r eference occurs, or at the variable declaration.
369 429
370 \rationale { 430 \rationale {
371 We allow the error to be reported at the declaration to allow implementations to avoid an extra processing phase. 431 We allow the error to be reported at the declaration to allow implementations to avoid an extra processing phase.
372 } 432 }
373 433
374 \commentary{ 434 \commentary{
375 The example below illustrates the expected behavior. A variable $x$ is declared at the library level, and another $x$ is declared inside the function $f$. 435 The example below illustrates the expected behavior. A variable $x$ is declared at the library level, and another $x$ is declared inside the function $f$.
376 } 436 }
377 437
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 475
416 \rationale{ 476 \rationale{
417 As a rule, type annotations are ignored in production mode. However, we do 477 As a rule, type annotations are ignored in production mode. However, we do
418 not want to allow programs to compile legally in one mode and not another, and in this extremely odd situation, that consideration takes precedence. 478 not want to allow programs to compile legally in one mode and not another, and in this extremely odd situation, that consideration takes precedence.
419 } 479 }
420 480
421 \end{dartCode} 481 \end{dartCode}
422 482
423 % the grammar does not support local getters and setters. The local var discussi on does not seem to mention getters and setters based semantics. It simply discu sses the creation of the variable, not its access. Access is either assignment o r identifiers. Identifiers ignore the getter story. 483 % the grammar does not support local getters and setters. The local var discussi on does not seem to mention getters and setters based semantics. It simply discu sses the creation of the variable, not its access. Access is either assignment o r identifiers. Identifiers ignore the getter story.
424 484
485 \LMHash{}
425 The following rules apply to all static and instance variables. 486 The following rules apply to all static and instance variables.
426 487
488 \LMHash{}
427 A variable declaration of one of the forms \code{$T$ $v$;}, \code{$T$ $v$ = $ e$;} , \code{\CONST{} $T$ $v$ = $e$;}, \code{\FINAL{} $T$ $v$;} or \code{\FINA L{} $T$ $v$ = $e$;} always induces an implicit getter function (\ref{getters}) with signature 489 A variable declaration of one of the forms \code{$T$ $v$;}, \code{$T$ $v$ = $ e$;} , \code{\CONST{} $T$ $v$ = $e$;}, \code{\FINAL{} $T$ $v$;} or \code{\FINA L{} $T$ $v$ = $e$;} always induces an implicit getter function (\ref{getters}) with signature
428 490
429 $T$ \GET{} $v$ 491 $T$ \GET{} $v$
430 492
431 whose invocation evaluates as described below (\ref{evaluationOfImplicitVariable Getters}). 493 whose invocation evaluates as described below (\ref{evaluationOfImplicitVariable Getters}).
432 494
433 495
496 \LMHash{}
434 A variable declaration of one of the forms \code{\VAR{} $v$;}, \code{\VAR{} $ v$ = $e$;} , \code{\CONST{} $v$ = $e$;}, \code{\FINAL{} $v$;} or \code{\FINAL{} $v$ = $e$;} always induces an implicit getter function with signature 497 A variable declaration of one of the forms \code{\VAR{} $v$;}, \code{\VAR{} $ v$ = $e$;} , \code{\CONST{} $v$ = $e$;}, \code{\FINAL{} $v$;} or \code{\FINAL{} $v$ = $e$;} always induces an implicit getter function with signature
435 498
436 \GET{} $v$ 499 \GET{} $v$
437 500
438 whose invocation evaluates as described below (\ref{evaluationOfImplicitVariabl eGetters}). 501 whose invocation evaluates as described below (\ref{evaluationOfImplicitVariabl eGetters}).
439 502
503 \LMHash{}
440 A non-final variable declaration of the form \code{{} $T$ $v$;} or the form \ code{$T$ $v$ = $e$;} always induces an implicit setter function (\ref{setters }) with signature 504 A non-final variable declaration of the form \code{{} $T$ $v$;} or the form \ code{$T$ $v$ = $e$;} always induces an implicit setter function (\ref{setters }) with signature
441 505
442 \VOID{} \SET{} $v=(T$ $x)$ 506 \VOID{} \SET{} $v=(T$ $x)$
443 507
444 whose execution sets the value of $v$ to the incoming argument $x$. 508 whose execution sets the value of $v$ to the incoming argument $x$.
445 509
510 \LMHash{}
446 A non-final variable declaration of the form \code{\VAR{} $v$;} or the form \ code{\VAR{} $v$ = $e$;} always induces an implicit setter function with signa ture 511 A non-final variable declaration of the form \code{\VAR{} $v$;} or the form \ code{\VAR{} $v$ = $e$;} always induces an implicit setter function with signa ture
447 512
448 \SET{} $v=(x)$ 513 \SET{} $v=(x)$
449 514
450 whose execution sets the value of $v$ to the incoming argument $x$. 515 whose execution sets the value of $v$ to the incoming argument $x$.
451 516
452 517
453 \subsection{Evaluation of Implicit Variable Getters} 518 \subsection{Evaluation of Implicit Variable Getters}
454 \label{evaluationOfImplicitVariableGetters} 519 \LMLabel{evaluationOfImplicitVariableGetters}
455 520
521 \LMHash{}
456 Let $d$ be the declaration of a static or instance variable $v$. If $d$ is an i nstance variable, then the invocation of the implicit getter of $v$ evaluates t o the value stored in $v$. 522 Let $d$ be the declaration of a static or instance variable $v$. If $d$ is an i nstance variable, then the invocation of the implicit getter of $v$ evaluates t o the value stored in $v$.
457 If $d$ is a static or library variable then the implicit getter method of $v$ ex ecutes as follows: 523 If $d$ is a static or library variable then the implicit getter method of $v$ ex ecutes as follows:
458 \begin{itemize} 524 \begin{itemize}
459 \item {\bf Non-constant variable declaration with initializer}. If $d$ is of one of the forms \code{\VAR{} $v$ = $e$;} , \code{$T$ $v$ = $e$;} , \code{\FINAL {} $v$ = $e$;} , \code{\FINAL{} $T$ $v$ = $e$;}, \code{\STATIC{} $v$ = $e$; }, \code{\STATIC{} $T$ $v$ = $e$; }, \code{\STATIC{} \FINAL{} $v$ = $e$; } or \code {\STATIC{} \FINAL{} $T$ $v$ = $e$;} and no value has yet been stored into $v$ th en the initializer expression $e$ is evaluated. If, during the evaluation of $e$ , the getter for $v$ is invoked, a \code{CyclicInitializationError} is thrown. I f the evaluation succeeded yielding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$ is stored into $v$. The result of executing the ge tter is $r$. 525 \item {\bf Non-constant variable declaration with initializer}. If $d$ is of one of the forms \code{\VAR{} $v$ = $e$;} , \code{$T$ $v$ = $e$;} , \code{\FINAL {} $v$ = $e$;} , \code{\FINAL{} $T$ $v$ = $e$;}, \code{\STATIC{} $v$ = $e$; }, \code{\STATIC{} $T$ $v$ = $e$; }, \code{\STATIC{} \FINAL{} $v$ = $e$; } or \code {\STATIC{} \FINAL{} $T$ $v$ = $e$;} and no value has yet been stored into $v$ th en the initializer expression $e$ is evaluated. If, during the evaluation of $e$ , the getter for $v$ is invoked, a \code{CyclicInitializationError} is thrown. I f the evaluation succeeded yielding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$ is stored into $v$. The result of executing the ge tter is $r$.
460 \item {\bf Constant variable declaration}. If $d$ is of one of the forms \code{ \CONST{} $v$ = $e$; } , \code{\CONST{} $T$ $v$ = $e$; }, \code{\STATIC{} \CON ST{} $v$ = $e$; } or \code{\STATIC{} \CONST{} $T$ $v$ = $e$;} the result of the getter is the value of the compile time constant $e$. \commentary{Note that a c ompile time constant cannot depend on itself, so no cyclic references can occur. } 526 \item {\bf Constant variable declaration}. If $d$ is of one of the forms \code{ \CONST{} $v$ = $e$; } , \code{\CONST{} $T$ $v$ = $e$; }, \code{\STATIC{} \CON ST{} $v$ = $e$; } or \code{\STATIC{} \CONST{} $T$ $v$ = $e$;} the result of the getter is the value of the compile time constant $e$. \commentary{Note that a c ompile time constant cannot depend on itself, so no cyclic references can occur. }
461 Otherwise 527 Otherwise
462 \item {\bf Variable declaration without initializer}. The result of executing th e getter method is the value stored in $v$. 528 \item {\bf Variable declaration without initializer}. The result of executing th e getter method is the value stored in $v$.
463 \end{itemize} 529 \end{itemize}
464 530
465 531
466 532
467 533
468 534
469 \section{Functions} 535 \section{Functions}
470 \label{functions} 536 \LMLabel{functions}
471 537
538 \LMHash{}
472 Functions abstract over executable actions. 539 Functions abstract over executable actions.
473 540
474 \begin{grammar} 541 \begin{grammar}
475 {\bf functionSignature:} 542 {\bf functionSignature:}
476 metadata returnType? identifier formalParameterList 543 metadata returnType? identifier formalParameterList
477 . 544 .
478 545
479 {\bf returnType:} 546 {\bf returnType:}
480 \VOID{}; 547 \VOID{};
481 type 548 type
482 . 549 .
483 550
484 {\bf functionBody:} \ASYNC{}? `={\escapegrammar \gt}' expression `{\escapegramm ar ;}'; 551 {\bf functionBody:} \ASYNC{}? `={\escapegrammar \gt}' expression `{\escapegramm ar ;}';
485 (\ASYNC{} $|$ \ASYNC* $|$ \SYNC*)? block 552 (\ASYNC{} $|$ \ASYNC* $|$ \SYNC*)? block
486 . 553 .
487 554
488 {\bf block:} 555 {\bf block:}
489 `\{' statements `\}' 556 `\{' statements `\}'
490 . 557 .
491 558
492 \end{grammar} 559 \end{grammar}
493 560
561 \LMHash{}
494 Functions include function declarations (\ref{functionDeclarations}), methods ( \ref{instanceMethods}, \ref{staticMethods}), getters (\ref{getters}), setters (\ref{setters}), constructors (\ref{constructors}) and function literals (\re f{functionExpressions}). 562 Functions include function declarations (\ref{functionDeclarations}), methods ( \ref{instanceMethods}, \ref{staticMethods}), getters (\ref{getters}), setters (\ref{setters}), constructors (\ref{constructors}) and function literals (\re f{functionExpressions}).
495 563
564 \LMHash{}
496 All functions have a signature and a body. The signature describes the formal pa rameters of the function, and possibly its name and return type. A function bod y is either: 565 All functions have a signature and a body. The signature describes the formal pa rameters of the function, and possibly its name and return type. A function bod y is either:
497 \begin{itemize} 566 \begin{itemize}
498 \item A block statement (\ref{blocks}) containing the statements (\ref{stateme nts}) executed by the function, optionally marked with one of the modifiers: \AS YNC, \ASYNC* or \SYNC*. In this case, if the last statement of a function is not a return statement (\ref{return}), the statement \code{\RETURN{};} is implicitl y appended to the function body. 567 \item A block statement (\ref{blocks}) containing the statements (\ref{stateme nts}) executed by the function, optionally marked with one of the modifiers: \AS YNC, \ASYNC* or \SYNC*. In this case, if the last statement of a function is not a return statement (\ref{return}), the statement \code{\RETURN{};} is implicitl y appended to the function body.
499 568
500 \rationale{ 569 \rationale{
501 Because Dart is optionally typed, we cannot guarantee that a function that does not return a value will not be used in the context of an expression. Therefore, every function must return a value. A \RETURN{} without an expression returns \N ULL{}. For generator functions, the situation is more subtle. See further discus sion in section \ref{return}. 570 Because Dart is optionally typed, we cannot guarantee that a function that does not return a value will not be used in the context of an expression. Therefore, every function must return a value. A \RETURN{} without an expression returns \N ULL{}. For generator functions, the situation is more subtle. See further discus sion in section \ref{return}.
502 } 571 }
503 572
504 OR 573 OR
505 \item of the form \code{=$>$ $e$} which is equivalent to a body of the form \c ode{\{\RETURN{} $e$;\}} or the form \code{\ASYNC{} =$>$ $e$} which is equivalent to a body of the form \code{\ASYNC{} \{\RETURN{} $e$;\}}. \rationale{The other modifiers do not apply here, because they apply only to generators, discussed be low, and generators do not allow the form \code{\RETURN{} $e$}; values are added to the generated stream or iterable using \YIELD{} instead.} 574 \item of the form \code{=$>$ $e$} which is equivalent to a body of the form \c ode{\{\RETURN{} $e$;\}} or the form \code{\ASYNC{} =$>$ $e$} which is equivalent to a body of the form \code{\ASYNC{} \{\RETURN{} $e$;\}}. \rationale{The other modifiers do not apply here, because they apply only to generators, discussed be low, and generators do not allow the form \code{\RETURN{} $e$}; values are added to the generated stream or iterable using \YIELD{} instead.}
506 575
507 \end{itemize} 576 \end{itemize}
508 577
578 \LMHash{}
509 A function is {\em asynchronous} if its body is marked with the \ASYNC{} or \ASY NC* modifier. Otherwise the function is {\em synchronous}. A function is a {\em generator} if its body is marked with the \SYNC* or \ASYNC* modifier. 579 A function is {\em asynchronous} if its body is marked with the \ASYNC{} or \ASY NC* modifier. Otherwise the function is {\em synchronous}. A function is a {\em generator} if its body is marked with the \SYNC* or \ASYNC* modifier.
510 580
511 \commentary{ 581 \commentary{
512 Whether a function is synchronous or asynchronous is orthogonal to whether it is a generator or not. Generator functions are a sugar for functions that produce collections in a systematic way, by lazily applying a function that {\em generat es} individual elements of a collection. Dart provides such a sugar in both the synchronous case, where one returns an iterable, and in the asynchronous case, w here one returns a stream. Dart also allows both synchronous and asynchronous fu nctions that produce a single value. 582 Whether a function is synchronous or asynchronous is orthogonal to whether it is a generator or not. Generator functions are a sugar for functions that produce collections in a systematic way, by lazily applying a function that {\em generat es} individual elements of a collection. Dart provides such a sugar in both the synchronous case, where one returns an iterable, and in the asynchronous case, w here one returns a stream. Dart also allows both synchronous and asynchronous fu nctions that produce a single value.
513 } 583 }
514 584
585 \LMHash{}
515 It is a compile-time error if an \ASYNC, \ASYNC* or \SYNC* modifier is attached to the body of a setter or constructor. 586 It is a compile-time error if an \ASYNC, \ASYNC* or \SYNC* modifier is attached to the body of a setter or constructor.
516 587
517 \rationale{ 588 \rationale{
518 An asynchronous setter would be of little use, since setters can only be used in the context of an assignment (\ref{assignment}), and an assignment expression a lways evaluates to the value of the assignment's right hand side. If the setter actually did its work asynchronously, one might imagine that one would return a future that resolved to the assignment's right hand side after the setter did it s work. However, this would require dynamic tests at every assignment, and so wo uld be prohibitively expensive. 589 An asynchronous setter would be of little use, since setters can only be used in the context of an assignment (\ref{assignment}), and an assignment expression a lways evaluates to the value of the assignment's right hand side. If the setter actually did its work asynchronously, one might imagine that one would return a future that resolved to the assignment's right hand side after the setter did it s work. However, this would require dynamic tests at every assignment, and so wo uld be prohibitively expensive.
519 590
520 An asynchronous constructor would, by definition, never return an instance of th e class it purports to construct, but instead return a future. Calling such a be ast via \NEW{} would be very confusing. If you need to produce an object asynchr onously, use a method. 591 An asynchronous constructor would, by definition, never return an instance of th e class it purports to construct, but instead return a future. Calling such a be ast via \NEW{} would be very confusing. If you need to produce an object asynchr onously, use a method.
521 592
522 One could allow modifiers for factories. A factory for \code{Future} could be mo dified by \ASYNC{}, a factory for \code{Stream} could be modified by \ASYNC* and a factory for \code{Iterable} could be modified by \SYNC*. No other scenario ma kes sense because the object returned by the factory would be of the wrong type. This situation is very unusual so it is not worth making an exception to the ge neral rule for constructors in order to allow it. 593 One could allow modifiers for factories. A factory for \code{Future} could be mo dified by \ASYNC{}, a factory for \code{Stream} could be modified by \ASYNC* and a factory for \code{Iterable} could be modified by \SYNC*. No other scenario ma kes sense because the object returned by the factory would be of the wrong type. This situation is very unusual so it is not worth making an exception to the ge neral rule for constructors in order to allow it.
523 } 594 }
524 595
525 596
526 \subsection{Function Declarations} 597 \subsection{Function Declarations}
527 \label{functionDeclarations} 598 \LMLabel{functionDeclarations}
528 599
600 \LMHash{}
529 A {\em function declaration} is a function that is neither a member of a class n or a function literal. Function declarations include {\em library functions}, wh ich are function declarations 601 A {\em function declaration} is a function that is neither a member of a class n or a function literal. Function declarations include {\em library functions}, wh ich are function declarations
530 %(including getters and setters) 602 %(including getters and setters)
531 at the top level of a library, and {\em local functions}, which are function dec larations declared inside other functions. Library functions are often referred to simply as top-level functions. 603 at the top level of a library, and {\em local functions}, which are function dec larations declared inside other functions. Library functions are often referred to simply as top-level functions.
532 604
605 \LMHash{}
533 A function declaration consists of an identifier indicating the function's name, possibly prefaced by a return type. The function name is followed by a signatur e and body. For getters, the signature is empty. The body is empty for function s that are external. 606 A function declaration consists of an identifier indicating the function's name, possibly prefaced by a return type. The function name is followed by a signatur e and body. For getters, the signature is empty. The body is empty for function s that are external.
534 607
608 \LMHash{}
535 The scope of a library function is the scope of the enclosing library. The scope of a local function is described in section \ref{localFunctionDeclaration}. In both cases, the name of the function is in scope in its formal parameter scope (\ref{formalParameters}). 609 The scope of a library function is the scope of the enclosing library. The scope of a local function is described in section \ref{localFunctionDeclaration}. In both cases, the name of the function is in scope in its formal parameter scope (\ref{formalParameters}).
536 610
537 %A function declaration of the form $T_0$ $id(T_1$ $a_1, \ldots, T_n$ $a_n, [T_ {n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k])\{s\}$ is equivalent to a variable declaration of the form \code{\FINAL{} $F$ $id$ = $(T_1$ $a_1, \ldots , T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k}= d_k])\{s\}$}, where $F$ is the function type alias (\ref{typedef}) \code{\TYPEDEF{} $T_0$ $F(T _1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}])$}. Likewise, a function declaration of the form $id(T_1$ $a_1, \ldots, T_n$ $a_n , [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k])\{s\}$ is equivalen t to a variable declaration of the form \code{\FINAL{} $F$ $id$ = $(T_1$ $a_1, \ ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k])\{s \}$}, where $F$ is the function type alias \code{\TYPEDEF{} $F(T_1$ $a_1, \ldot s, T_n$ $a_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}])$}. 611 %A function declaration of the form $T_0$ $id(T_1$ $a_1, \ldots, T_n$ $a_n, [T_ {n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k])\{s\}$ is equivalent to a variable declaration of the form \code{\FINAL{} $F$ $id$ = $(T_1$ $a_1, \ldots , T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k}= d_k])\{s\}$}, where $F$ is the function type alias (\ref{typedef}) \code{\TYPEDEF{} $T_0$ $F(T _1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}])$}. Likewise, a function declaration of the form $id(T_1$ $a_1, \ldots, T_n$ $a_n , [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k])\{s\}$ is equivalen t to a variable declaration of the form \code{\FINAL{} $F$ $id$ = $(T_1$ $a_1, \ ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k])\{s \}$}, where $F$ is the function type alias \code{\TYPEDEF{} $F(T_1$ $a_1, \ldot s, T_n$ $a_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}])$}.
538 612
539 %\Q{We need to cover library getters as well.} 613 %\Q{We need to cover library getters as well.}
540 614
541 %\Q{ The definition in terms of variables is untrue, because the code would be i llegal. The initializer cannot refer to the function name in this case. I belie ve the best fix is to relax this 615 %\Q{ The definition in terms of variables is untrue, because the code would be i llegal. The initializer cannot refer to the function name in this case. I belie ve the best fix is to relax this
542 %requirement in the case of closures. See bug 315. 616 %requirement in the case of closures. See bug 315.
543 %} 617 %}
544 618
545 %\commentary{ 619 %\commentary{
546 %Some obvious conclusions: 620 %Some obvious conclusions:
547 621
548 %A function declaration of the form $id(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k]) => e$ is equivalent to a varia ble declaration of the form \code{\FINAL{} $id$ = ($(T_1$ $a_1, \ldots, T_n$ $a _n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k])=> e$}. 622 %A function declaration of the form $id(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k]) => e$ is equivalent to a varia ble declaration of the form \code{\FINAL{} $id$ = ($(T_1$ $a_1, \ldots, T_n$ $a _n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k])=> e$}.
549 623
550 %A function literal of the form $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+ 1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k]) => e$ is equivalent to a function li teral of the form \code{$(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_ 1, \ldots, T_{n+k}$ $x_{n+k} = d_k])\{$ \RETURN{} $e$;\}}. 624 %A function literal of the form $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+ 1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k]) => e$ is equivalent to a function li teral of the form \code{$(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_ 1, \ldots, T_{n+k}$ $x_{n+k} = d_k])\{$ \RETURN{} $e$;\}}.
551 %} 625 %}
552 626
553 %A function declaration of the form $T_0$ $id(T_1$ $a_1, \ldots, T_n$ $a_n, \{T _{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_{n+k} : d_k\})\{s\}$ is equivalent t o a variable declaration of the form \code{\FINAL{} $F$ $id$ = $(T_1$ $a_1, \ldo ts, T_n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_{n+k} : d_k\})\{s\ }$}, where $F$ is the function type alias (\ref{typedef}) \code{\TYPEDEF{} $T_0$ $F(T_1$ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k} ]\}$}. Likewise, a function declaration of the form $id(T_1$ $a_1, \ldots, T_ n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_{n+k} : d_k\})\{s\}$ is equivalent to a variable declaration of the form \code{\FINAL{} $F$ $id$ = $(T_1 $ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_{n+k} : d_k\})\{s\}$}, where $F$ is the function type alias \code{\TYPEDEF{} $F(T_1$ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\})$}. 627 %A function declaration of the form $T_0$ $id(T_1$ $a_1, \ldots, T_n$ $a_n, \{T _{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_{n+k} : d_k\})\{s\}$ is equivalent t o a variable declaration of the form \code{\FINAL{} $F$ $id$ = $(T_1$ $a_1, \ldo ts, T_n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_{n+k} : d_k\})\{s\ }$}, where $F$ is the function type alias (\ref{typedef}) \code{\TYPEDEF{} $T_0$ $F(T_1$ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k} ]\}$}. Likewise, a function declaration of the form $id(T_1$ $a_1, \ldots, T_ n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_{n+k} : d_k\})\{s\}$ is equivalent to a variable declaration of the form \code{\FINAL{} $F$ $id$ = $(T_1 $ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_{n+k} : d_k\})\{s\}$}, where $F$ is the function type alias \code{\TYPEDEF{} $F(T_1$ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\})$}.
554 628
629 \LMHash{}
555 It is a compile-time error to preface a function declaration with the built-in i dentifier \STATIC{}. 630 It is a compile-time error to preface a function declaration with the built-in i dentifier \STATIC{}.
556 631
632 \LMHash{}
557 When we say that a function $f_1$ {\em forwards} to another function $f_2$, we m ean that invoking $f_1$ causes $f_2$ to be executed with the same arguments an d/or receiver as $f_1$, and returns the result of executing $f_2$ to the caller of $f_1$, unless $f_2$ throws an exception, in which case $f_1$ throws the same exception. Furthermore, we only use the term for synthetic functions introduced by the specification. 633 When we say that a function $f_1$ {\em forwards} to another function $f_2$, we m ean that invoking $f_1$ causes $f_2$ to be executed with the same arguments an d/or receiver as $f_1$, and returns the result of executing $f_2$ to the caller of $f_1$, unless $f_2$ throws an exception, in which case $f_1$ throws the same exception. Furthermore, we only use the term for synthetic functions introduced by the specification.
558 634
559 635
560 \subsection{Formal Parameters} 636 \subsection{Formal Parameters}
561 \label{formalParameters} 637 \LMLabel{formalParameters}
562 638
639 \LMHash{}
563 Every function includes a {\em formal parameter list}, which consists of a list of required positional parameters (\ref{requiredFormals}), followed by any optio nal parameters (\ref{optionalFormals}). The optional parameters may be specified either as a set of named parameters or as a list of positional parameters, but not both. 640 Every function includes a {\em formal parameter list}, which consists of a list of required positional parameters (\ref{requiredFormals}), followed by any optio nal parameters (\ref{optionalFormals}). The optional parameters may be specified either as a set of named parameters or as a list of positional parameters, but not both.
564 641
642 \LMHash{}
565 The formal parameter list of a function introduces a new scope known as the func tion's {\em formal parameter scope}. The formal parameter scope of a function $f $ is enclosed in the scope where $f$ is declared. Every formal parameter intr oduces a local variable into the formal parameter scope. However, the scope of a function's signature is the function's enclosing scope, not the formal paramete r scope. 643 The formal parameter list of a function introduces a new scope known as the func tion's {\em formal parameter scope}. The formal parameter scope of a function $f $ is enclosed in the scope where $f$ is declared. Every formal parameter intr oduces a local variable into the formal parameter scope. However, the scope of a function's signature is the function's enclosing scope, not the formal paramete r scope.
566 644
645 \LMHash{}
567 The body of a function introduces a new scope known as the function's {\em body scope}. The body scope of a function $f$ is enclosed in the scope introduced by the formal parameter scope of $f$. 646 The body of a function introduces a new scope known as the function's {\em body scope}. The body scope of a function $f$ is enclosed in the scope introduced by the formal parameter scope of $f$.
568 647
569 648
570 %The formal parameter scope of a function maps the name of each formal parameter $p$ to the value $p$ is bound to. 649 %The formal parameter scope of a function maps the name of each formal parameter $p$ to the value $p$ is bound to.
571 650
572 % The formal parameters of a function are processed in the enclosing scope of th e function. 651 % The formal parameters of a function are processed in the enclosing scope of th e function.
573 % \commentary{this means that the parameters themselves may not be referenced wi thin the formal parameter list.} 652 % \commentary{this means that the parameters themselves may not be referenced wi thin the formal parameter list.}
574 653
654 \LMHash{}
575 It is a compile-time error if a formal parameter is declared as a constant varia ble (\ref{variables}). 655 It is a compile-time error if a formal parameter is declared as a constant varia ble (\ref{variables}).
576 656
577 \begin{grammar} 657 \begin{grammar}
578 {\bf formalParameterList:}`(' `)'; 658 {\bf formalParameterList:}`(' `)';
579 `(' normalFormalParameters ( `,' optionalFormalParameters)? `)'; 659 `(' normalFormalParameters ( `,' optionalFormalParameters)? `)';
580 `(' optionalFormalParameters `)' 660 `(' optionalFormalParameters `)'
581 . 661 .
582 %\end{grammar} 662 %\end{grammar}
583 %} 663 %}
584 664
(...skipping 19 matching lines...) Expand all
604 `\{' defaultNamedParameter (`,' defaultNamedParameter)* `\}' 684 `\{' defaultNamedParameter (`,' defaultNamedParameter)* `\}'
605 . 685 .
606 \end{grammar} 686 \end{grammar}
607 687
608 %Formal parameters are always \FINAL{}. 688 %Formal parameters are always \FINAL{}.
609 %\Q{We're awaiting some data on whether enforcing this would cause widespread pa in.} 689 %\Q{We're awaiting some data on whether enforcing this would cause widespread pa in.}
610 %A formal parameter is always considered to be initialized. \rationale{This is because it will always be initialized by the call - even if it is optional.} 690 %A formal parameter is always considered to be initialized. \rationale{This is because it will always be initialized by the call - even if it is optional.}
611 691
612 692
613 \subsubsection{Required Formals} 693 \subsubsection{Required Formals}
614 \label{requiredFormals} 694 \LMLabel{requiredFormals}
615 695
696 \LMHash{}
616 A {\em required formal parameter} may be specified in one of three ways: 697 A {\em required formal parameter} may be specified in one of three ways:
617 \begin{itemize} 698 \begin{itemize}
618 \item By means of a function signature that names the parameter and describes it s type as a function type (\ref{functionTypes}). It is a compile-time error if any default values are specified in the signature of such a function type.% expl ain what the type is in this case? Where is this described in general? 699 \item By means of a function signature that names the parameter and describes it s type as a function type (\ref{functionTypes}). It is a compile-time error if any default values are specified in the signature of such a function type.% expl ain what the type is in this case? Where is this described in general?
619 \item As an initializing formal, which is only valid as a parameter to a generat ive constructor (\ref{generativeConstructors}). % do we need to say this, or any thing more? 700 \item As an initializing formal, which is only valid as a parameter to a generat ive constructor (\ref{generativeConstructors}). % do we need to say this, or any thing more?
620 \item Via an ordinary variable declaration (\ref{variables}). 701 \item Via an ordinary variable declaration (\ref{variables}).
621 \end{itemize} 702 \end{itemize}
622 703
623 \begin{grammar} 704 \begin{grammar}
624 {\bf normalFormalParameter:}functionSignature; 705 {\bf normalFormalParameter:}functionSignature;
625 fieldFormalParameter; 706 fieldFormalParameter;
(...skipping 12 matching lines...) Expand all
638 %\subsubsection{Rest Formals} 719 %\subsubsection{Rest Formals}
639 720
640 %A rest formal $R$ must be the last parameter in a formal parameter list. If a type $T$ is specified for $R$, it signifies that the type of $R$ is $T[]$. 721 %A rest formal $R$ must be the last parameter in a formal parameter list. If a type $T$ is specified for $R$, it signifies that the type of $R$ is $T[]$.
641 722
642 %\begin{grammar} 723 %\begin{grammar}
643 %restFormalParameter: 724 %restFormalParameter:
644 % finalConstVarOrType? '{\escapegrammar ...}' identifier 725 % finalConstVarOrType? '{\escapegrammar ...}' identifier
645 %\end{grammar} 726 %\end{grammar}
646 727
647 \subsubsection{Optional Formals} 728 \subsubsection{Optional Formals}
648 \label{optionalFormals} 729 \LMLabel{optionalFormals}
649 730
731 \LMHash{}
650 Optional parameters may be specified and provided with default values. 732 Optional parameters may be specified and provided with default values.
651 733
652 \begin{grammar} 734 \begin{grammar}
653 {\bf defaultFormalParameter:} 735 {\bf defaultFormalParameter:}
654 normalFormalParameter ('=' expression)? 736 normalFormalParameter ('=' expression)?
655 . 737 .
656 738
657 {\bf defaultNamedParameter:} 739 {\bf defaultNamedParameter:}
658 normalFormalParameter ( `{\escapegrammar :}' expression)? 740 normalFormalParameter ( `{\escapegrammar :}' expression)?
659 . 741 .
660 \end{grammar} 742 \end{grammar}
661 743
744 \LMHash{}
662 It is a compile-time error if the default value of an optional parameter is not a compile-time constant (\ref{constants}). If no default is explicitly specified for an optional parameter an implicit default of \NULL{} is provided. 745 It is a compile-time error if the default value of an optional parameter is not a compile-time constant (\ref{constants}). If no default is explicitly specified for an optional parameter an implicit default of \NULL{} is provided.
663 746
747 \LMHash{}
664 It is a compile-time error if the name of a named optional parameter begins with an `\_' character. 748 It is a compile-time error if the name of a named optional parameter begins with an `\_' character.
665 749
666 \rationale{ 750 \rationale{
667 The need for this restriction is a direct consequence of the fact that naming a nd privacy are not orthogonal. 751 The need for this restriction is a direct consequence of the fact that naming a nd privacy are not orthogonal.
668 If we allowed named parameters to begin with an underscore, they would be consid ered private and inaccessible to callers from outside the library where it was d efined. If a method outside the library overrode a method with a private optiona l name, it would not be a subtype of the original method. The static checker wou ld of course flag such situations, but the consequence would be that adding a pr ivate named formal would break clients outside the library in a way they could n ot easily correct. 752 If we allowed named parameters to begin with an underscore, they would be consid ered private and inaccessible to callers from outside the library where it was d efined. If a method outside the library overrode a method with a private optiona l name, it would not be a subtype of the original method. The static checker wou ld of course flag such situations, but the consequence would be that adding a pr ivate named formal would break clients outside the library in a way they could n ot easily correct.
669 } 753 }
670 754
671 \subsection{Type of a Function} 755 \subsection{Type of a Function}
672 \label{typeOfAFunction} 756 \LMLabel{typeOfAFunction}
673 757
758 \LMHash{}
674 If a function does not declare a return type explicitly, its return type is \DYN AMIC{} (\ref{typeDynamic}). 759 If a function does not declare a return type explicitly, its return type is \DYN AMIC{} (\ref{typeDynamic}).
675 760
761 \LMHash{}
676 Let $F$ be a function with required formal parameters $T_1$ $p_1 \ldots, T_n$ $p _n$, return type $T_0$ and no optional parameters. Then the type of $F$ is $(T_1 ,\ldots, T_n) \rightarrow T_0$. 762 Let $F$ be a function with required formal parameters $T_1$ $p_1 \ldots, T_n$ $p _n$, return type $T_0$ and no optional parameters. Then the type of $F$ is $(T_1 ,\ldots, T_n) \rightarrow T_0$.
677 763
764 \LMHash{}
678 Let $F$ be a function with required formal parameters $T_1$ $p_1 \ldots, T_n$ $p _n$, return type $T_0$ and positional optional parameters $T_{n+1}$ $p_{n+1}, \l dots, T_{n+k}$ $ p_{n+k}$. Then the type of $F$ is $(T_1 ,\ldots, T_n, [T_{n+1}$ $p_{n+1}, \ldots, T_{n+k}$ $p_{n+k}]) \rightarrow T_0$. 765 Let $F$ be a function with required formal parameters $T_1$ $p_1 \ldots, T_n$ $p _n$, return type $T_0$ and positional optional parameters $T_{n+1}$ $p_{n+1}, \l dots, T_{n+k}$ $ p_{n+k}$. Then the type of $F$ is $(T_1 ,\ldots, T_n, [T_{n+1}$ $p_{n+1}, \ldots, T_{n+k}$ $p_{n+k}]) \rightarrow T_0$.
679 766
767 \LMHash{}
680 Let $F$ be a function with required formal parameters $T_1$ $p_1 \ldots, T_n$ $p _n$, return type $T_0$ and named optional parameters $T_{n+1}$ $p_{n+1}, \ldots, T_{n+k}$ $ p_{n+k}$. Then the type of $F$ is $(T_1 ,\ldots, T_n, \{T_{n+1}$ $p_ {n+1}, \ldots, T_{n+k}$ $p_{n+k}\}) \rightarrow T_0$. 768 Let $F$ be a function with required formal parameters $T_1$ $p_1 \ldots, T_n$ $p _n$, return type $T_0$ and named optional parameters $T_{n+1}$ $p_{n+1}, \ldots, T_{n+k}$ $ p_{n+k}$. Then the type of $F$ is $(T_1 ,\ldots, T_n, \{T_{n+1}$ $p_ {n+1}, \ldots, T_{n+k}$ $p_{n+k}\}) \rightarrow T_0$.
681 769
770 \LMHash{}
682 The run time type of a function object always implements the class \cd{Function} . 771 The run time type of a function object always implements the class \cd{Function} .
683 772
684 \commentary{ 773 \commentary{
685 One cannot assume, based on the above, that given a function \cd{f}, \cd{f.runt imeType} will actually be \cd{Function}, or that any two distinct function objec ts necessarily have the same runtime type. 774 One cannot assume, based on the above, that given a function \cd{f}, \cd{f.runt imeType} will actually be \cd{Function}, or that any two distinct function objec ts necessarily have the same runtime type.
686 } 775 }
687 776
688 \rationale{ 777 \rationale{
689 It is up to the implementation to choose an appropriate representation for funct ions. 778 It is up to the implementation to choose an appropriate representation for funct ions.
690 For example, consider that a closure produced via property extraction treats equ ality different from ordinary closures, and is therefore likely a different clas s. Implementations may also use different classes for functions based on arity a nd or type. Arity may be implicitly affected by whether a function is an instanc e method (with an implicit receiver parameter) or not. The variations are manifo ld, and so this specification only guarantees that function objects are instance s of some class that is considered to implement \cd{Function}. 779 For example, consider that a closure produced via property extraction treats equ ality different from ordinary closures, and is therefore likely a different clas s. Implementations may also use different classes for functions based on arity a nd or type. Arity may be implicitly affected by whether a function is an instanc e method (with an implicit receiver parameter) or not. The variations are manifo ld, and so this specification only guarantees that function objects are instance s of some class that is considered to implement \cd{Function}.
691 780
692 } 781 }
693 782
694 \subsection{External Functions} 783 \subsection{External Functions}
695 \label{externalFunctions} 784 \LMLabel{externalFunctions}
696 785
786 \LMHash{}
697 An {\em external function} is a function whose body is provided separately from its declaration. An external function may be a top-level function (\ref{librarie sAndScripts}), a method (\ref{instanceMethods}, \ref{staticMethods}), a getter ( \ref{getters}), a setter (\ref{setters}) or a non-redirecting constructor (\ref{ generativeConstructors}, \ref{factories}). External functions are introduced via the built-in identifier \EXTERNAL{} (\ref{identifierReference}) followed by th e function signature. 787 An {\em external function} is a function whose body is provided separately from its declaration. An external function may be a top-level function (\ref{librarie sAndScripts}), a method (\ref{instanceMethods}, \ref{staticMethods}), a getter ( \ref{getters}), a setter (\ref{setters}) or a non-redirecting constructor (\ref{ generativeConstructors}, \ref{factories}). External functions are introduced via the built-in identifier \EXTERNAL{} (\ref{identifierReference}) followed by th e function signature.
698 788
699 \rationale{ 789 \rationale{
700 External functions allow us to introduce type information for code that is not statically known to the Dart compiler. 790 External functions allow us to introduce type information for code that is not statically known to the Dart compiler.
701 } 791 }
702 792
703 \commentary{ 793 \commentary{
704 Examples of external functions might be foreign functions (defined in C, or Java script etc.), primitives of the implementation (as defined by the Dart runtime), or code that was dynamically generated but whose interface is statically known. However, an abstract method is different from an external function, as it has { \em no} body. 794 Examples of external functions might be foreign functions (defined in C, or Java script etc.), primitives of the implementation (as defined by the Dart runtime), or code that was dynamically generated but whose interface is statically known. However, an abstract method is different from an external function, as it has { \em no} body.
705 } 795 }
706 796
797 \LMHash{}
707 An external function is connected to its body by an implementation specific mech anism. Attempting to invoke an external function that has not been connected to its body will raise a \code{NoSuchMethodError} or some subclass thereof. 798 An external function is connected to its body by an implementation specific mech anism. Attempting to invoke an external function that has not been connected to its body will raise a \code{NoSuchMethodError} or some subclass thereof.
708 799
800 \LMHash{}
709 The actual syntax is given in sections \ref{classes} and \ref{librariesAndScript s} below. 801 The actual syntax is given in sections \ref{classes} and \ref{librariesAndScript s} below.
710 802
711 \section{Classes} 803 \section{Classes}
712 \label{classes} 804 \LMLabel{classes}
713 805
806 \LMHash{}
714 A {\em class} defines the form and behavior of a set of objects which are its {\ em instances}. Classes may be defined by class declarations as described below, or via mixin applications (\ref{mixinApplication}). 807 A {\em class} defines the form and behavior of a set of objects which are its {\ em instances}. Classes may be defined by class declarations as described below, or via mixin applications (\ref{mixinApplication}).
715 808
716 \begin{grammar} 809 \begin{grammar}
717 {\bf classDefinition:} 810 {\bf classDefinition:}
718 metadata \ABSTRACT{}? \CLASS{} identifier typeParameters? (superclass mixins?)? interfaces? \\ 811 metadata \ABSTRACT{}? \CLASS{} identifier typeParameters? (superclass mixins?)? interfaces? \\
719 `\{' (metadata classMemberDefinition)* `\}'; 812 `\{' (metadata classMemberDefinition)* `\}';
720 813
721 metadata \ABSTRACT{}? \CLASS{} mixinApplicationClass 814 metadata \ABSTRACT{}? \CLASS{} mixinApplicationClass
722 . 815 .
723 816
(...skipping 30 matching lines...) Expand all
754 {\bf staticFinalDeclarationList:} 847 {\bf staticFinalDeclarationList:}
755 staticFinalDeclaration (`,' staticFinalDeclaration)* 848 staticFinalDeclaration (`,' staticFinalDeclaration)*
756 . 849 .
757 850
758 {\bf staticFinalDeclaration:} 851 {\bf staticFinalDeclaration:}
759 identifier `=' expression 852 identifier `=' expression
760 . 853 .
761 854
762 \end{grammar} 855 \end{grammar}
763 856
857 \LMHash{}
764 A class has constructors, instance members and static members. The instance mem bers of a class are its instance methods, getters, setters and instance variable s. The static members of a class are its static methods, getters, setters and st atic variables. The members of a class are its static and instance members. 858 A class has constructors, instance members and static members. The instance mem bers of a class are its instance methods, getters, setters and instance variable s. The static members of a class are its static methods, getters, setters and st atic variables. The members of a class are its static and instance members.
765 859
766 % A class has a static scope and an instance scope. The enclosing scope of the s tatic scope of a non-generic class is the enclosing scope of the class declarati on. The enclosing scope of the static scope of a generic class is the type param eter scope (\ref{}) of the generic class declaration. 860 % A class has a static scope and an instance scope. The enclosing scope of the s tatic scope of a non-generic class is the enclosing scope of the class declarati on. The enclosing scope of the static scope of a generic class is the type param eter scope (\ref{}) of the generic class declaration.
767 %The enclosing scope of a class' instance scope is the class' static scope. 861 %The enclosing scope of a class' instance scope is the class' static scope.
768 862
769 %The enclosing scope of an instance member declaration is the instance scope of the class in which it is declared. 863 %The enclosing scope of an instance member declaration is the instance scope of the class in which it is declared.
770 864
771 %The enclosing scope of a static member declaration is the static scope of the c lass in which it is declared. 865 %The enclosing scope of a static member declaration is the static scope of the c lass in which it is declared.
772 866
773 867
868 \LMHash{}
774 Every class has a single superclass except class \code{Object} which has no sup erclass. A class may implement a number of interfaces 869 Every class has a single superclass except class \code{Object} which has no sup erclass. A class may implement a number of interfaces
775 %, either 870 %, either
776 by declaring them in its implements clause (\ref{superinterfaces}). 871 by declaring them in its implements clause (\ref{superinterfaces}).
777 % or via interface injection declarations (\ref{interfaceInjection}) outside the class declaration 872 % or via interface injection declarations (\ref{interfaceInjection}) outside the class declaration
778 873
779 874
875 \LMHash{}
780 An {\em abstract class} is 876 An {\em abstract class} is
781 %either 877 %either
782 a class that is explicitly declared with the \ABSTRACT{} modifier, either by m eans of a class declaration or via a type alias (\ref{typedef}) for a mixin appl ication (\ref{mixinApplication}). A {\em concrete class} is a class that is not abstract. 878 a class that is explicitly declared with the \ABSTRACT{} modifier, either by m eans of a class declaration or via a type alias (\ref{typedef}) for a mixin appl ication (\ref{mixinApplication}). A {\em concrete class} is a class that is not abstract.
783 %, or a class that declares at least one abstract method (\ref{abstractInstance Members}). 879 %, or a class that declares at least one abstract method (\ref{abstractInstance Members}).
784 880
785 \rationale{ 881 \rationale{
786 %The abstract modifier for classes is intended to be used in scenarios where an abstract class $A$ inherits from another abstract class $B$. In such a situation , it may be that A$ $itself does not declare any abstract methods. In the absenc e of an abstract modifier on the class, the class would be interpreted as a conc rete class. However, w 882 %The abstract modifier for classes is intended to be used in scenarios where an abstract class $A$ inherits from another abstract class $B$. In such a situation , it may be that A$ $itself does not declare any abstract methods. In the absenc e of an abstract modifier on the class, the class would be interpreted as a conc rete class. However, w
787 We want different behavior for concrete classes and abstract classes. If $A$ is intended to be abstract, we want the static checker to warn about any attempt to instantiate $A$, and we do not want the checker to complain about unimplemented methods in $A$. In contrast, if $A$ is intended to be concrete, the checker sho uld warn about all unimplemented methods, but allow clients to instantiate it fr eely. 883 We want different behavior for concrete classes and abstract classes. If $A$ is intended to be abstract, we want the static checker to warn about any attempt to instantiate $A$, and we do not want the checker to complain about unimplemented methods in $A$. In contrast, if $A$ is intended to be concrete, the checker sho uld warn about all unimplemented methods, but allow clients to instantiate it fr eely.
788 } 884 }
789 885
886 \LMHash{}
790 The {\em interface of class $C$} is an implicit interface that declares instance members that correspond to the instance members declared by $C$, and whose dire ct superinterfaces are the direct superinterfaces of $C$ (\ref{superinterfaces}) . When a class name appears as a type, that name denotes the interface of the cl ass. 887 The {\em interface of class $C$} is an implicit interface that declares instance members that correspond to the instance members declared by $C$, and whose dire ct superinterfaces are the direct superinterfaces of $C$ (\ref{superinterfaces}) . When a class name appears as a type, that name denotes the interface of the cl ass.
791 888
792 % making an exception for the setters generated for final fields is tempting but problematic. 889 % making an exception for the setters generated for final fields is tempting but problematic.
793 % If a super type defines a setter, it will be overridden yet have no impact on the interface. 890 % If a super type defines a setter, it will be overridden yet have no impact on the interface.
794 % Maybe the final field hides the setter in scope? 891 % Maybe the final field hides the setter in scope?
795 % I think the original rules were best. 892 % I think the original rules were best.
796 893
894 \LMHash{}
797 It is a compile-time error if a class declares two members of the same name. 895 It is a compile-time error if a class declares two members of the same name.
798 %, except that a getter and a setter may be declared with the same name provide d both are instance members or both are static members. 896 %, except that a getter and a setter may be declared with the same name provide d both are instance members or both are static members.
799 It is a compile-time error if a class has an instance member and a static member with the same name. 897 It is a compile-time error if a class has an instance member and a static member with the same name.
800 % It is a compile-time error if a generic (\ref{generics}) class declares a memb er with the same name as one of its type parameters. 898 % It is a compile-time error if a generic (\ref{generics}) class declares a memb er with the same name as one of its type parameters.
801 899
802 \commentary{Here are simple examples, that illustrate the difference between ``h as a member'' and ``declares a member''. For example, \code{B} {\em declares} on e member named \code{f}, but {\em has} two such members. The rules of inheritanc e determine what members a class has. 900 \commentary{Here are simple examples, that illustrate the difference between ``h as a member'' and ``declares a member''. For example, \code{B} {\em declares} on e member named \code{f}, but {\em has} two such members. The rules of inheritanc e determine what members a class has.
803 } 901 }
804 902
805 \begin{dartCode} 903 \begin{dartCode}
806 \CLASS{} A \{ 904 \CLASS{} A \{
807 \VAR{} i = 0; 905 \VAR{} i = 0;
808 \VAR{} j; 906 \VAR{} j;
809 f(x) =$>$ 3; 907 f(x) =$>$ 3;
810 \} 908 \}
811 909
812 \CLASS{} B \EXTENDS{} A \{ 910 \CLASS{} B \EXTENDS{} A \{
813 int i = 1; // getter i and setter i= override versions from A 911 int i = 1; // getter i and setter i= override versions from A
814 \STATIC{} j; // compile-time error: static getter \& setter conflict with 912 \STATIC{} j; // compile-time error: static getter \& setter conflict with
815 //instance getter \& setter 913 //instance getter \& setter
816 914
817 /* compile-time error: static method conflicts with instance method */ 915 /* compile-time error: static method conflicts with instance method */
818 \STATIC{} f(x) =$>$ 3; 916 \STATIC{} f(x) =$>$ 3;
819 \} 917 \}
820 \end{dartCode} 918 \end{dartCode}
821 919
920 \LMHash{}
822 It is a compile time error if a class $C$ declares a member with the same name a s $C$. It is a compile time error if a generic class declares a type variable wi th the same name as the class or any of its members or constructors. 921 It is a compile time error if a class $C$ declares a member with the same name a s $C$. It is a compile time error if a generic class declares a type variable wi th the same name as the class or any of its members or constructors.
823 922
824 \subsection{Instance Methods} 923 \subsection{Instance Methods}
825 \label{instanceMethods} 924 \LMLabel{instanceMethods}
826 925
926 \LMHash{}
827 Instance methods are functions (\ref{functions}) whose declarations are immediat ely contained within a class declaration and that are not declared \STATIC{}. Th e instance methods of a class $C$ are those instance methods declared by $C$ and the instance methods inherited by $C$ from its superclass. 927 Instance methods are functions (\ref{functions}) whose declarations are immediat ely contained within a class declaration and that are not declared \STATIC{}. Th e instance methods of a class $C$ are those instance methods declared by $C$ and the instance methods inherited by $C$ from its superclass.
828 928
829 %make these warnings if possible 929 %make these warnings if possible
830 930
931 \LMHash{}
831 It is a static warning if an instance method $m_1$ overrides (\ref{inheritanceA ndOverriding}) an instance member $m_2$ and $m_1$ has a greater number of requi red parameters than $m_2$. It is a static warning if an instance method $m_1$ ov errides an instance member $m_2$ and $m_1$ has fewer positional parameters tha n $m_2$. It is a static warning if an instance method $m_1$ overrides an insta nce member $m_2$ and $m_1$ does not declare all the named parameters declared b y $m_2$. 932 It is a static warning if an instance method $m_1$ overrides (\ref{inheritanceA ndOverriding}) an instance member $m_2$ and $m_1$ has a greater number of requi red parameters than $m_2$. It is a static warning if an instance method $m_1$ ov errides an instance member $m_2$ and $m_1$ has fewer positional parameters tha n $m_2$. It is a static warning if an instance method $m_1$ overrides an insta nce member $m_2$ and $m_1$ does not declare all the named parameters declared b y $m_2$.
832 933
833 % not quite right. It should be ok to override a method that requires N paramete rs with one that requires M < N but accepts the others as optional. 934 % not quite right. It should be ok to override a method that requires N paramete rs with one that requires M < N but accepts the others as optional.
834 935
936 \LMHash{}
835 It is a static warning if an instance method $m_1$ overrides an instance member $m_2$ and the type of $m_1$ is not a subtype of the type of $m_2$. It is a stati c warning if an instance method $m_1$ overrides an instance member $m_2$, the s ignature of $m_2$ explicitly specifies a default value for a formal parameter $p $ and the signature of $m_1$ implies a different default value for $p$. It is a static warning if a class $C$ declares an instance method named $n$ and has a se tter named $n=$. It is a static warning if a class $C$ declares an instance meth od named $n$ and an accessible static member named $n$ is declared in a supercla ss of $C$. 937 It is a static warning if an instance method $m_1$ overrides an instance member $m_2$ and the type of $m_1$ is not a subtype of the type of $m_2$. It is a stati c warning if an instance method $m_1$ overrides an instance member $m_2$, the s ignature of $m_2$ explicitly specifies a default value for a formal parameter $p $ and the signature of $m_1$ implies a different default value for $p$. It is a static warning if a class $C$ declares an instance method named $n$ and has a se tter named $n=$. It is a static warning if a class $C$ declares an instance meth od named $n$ and an accessible static member named $n$ is declared in a supercla ss of $C$.
836 938
837 % Works. If the name is public, no issue. If it's private, if a subclass has a c onflicting inst var, it either is in the same lib and will be flagged, or is in another and is not an issue. 939 % Works. If the name is public, no issue. If it's private, if a subclass has a c onflicting inst var, it either is in the same lib and will be flagged, or is in another and is not an issue.
838 940
839 941
840 \subsubsection{Operators} 942 \subsubsection{Operators}
841 \label{operators} 943 \LMLabel{operators}
842 944
945 \LMHash{}
843 {\em Operators} are instance methods with special names. 946 {\em Operators} are instance methods with special names.
844 947
845 \begin{grammar} 948 \begin{grammar}
846 {\bf operatorSignature:} 949 {\bf operatorSignature:}
847 returnType? \OPERATOR{} operator formalParameterList 950 returnType? \OPERATOR{} operator formalParameterList
848 . 951 .
849 952
850 {\bf operator:}`\~{}'; 953 {\bf operator:}`\~{}';
851 binaryOperator; 954 binaryOperator;
852 `[' `]' ; 955 `[' `]' ;
853 `[' `]' `=' 956 `[' `]' `='
854 . 957 .
855 958
856 {\bf binaryOperator:}multiplicativeOperator; 959 {\bf binaryOperator:}multiplicativeOperator;
857 additiveOperator; 960 additiveOperator;
858 shiftOperator; 961 shiftOperator;
859 relationalOperator; 962 relationalOperator;
860 `=='; 963 `==';
861 bitwiseOperator 964 bitwiseOperator
862 . 965 .
863 \end{grammar} 966 \end{grammar}
864 967
968 \LMHash{}
865 An operator declaration is identified using the built-in identifier (\ref{identi fierReference}) \OPERATOR{}. 969 An operator declaration is identified using the built-in identifier (\ref{identi fierReference}) \OPERATOR{}.
866 970
971 \LMHash{}
867 The following names are allowed for user-defined operators: \code{$<$, $>$, $<$= , $>$=, ==, -, +, /, \~{}/, *, \%, $|$, \^{}, \&, $<<$, $>>$, []=, [], \~{}.} 972 The following names are allowed for user-defined operators: \code{$<$, $>$, $<$= , $>$=, ==, -, +, /, \~{}/, *, \%, $|$, \^{}, \&, $<<$, $>>$, []=, [], \~{}.}
868 973
869 974
975 \LMHash{}
870 It is a compile-time error if the arity of the user-declared operator \code{[]=} is not 2. It is a compile-time error if the arity of a user-declared operator w ith one of the names: \code{ $<$, $>$, $<$=, $>$=, ==, -, +, \~{}/, /, *, \%, $|$, \^{}, \&, $<<$, $>>$, []} is not 1. It is a compile-time error if the arity of the user-declared operator \code{-} is not 0 or 1. 976 It is a compile-time error if the arity of the user-declared operator \code{[]=} is not 2. It is a compile-time error if the arity of a user-declared operator w ith one of the names: \code{ $<$, $>$, $<$=, $>$=, ==, -, +, \~{}/, /, *, \%, $|$, \^{}, \&, $<<$, $>>$, []} is not 1. It is a compile-time error if the arity of the user-declared operator \code{-} is not 0 or 1.
871 977
872 \commentary{ 978 \commentary{
873 The \code{-} operator is unique in that two overloaded versions are permitted. I f the operator has no arguments, it denotes unary minus. If it has an argument, it denotes binary subtraction. 979 The \code{-} operator is unique in that two overloaded versions are permitted. I f the operator has no arguments, it denotes unary minus. If it has an argument, it denotes binary subtraction.
874 } 980 }
875 981
982 \LMHash{}
876 The name of the unary operator \code{-} is \code{unary-}. 983 The name of the unary operator \code{-} is \code{unary-}.
877 984
878 \rationale{ 985 \rationale{
879 This device allows the two methods to be distinguished for purposes of method lo okup, override and reflection. 986 This device allows the two methods to be distinguished for purposes of method lo okup, override and reflection.
880 } 987 }
881 988
989 \LMHash{}
882 It is a compile-time error if the arity of the user-declared operator \code{ \~ {}} is not 0. 990 It is a compile-time error if the arity of the user-declared operator \code{ \~ {}} is not 0.
883 991
992 \LMHash{}
884 It is a compile-time error to declare an optional parameter in an operator. 993 It is a compile-time error to declare an optional parameter in an operator.
885 994
995 \LMHash{}
886 It is a static warning if the return type of the user-declared operator \code{[] =} is explicitly declared and not \VOID{}. 996 It is a static warning if the return type of the user-declared operator \code{[] =} is explicitly declared and not \VOID{}.
887 997
888 998
889 \subsection{Getters} 999 \subsection{Getters}
890 \label{getters} 1000 \LMLabel{getters}
891 1001
1002 \LMHash{}
892 Getters are functions (\ref{functions}) that are used to retrieve the values of object properties. 1003 Getters are functions (\ref{functions}) that are used to retrieve the values of object properties.
893 1004
894 \begin{grammar} 1005 \begin{grammar}
895 {\bf getterSignature:} 1006 {\bf getterSignature:}
896 returnType? \GET{} identifier 1007 returnType? \GET{} identifier
897 . 1008 .
898 \end{grammar} 1009 \end{grammar}
899 1010
900 %\Q{Why does a getter have a formal parameter list at all?} 1011 %\Q{Why does a getter have a formal parameter list at all?}
901 1012
1013 \LMHash{}
902 If no return type is specified, the return type of the getter is \DYNAMIC{}. 1014 If no return type is specified, the return type of the getter is \DYNAMIC{}.
903 1015
1016 \LMHash{}
904 A getter definition that is prefixed with the \STATIC{} modifier defines a stati c getter. Otherwise, it defines an instance getter. The name of the getter is gi ven by the identifier in the definition. The effect of a static getter declarati on in class $C$ is to add an instance getter with the same name and signature to the \code{Type} object for class $C$ that forwards (\ref{functionDeclarations}) to the static getter. 1017 A getter definition that is prefixed with the \STATIC{} modifier defines a stati c getter. Otherwise, it defines an instance getter. The name of the getter is gi ven by the identifier in the definition. The effect of a static getter declarati on in class $C$ is to add an instance getter with the same name and signature to the \code{Type} object for class $C$ that forwards (\ref{functionDeclarations}) to the static getter.
905 1018
906 %It is a compile-time error if a getter`s formal parameter list is not empty. 1019 %It is a compile-time error if a getter`s formal parameter list is not empty.
907 1020
1021 \LMHash{}
908 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$. 1022 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$.
909 1023
1024 \LMHash{}
910 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. 1025 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.
911 1026
912 \commentary{ 1027 \commentary{
913 This implies that a getter can never override a method, and a method can never o verride a getter or field. 1028 This implies that a getter can never override a method, and a method can never o verride a getter or field.
914 } 1029 }
915 1030
1031 \LMHash{}
916 It is a static warning if the return type of a getter is \VOID. 1032 It is a static warning if the return type of a getter is \VOID.
917 It is a static warning if a getter $m_1$ overrides (\ref{inheritanceAndOverridi ng}) a getter 1033 It is a static warning if a getter $m_1$ overrides (\ref{inheritanceAndOverridi ng}) a getter
918 $m_2$ and the type of $m_1$ is not a subtype of the type of $m_2$. 1034 $m_2$ and the type of $m_1$ is not a subtype of the type of $m_2$.
919 1035
1036 \LMHash{}
920 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. 1037 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.
921 1038
922 \subsection{Setters} 1039 \subsection{Setters}
923 \label{setters} 1040 \LMLabel{setters}
924 1041
1042 \LMHash{}
925 Setters are functions (\ref{functions}) that are used to set the values of objec t properties. 1043 Setters are functions (\ref{functions}) that are used to set the values of objec t properties.
926 1044
927 % what about top level ones? Same for getters 1045 % what about top level ones? Same for getters
928 1046
929 \begin{grammar} 1047 \begin{grammar}
930 {\bf setterSignature:} 1048 {\bf setterSignature:}
931 returnType? \SET{} identifier formalParameterList 1049 returnType? \SET{} identifier formalParameterList
932 . 1050 .
933 \end{grammar} 1051 \end{grammar}
934 1052
1053 \LMHash{}
935 If no return type is specified, the return type of the setter is \DYNAMIC{}. 1054 If no return type is specified, the return type of the setter is \DYNAMIC{}.
936 1055
1056 \LMHash{}
937 A setter definition that is prefixed with the \STATIC{} modifier defines a stati c setter. Otherwise, it defines an instance setter. The name of a setter is obt ained by appending the string `=' to the identifier given in its signature. Th e effect of a static setter declaration in class $C$ is to add an instance sette r with the same name and signature to the \code{Type} object for class $C$ that forwards (\ref{functionDeclarations}) to the static setter. 1057 A setter definition that is prefixed with the \STATIC{} modifier defines a stati c setter. Otherwise, it defines an instance setter. The name of a setter is obt ained by appending the string `=' to the identifier given in its signature. Th e effect of a static setter declaration in class $C$ is to add an instance sette r with the same name and signature to the \code{Type} object for class $C$ that forwards (\ref{functionDeclarations}) to the static setter.
938 1058
939 \commentary{Hence, a setter name can never conflict with, override or be overrid den by a getter or method.} 1059 \commentary{Hence, a setter name can never conflict with, override or be overrid den by a getter or method.}
940 1060
1061 \LMHash{}
941 The instance setters of a class $C$ are those instance setters declared by $C$ e ither implicitly or explicitly, and the instance setters inherited by $C$ from i ts superclass. The static setters of a class $C$ are those static setters declar ed by $C$. 1062 The instance setters of a class $C$ are those instance setters declared by $C$ e ither implicitly or explicitly, and the instance setters inherited by $C$ from i ts superclass. The static setters of a class $C$ are those static setters declar ed by $C$.
942 1063
1064 \LMHash{}
943 It is a compile-time error if a setter's formal parameter list does not consist of exactly one required formal parameter $p$. \rationale{We could enforce this via the grammar, but we'd have to specify the evaluation rules in that case.} 1065 It is a compile-time error if a setter's formal parameter list does not consist of exactly one required formal parameter $p$. \rationale{We could enforce this via the grammar, but we'd have to specify the evaluation rules in that case.}
944 1066
945 %It is a compile-time error if a class has both a setter and a method with the s ame name. This restriction holds regardless of whether the setter is defined exp licitly or implicitly, or whether the setter or the method are inherited or not. 1067 %It is a compile-time error if a class has both a setter and a method with the s ame name. This restriction holds regardless of whether the setter is defined exp licitly or implicitly, or whether the setter or the method are inherited or not.
946 1068
1069 \LMHash{}
947 It is a static warning if a setter declares a return type other than \VOID{}. 1070 It is a static warning if a setter declares a return type other than \VOID{}.
948 It is a static warning if a setter $m_1$ overrides (\ref{inheritanceAndOverridi ng}) a setter $m_2$ and the type of $m_1$ is not a subtype of the type of $m_2$. It is a static warning if a class has a setter named $v=$ with argument type $T $ and a getter named $v$ with return type $S$, and $T$ may not be assigned to $S $. 1071 It is a static warning if a setter $m_1$ overrides (\ref{inheritanceAndOverridi ng}) a setter $m_2$ and the type of $m_1$ is not a subtype of the type of $m_2$. It is a static warning if a class has a setter named $v=$ with argument type $T $ and a getter named $v$ with return type $S$, and $T$ may not be assigned to $S $.
949 1072
1073 \LMHash{}
950 It is a static warning if a class declares a static setter named $v=$ and also has a non-static member named $v$. It is a static warning if a class $C$ declare s an instance setter named $v=$ and an accessible static member named $v=$ or $v $ is declared in a superclass of $C$. 1074 It is a static warning if a class declares a static setter named $v=$ and also has a non-static member named $v$. It is a static warning if a class $C$ declare s an instance setter named $v=$ and an accessible static member named $v=$ or $v $ is declared in a superclass of $C$.
951 1075
1076 \LMHash{}
952 These warnings must be issued regardless of whether the getters or setters are d eclared explicitly or implicitly. 1077 These warnings must be issued regardless of whether the getters or setters are d eclared explicitly or implicitly.
953 1078
954 \subsection{Abstract Instance Members} 1079 \subsection{Abstract Instance Members}
955 \label{abstractInstanceMembers} 1080 \LMLabel{abstractInstanceMembers}
956 1081
1082 \LMHash{}
957 An {\em abstract method} (respectively, {\em abstract getter} or {\em abstract s etter)} is an instance method, getter or setter that is not declared \EXTERNAL{} and does not provide an implementation. A {\em concrete method} (respectively, {\em concrete getter} or {\em concrete setter)} is an instance method, getter o r setter that is not abstract. 1083 An {\em abstract method} (respectively, {\em abstract getter} or {\em abstract s etter)} is an instance method, getter or setter that is not declared \EXTERNAL{} and does not provide an implementation. A {\em concrete method} (respectively, {\em concrete getter} or {\em concrete setter)} is an instance method, getter o r setter that is not abstract.
958 %The declaration of an abstract method is prefixed by the built-in identifier (\ ref{identifierReference}) \ABSTRACT{}. 1084 %The declaration of an abstract method is prefixed by the built-in identifier (\ ref{identifierReference}) \ABSTRACT{}.
959 1085
960 \rationale{ 1086 \rationale{
961 Earlier versions of Dart required that abstract members be identified by prefixi ng them with the modifier \ABSTRACT{}. The elimination of this requirement is m otivated by the desire to use abstract classes as interfaces. Every Dart class i nduces an implicit interface. 1087 Earlier versions of Dart required that abstract members be identified by prefixi ng them with the modifier \ABSTRACT{}. The elimination of this requirement is m otivated by the desire to use abstract classes as interfaces. Every Dart class i nduces an implicit interface.
962 1088
963 Using an abstract class instead of an interface has important advantages. An abs tract class can provide default implementations; it can also provide static meth ods, obviating the need for service classes such as \code{Collections} or \code{ Lists}, whose entire purpose is to group utilities related to a given type. 1089 Using an abstract class instead of an interface has important advantages. An abs tract class can provide default implementations; it can also provide static meth ods, obviating the need for service classes such as \code{Collections} or \code{ Lists}, whose entire purpose is to group utilities related to a given type.
964 1090
965 Eliminating the requirement for an explicit modifier on members makes abstract c lasses more concise, making abstract classes an attractive substitute for inter face declarations. 1091 Eliminating the requirement for an explicit modifier on members makes abstract c lasses more concise, making abstract classes an attractive substitute for inter face declarations.
966 } 1092 }
967 1093
968 \commentary {Invoking an abstract method, getter or setter results in an invocat ion of \cd{noSuchMethod} exactly as if the declaration did not exist, unless a suitable member $a$ is available in a superclass, in which case $a$ is invoked. The normative specification for this appears under the definitions of lookup fo r methods, getters and setters. 1094 \commentary {Invoking an abstract method, getter or setter results in an invocat ion of \cd{noSuchMethod} exactly as if the declaration did not exist, unless a suitable member $a$ is available in a superclass, in which case $a$ is invoked. The normative specification for this appears under the definitions of lookup fo r methods, getters and setters.
969 } 1095 }
970 1096
971 % so does an abstract method override a method in a superclass or not? Does the superclass method get inherited or not? This generally makes the spec inconsist ent, as there is no simple answer. 1097 % so does an abstract method override a method in a superclass or not? Does the superclass method get inherited or not? This generally makes the spec inconsist ent, as there is no simple answer.
972 % For example - if we say it does not override, then the superclass member is in herited, in which case the rules for warning break down, and also there is quest ion of whether there are two definitions of the same name. 1098 % For example - if we say it does not override, then the superclass member is in herited, in which case the rules for warning break down, and also there is quest ion of whether there are two definitions of the same name.
973 % But if we do override, method lookup rules break down. So several things need revisiting. 1099 % But if we do override, method lookup rules break down. So several things need revisiting.
974 1100
975 \rationale{ 1101 \rationale{
976 The purpose of an abstract method is to provide a declaration for purposes such as type checking and reflection. In classes used as mixins, it is often useful t o introduce such declarations for methods that the mixin expects will be provide d by the superclass the mixin is applied to. 1102 The purpose of an abstract method is to provide a declaration for purposes such as type checking and reflection. In classes used as mixins, it is often useful t o introduce such declarations for methods that the mixin expects will be provide d by the superclass the mixin is applied to.
977 } 1103 }
978 %always results in a run-time error. This must be \code{NoSuchMethodError} or an instance of a subclass of \code{NoSuchMethodError}, such as \code{AbstractMetho dError}. 1104 %always results in a run-time error. This must be \code{NoSuchMethodError} or an instance of a subclass of \code{NoSuchMethodError}, such as \code{AbstractMetho dError}.
979 1105
1106 \LMHash{}
980 It is a static warning if an abstract member is declared or inherited in a concr ete class unless that member overrides a concrete one. 1107 It is a static warning if an abstract member is declared or inherited in a concr ete class unless that member overrides a concrete one.
981 1108
982 \rationale { 1109 \rationale {
983 We wish to warn if one declares a concrete class with abstract members. However, code like the following should work without warnings: 1110 We wish to warn if one declares a concrete class with abstract members. However, code like the following should work without warnings:
984 } 1111 }
985 1112
986 \begin{dartCode} 1113 \begin{dartCode}
987 class Base \{ 1114 class Base \{
988 int get one =$>$ 1; 1115 int get one =$>$ 1;
989 \} 1116 \}
990 1117
991 abstract class Mix \{ 1118 abstract class Mix \{
992 int get one; 1119 int get one;
993 int get two =$>$ one + one; 1120 int get two =$>$ one + one;
994 \} 1121 \}
995 1122
996 class C extends Base with Mix \{ 1123 class C extends Base with Mix \{
997 \} 1124 \}
998 \} 1125 \}
999 \end{dartCode} 1126 \end{dartCode}
1000 1127
1001 \rationale{At run time, the concrete method \cd{one} declared in \cd{Base} will be executed, and no problem should arise. Therefore no warning should be issued and so we suppress warnings if a corresponding concrete member exists in the hie rarchy. } 1128 \rationale{At run time, the concrete method \cd{one} declared in \cd{Base} will be executed, and no problem should arise. Therefore no warning should be issued and so we suppress warnings if a corresponding concrete member exists in the hie rarchy. }
1002 1129
1003 \subsection{Instance Variables} 1130 \subsection{Instance Variables}
1004 \label{instanceVariables} 1131 \LMLabel{instanceVariables}
1005 1132
1133 \LMHash{}
1006 Instance variables are variables whose declarations are immediately contained wi thin a class declaration and that are not declared \STATIC{}. The instance varia bles of a class $C$ are those instance variables declared by $C$ and the instanc e variables inherited by $C$ from its superclass. 1134 Instance variables are variables whose declarations are immediately contained wi thin a class declaration and that are not declared \STATIC{}. The instance varia bles of a class $C$ are those instance variables declared by $C$ and the instanc e variables inherited by $C$ from its superclass.
1007 1135
1136 \LMHash{}
1008 It is a compile-time error if an instance variable is declared to be constant. 1137 It is a compile-time error if an instance variable is declared to be constant.
1009 1138
1010 \rationale{ 1139 \rationale{
1011 The notion of a constant instance variable is subtle and confusing to programmer s. 1140 The notion of a constant instance variable is subtle and confusing to programmer s.
1012 An instance variable is intended to vary per instance. A constant instance varia ble would have the same value for all instances, and as such is already a dubiou s idea. 1141 An instance variable is intended to vary per instance. A constant instance varia ble would have the same value for all instances, and as such is already a dubiou s idea.
1013 1142
1014 The language could interpret const instance variable declarations as instance ge tters that return a constant. However, a constant instance variable could not b e treated as a true compile time constant, as its getter would be subject to ove rriding. 1143 The language could interpret const instance variable declarations as instance ge tters that return a constant. However, a constant instance variable could not b e treated as a true compile time constant, as its getter would be subject to ove rriding.
1015 1144
1016 Given that the value does not depend on the instance, it is better to use a sta tic class variable. 1145 Given that the value does not depend on the instance, it is better to use a sta tic class variable.
1017 An instance getter for it can always be defined manually if desired. 1146 An instance getter for it can always be defined manually if desired.
(...skipping 23 matching lines...) Expand all
1041 %A non-final instance variable declaration of the form \code{\VAR{} $v$;} or th e form \code{\VAR{} $v$ = $e$;} always induces an implicit setter function wi th signature 1170 %A non-final instance variable declaration of the form \code{\VAR{} $v$;} or th e form \code{\VAR{} $v$ = $e$;} always induces an implicit setter function wi th signature
1042 1171
1043 %\SET{} $v=(x)$ 1172 %\SET{} $v=(x)$
1044 1173
1045 %whose execution sets the value of $v$ to the incoming argument $x$. 1174 %whose execution sets the value of $v$ to the incoming argument $x$.
1046 1175
1047 % It is a compile-time error/warning if a class $C$ declares a final instance va riable $v$ and $C$ inherits a setter $v=$. 1176 % It is a compile-time error/warning if a class $C$ declares a final instance va riable $v$ and $C$ inherits a setter $v=$.
1048 1177
1049 1178
1050 \subsection{Constructors} 1179 \subsection{Constructors}
1051 \label{constructors} 1180 \LMLabel{constructors}
1052 1181
1182 \LMHash{}
1053 A {\em constructor} is a special function that is used in instance creation expr essions (\ref{instanceCreation}) to produce objects. Constructors may be generat ive (\ref{generativeConstructors}) or they may be factories (\ref{factories}). 1183 A {\em constructor} is a special function that is used in instance creation expr essions (\ref{instanceCreation}) to produce objects. Constructors may be generat ive (\ref{generativeConstructors}) or they may be factories (\ref{factories}).
1054 1184
1185 \LMHash{}
1055 A {\em constructor name} always begins with the name of its immediately enclosin g class, and may optionally be followed by a dot and an identifier $id$. It is a compile-time error if $id$ is the name of a member declared in the immediately enclosing class. It is a compile-time error if the name of a constructor is no t a constructor name. 1186 A {\em constructor name} always begins with the name of its immediately enclosin g class, and may optionally be followed by a dot and an identifier $id$. It is a compile-time error if $id$ is the name of a member declared in the immediately enclosing class. It is a compile-time error if the name of a constructor is no t a constructor name.
1056 1187
1057 1188
1058 % In what scope do constructors go? The simple names of named constructors go i n the static scope of the class. Unnamed ones go nowhere, but we use the class n ame to refer to them; the class name could also in the static scope of the class as well to prevent weird errors, or we could ban it explicitly and avoiding dup lication. Similarly, the instance scope could contain the constructor names and class name, or we could have special rules to prevent collisions between instanc e members and constructors or the class. 1189 % In what scope do constructors go? The simple names of named constructors go i n the static scope of the class. Unnamed ones go nowhere, but we use the class n ame to refer to them; the class name could also in the static scope of the class as well to prevent weird errors, or we could ban it explicitly and avoiding dup lication. Similarly, the instance scope could contain the constructor names and class name, or we could have special rules to prevent collisions between instanc e members and constructors or the class.
1059 1190
1060 % The enclosing scope of a generative constructor is the instance scope of the c lass in which it is declared (but what about redirecting?) 1191 % The enclosing scope of a generative constructor is the instance scope of the c lass in which it is declared (but what about redirecting?)
1061 1192
1193 \LMHash{}
1062 Iff no constructor is specified for a class $C$, it implicitly has a default con structor \code{C() : \SUPER{}() \{\}}, unless $C$ is class \code{Object}. 1194 Iff no constructor is specified for a class $C$, it implicitly has a default con structor \code{C() : \SUPER{}() \{\}}, unless $C$ is class \code{Object}.
1063 1195
1064 \subsubsection{Generative Constructors} 1196 \subsubsection{Generative Constructors}
1065 \label{generativeConstructors} 1197 \LMLabel{generativeConstructors}
1066 1198
1199 \LMHash{}
1067 A {\em generative constructor} consists of a constructor name, a constructor par ameter list, and either a redirect clause or an initializer list and an optiona l body. 1200 A {\em generative constructor} consists of a constructor name, a constructor par ameter list, and either a redirect clause or an initializer list and an optiona l body.
1068 1201
1069 \begin{grammar} 1202 \begin{grammar}
1070 {\bf constructorSignature:} 1203 {\bf constructorSignature:}
1071 identifier (`{\escapegrammar .}' identifier)? formalParameterList 1204 identifier (`{\escapegrammar .}' identifier)? formalParameterList
1072 . 1205 .
1073 \end{grammar} 1206 \end{grammar}
1074 1207
1208 \LMHash{}
1075 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 \code{id} is the name of an instance variable of the immediately enclosing class. It is a compile-time e rror if \code{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 oth er than a non-redirecting generative constructor. 1209 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 \code{id} is the name of an instance variable of the immediately enclosing class. It is a compile-time e rror if \code{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 oth er than a non-redirecting generative constructor.
1076 1210
1211 \LMHash{}
1077 If an explicit type is attached to the initializing formal, that is its static t ype. Otherwise, the type of an initializing formal named \code{id} is $T_{id}$, where $T_{id}$ is the type of the field named \code{id} in the immediately enclo sing class. It is a static warning if the static type of \code{id} is not assign able to $T_{id}$. 1212 If an explicit type is attached to the initializing formal, that is its static t ype. Otherwise, the type of an initializing formal named \code{id} is $T_{id}$, where $T_{id}$ is the type of the field named \code{id} in the immediately enclo sing class. It is a static warning if the static type of \code{id} is not assign able to $T_{id}$.
1078 1213
1214 \LMHash{}
1079 Using an initializing formal \code{\THIS{}.id} in a formal parameter list does n ot introduce a formal parameter name into the scope of the constructor. However, the initializing formal does effect the type of the constructor function exactl y as if a formal parameter named \code{id} of the same type were introduced in the same position. 1215 Using an initializing formal \code{\THIS{}.id} in a formal parameter list does n ot introduce a formal parameter name into the scope of the constructor. However, the initializing formal does effect the type of the constructor function exactl y as if a formal parameter named \code{id} of the same type were introduced in the same position.
1080 1216
1217 \LMHash{}
1081 Initializing formals are executed during the execution of generative constructor s detailed below. Executing an initializing formal \code{\THIS{}.id} causes the field \code{id} of the immediately surrounding class to be assigned the value o f the corresponding actual parameter, unless $id$ is a final variable that has a lready been initialized, in which case a runtime error occurs. 1218 Initializing formals are executed during the execution of generative constructor s detailed below. Executing an initializing formal \code{\THIS{}.id} causes the field \code{id} of the immediately surrounding class to be assigned the value o f the corresponding actual parameter, unless $id$ is a final variable that has a lready been initialized, in which case a runtime error occurs.
1082 1219
1083 1220
1084 \commentary{ 1221 \commentary{
1085 The above rule allows initializing formals to be used as optional parameters: 1222 The above rule allows initializing formals to be used as optional parameters:
1086 } 1223 }
1087 1224
1088 \begin{dartCode} 1225 \begin{dartCode}
1089 class A \{ 1226 class A \{
1090 int x; 1227 int x;
1091 A([this.x]); 1228 A([this.x]);
1092 \} 1229 \}
1093 \end{dartCode} 1230 \end{dartCode}
1094 1231
1095 \commentary{is legal, and has the same effect as} 1232 \commentary{is legal, and has the same effect as}
1096 1233
1097 \begin{dartCode} 1234 \begin{dartCode}
1098 class A \{ 1235 class A \{
1099 int x; 1236 int x;
1100 A([int x]): this.x = x; 1237 A([int x]): this.x = x;
1101 \} 1238 \}
1102 \end{dartCode} 1239 \end{dartCode}
1103 1240
1241 \LMHash{}
1104 A {\em fresh instance} is an instance whose identity is distinct from any previ ously allocated instance of its class. A generative constructor always operates on a fresh instance of its immediately enclosing class. 1242 A {\em fresh instance} is an instance whose identity is distinct from any previ ously allocated instance of its class. A generative constructor always operates on a fresh instance of its immediately enclosing class.
1105 1243
1106 \commentary{ 1244 \commentary{
1107 The above holds if the constructor is actually run, as it is by \NEW{}. If a con structor $c$ is referenced by \CONST{}, $c$ may not be run; instead, a canonical object may be looked up. See the section on instance creation (\ref{instanceCre ation}). 1245 The above holds if the constructor is actually run, as it is by \NEW{}. If a con structor $c$ is referenced by \CONST{}, $c$ may not be run; instead, a canonical object may be looked up. See the section on instance creation (\ref{instanceCre ation}).
1108 } 1246 }
1109 1247
1248 \LMHash{}
1110 If a generative constructor $c$ is not a redirecting constructor and no body is provided, then $c$ implicitly has an empty body \code{\{\}}. 1249 If a generative constructor $c$ is not a redirecting constructor and no body is provided, then $c$ implicitly has an empty body \code{\{\}}.
1111 1250
1112 1251
1113 \paragraph{Redirecting Constructors} 1252 \paragraph{Redirecting Constructors}
1114 \label{redirectingConstructors} 1253 \LMLabel{redirectingConstructors}
1115 1254
1255 \LMHash{}
1116 A generative constructor may be {\em redirecting}, in which case its only action is to invoke another generative constructor. A redirecting constructor has no body; instead, it has a redirect clause that specifies which constructor the inv ocation is redirected to, and with what arguments. 1256 A generative constructor may be {\em redirecting}, in which case its only action is to invoke another generative constructor. A redirecting constructor has no body; instead, it has a redirect clause that specifies which constructor the inv ocation is redirected to, and with what arguments.
1117 1257
1118 \begin{grammar} 1258 \begin{grammar}
1119 {\bf redirection:} 1259 {\bf redirection:}
1120 `{\escapegrammar :}' \THIS{} (`{\escapegrammar .}' identifier)? arguments 1260 `{\escapegrammar :}' \THIS{} (`{\escapegrammar .}' identifier)? arguments
1121 . 1261 .
1122 \end{grammar} 1262 \end{grammar}
1123 1263
1124 % Need to specify exactly how executing a redirecting constructor works 1264 % Need to specify exactly how executing a redirecting constructor works
1125 1265
1126 1266
1127 %\Q{We now have generative constructors with no bodies as well.} 1267 %\Q{We now have generative constructors with no bodies as well.}
1128 1268
1129 \paragraph{Initializer Lists} 1269 \paragraph{Initializer Lists}
1130 1270
1271 \LMHash{}
1131 An initializer list begins with a colon, and consists of a comma-separated list of individual {\em initializers}. There are two kinds of initializers. 1272 An initializer list begins with a colon, and consists of a comma-separated list of individual {\em initializers}. There are two kinds of initializers.
1132 \begin{itemize} 1273 \begin{itemize}
1133 \item A {\em superinitializer} identifies a {\em superconstructor} - that is, a specific constructor of the superclass. Execution of the superinitializer caus es the initializer list of the superconstructor to be executed. 1274 \item A {\em superinitializer} identifies a {\em superconstructor} - that is, a specific constructor of the superclass. Execution of the superinitializer caus es the initializer list of the superconstructor to be executed.
1134 1275
1135 \item An {\em instance variable initializer} assigns a value to an individual in stance variable. 1276 \item An {\em instance variable initializer} assigns a value to an individual in stance variable.
1136 \end{itemize} 1277 \end{itemize}
1137 1278
1138 \begin{grammar} 1279 \begin{grammar}
1139 {\bf initializers:} 1280 {\bf initializers:}
1140 `{\escapegrammar :}' superCallOrFieldInitializer (`,' superCallOrFieldInit ializer)* 1281 `{\escapegrammar :}' superCallOrFieldInitializer (`,' superCallOrFieldInit ializer)*
1141 . 1282 .
1142 1283
1143 1284
1144 {\bf superCallOrFieldInitializer:}\SUPER{} arguments; 1285 {\bf superCallOrFieldInitializer:}\SUPER{} arguments;
1145 \SUPER{} `{\escapegrammar .}' identifier arguments; 1286 \SUPER{} `{\escapegrammar .}' identifier arguments;
1146 fieldInitializer 1287 fieldInitializer
1147 . 1288 .
1148 1289
1149 {\bf fieldInitializer:} 1290 {\bf fieldInitializer:}
1150 (\THIS{} `{\escapegrammar .}')? identifier `=' conditionalExpression casca deSection* 1291 (\THIS{} `{\escapegrammar .}')? identifier `=' conditionalExpression casca deSection*
1151 . 1292 .
1152 1293
1153 \end{grammar} 1294 \end{grammar}
1154 1295
1296 \LMHash{}
1155 Let $k$ be a generative constructor. Then $k$ may include at most one superini tializer in its initializer list or a compile-time error occurs. If no superinit ializer is provided, an implicit superinitializer of the form \SUPER{}() is adde d at the end of $k$'s initializer list, unless the enclosing class is class \cod e{Object}. It is a compile-time error if more than one initializer corresponding to a given instance variable appears in $k$'s initializer list. It is a compile -time error if $k$'s initializer list contains an initializer for a variable tha t is initialized by means of an initializing formal of $k$. % It is a compile-ti me error if $k$'s initializer list contains an initializer for a final variable $f$ whose declaration includes an initialization expression. 1297 Let $k$ be a generative constructor. Then $k$ may include at most one superini tializer in its initializer list or a compile-time error occurs. If no superinit ializer is provided, an implicit superinitializer of the form \SUPER{}() is adde d at the end of $k$'s initializer list, unless the enclosing class is class \cod e{Object}. It is a compile-time error if more than one initializer corresponding to a given instance variable appears in $k$'s initializer list. It is a compile -time error if $k$'s initializer list contains an initializer for a variable tha t is initialized by means of an initializing formal of $k$. % It is a compile-ti me error if $k$'s initializer list contains an initializer for a final variable $f$ whose declaration includes an initialization expression.
1156 1298
1299 \LMHash{}
1157 Each final instance variable $f$ declared in the immediately enclosing class mus t have an initializer in $k$'s initializer list unless it has already been initi alized by one of the following means: 1300 Each final instance variable $f$ declared in the immediately enclosing class mus t have an initializer in $k$'s initializer list unless it has already been initi alized by one of the following means:
1158 \begin{itemize} 1301 \begin{itemize}
1159 \item Initialization at the declaration of $f$. 1302 \item Initialization at the declaration of $f$.
1160 \item Initialization by means of an initializing formal of $k$. 1303 \item Initialization by means of an initializing formal of $k$.
1161 \end{itemize} 1304 \end{itemize}
1162 1305
1163 or a static warning occurs. It is a compile-time error if $k$'s initializer list contains an initializer for a variable that is not an instance variable declare d in the immediately surrounding class. 1306 or a static warning occurs. It is a compile-time error if $k$'s initializer list contains an initializer for a variable that is not an instance variable declare d in the immediately surrounding class.
1164 1307
1165 1308
1166 \commentary{The initializer list may of course contain an initializer for any instance variable declared by the immediately surrounding class, even if it is n ot final. 1309 \commentary{The initializer list may of course contain an initializer for any instance variable declared by the immediately surrounding class, even if it is n ot final.
1167 } 1310 }
1168 1311
1312 \LMHash{}
1169 It is a compile-time error if a generative constructor of class \code{Object} includes a superinitializer. 1313 It is a compile-time error if a generative constructor of class \code{Object} includes a superinitializer.
1170 1314
1315 \LMHash{}
1171 Execution of a generative constructor $k$ is always done with respect to a set o f bindings for its formal parameters and with \THIS{} bound to a fresh instance $i$ and the type parameters of the immediately enclosing class bound to a set o f actual type arguments $V_1, \ldots , V_m$. 1316 Execution of a generative constructor $k$ is always done with respect to a set o f bindings for its formal parameters and with \THIS{} bound to a fresh instance $i$ and the type parameters of the immediately enclosing class bound to a set o f actual type arguments $V_1, \ldots , V_m$.
1172 1317
1173 \commentary{These bindings are usually determined by the instance creation expre ssion that invoked the constructor (directly or indirectly). However, they may a lso be determined by a reflective call,. 1318 \commentary{These bindings are usually determined by the instance creation expre ssion that invoked the constructor (directly or indirectly). However, they may a lso be determined by a reflective call,.
1174 } 1319 }
1175 1320
1321 \LMHash{}
1176 If $k$ is redirecting then its redirect clause has the form 1322 If $k$ is redirecting then its redirect clause has the form
1177 1323
1178 \THIS{}$.g(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 1324 \THIS{}$.g(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
1179 1325
1180 where $g$ identifies another generative constructor of the immediately surround ing class. Then execution of $k$ proceeds by evaluating the argument list $(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, and then executing $g$ with respect to the bindings resulting from the evaluation of $(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ and with \THIS{} bound to $i$ and the type parameters of the immediately enclosing class bound to $V_1, \ ldots , V_m$. 1326 where $g$ identifies another generative constructor of the immediately surround ing class. Then execution of $k$ proceeds by evaluating the argument list $(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, and then executing $g$ with respect to the bindings resulting from the evaluation of $(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ and with \THIS{} bound to $i$ and the type parameters of the immediately enclosing class bound to $V_1, \ ldots , V_m$.
1181 1327
1328 \LMHash{}
1182 Otherwise, execution proceeds as follows: 1329 Otherwise, execution proceeds as follows:
1183 1330
1331 \LMHash{}
1184 %First, a fresh instance (\ref{generativeConstructors}) $i$ of the immediately e nclosing class is allocated. Next, the instance variable declarations of the im mediately enclosing class are visited in the order they appear in the program te xt. For each such declaration $d$, if $d$ has the form \code{$finalConstVarOrTy pe$ $v$ = $e$; } then the instance variable $v$ of $i$ is bound to the value of $e$ (which is necessarily a compile-time constant). 1332 %First, a fresh instance (\ref{generativeConstructors}) $i$ of the immediately e nclosing class is allocated. Next, the instance variable declarations of the im mediately enclosing class are visited in the order they appear in the program te xt. For each such declaration $d$, if $d$ has the form \code{$finalConstVarOrTy pe$ $v$ = $e$; } then the instance variable $v$ of $i$ is bound to the value of $e$ (which is necessarily a compile-time constant).
1185 %Next, a 1333 %Next, a
1186 Any initializing formals declared in $k$'s parameter list are executed in the or der they appear in the program text. 1334 Any initializing formals declared in $k$'s parameter list are executed in the or der they appear in the program text.
1187 % In fact, this order is unobservable; this could be done any time prior to runn ing the body, since 1335 % In fact, this order is unobservable; this could be done any time prior to runn ing the body, since
1188 % these only effect \THIS{}. 1336 % these only effect \THIS{}.
1189 Then, $k$'s initializers are executed in the order they appear in the program. 1337 Then, $k$'s initializers are executed in the order they appear in the program.
1190 1338
1191 \rationale {We could observe the order by side effecting external routines call ed. So we need to specify the order.} 1339 \rationale {We could observe the order by side effecting external routines call ed. So we need to specify the order.}
1192 1340
1341 \LMHash{}
1193 After all the initializers have completed, the body of $k$ is executed in a sc ope where \THIS{} is bound to $i$. Execution of the body begins with execution o f the body of the superconstructor with \THIS{} bound to $i$, the type paramete rs of the immediately enclosing class bound to a set of actual type arguments $V _1, \ldots , V_m$ and the formal parameters bindings determined by the argument list of the superinitializer of $k$. 1342 After all the initializers have completed, the body of $k$ is executed in a sc ope where \THIS{} is bound to $i$. Execution of the body begins with execution o f the body of the superconstructor with \THIS{} bound to $i$, the type paramete rs of the immediately enclosing class bound to a set of actual type arguments $V _1, \ldots , V_m$ and the formal parameters bindings determined by the argument list of the superinitializer of $k$.
1194 1343
1195 \rationale{ 1344 \rationale{
1196 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 being invoked in the initializer. 1345 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 being invoked in the initializer.
1197 } 1346 }
1198 1347
1348 \LMHash{}
1199 Execution of an initializer of the form \code{\THIS{}.$v$ = $e$} proceeds as fol lows: 1349 Execution of an initializer of the form \code{\THIS{}.$v$ = $e$} proceeds as fol lows:
1200 1350
1351 \LMHash{}
1201 First, the expression $e$ is evaluated to an object $o$. Then, the instance vari able $v$ of the object denoted by \THIS{} is bound to $o$, unless $v$ is a final variable that has already been initialized, in which case a runtime error occur s. In checked mode, it is a dynamic type error if $o$ is not \NULL{} and the int erface of the class of $o$ is not a subtype of the actual type of the field $v$. 1352 First, the expression $e$ is evaluated to an object $o$. Then, the instance vari able $v$ of the object denoted by \THIS{} is bound to $o$, unless $v$ is a final variable that has already been initialized, in which case a runtime error occur s. In checked mode, it is a dynamic type error if $o$ is not \NULL{} and the int erface of the class of $o$ is not a subtype of the actual type of the field $v$.
1202 1353
1354 \LMHash{}
1203 An initializer of the form \code{$v$ = $e$} is equivalent to an initializer of t he form \code{\THIS{}.$v$ = $e$}. 1355 An initializer of the form \code{$v$ = $e$} is equivalent to an initializer of t he form \code{\THIS{}.$v$ = $e$}.
1204 1356
1357 \LMHash{}
1205 Execution of a superinitializer of the form 1358 Execution of a superinitializer of the form
1206 1359
1207 \SUPER{}$(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$ 1360 \SUPER{}$(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$
1208 1361
1209 (respectively \SUPER{}$.id(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$ 1362 (respectively \SUPER{}$.id(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$
1210 1363
1211 proceeds as follows: 1364 proceeds as follows:
1212 1365
1366 \LMHash{}
1213 First, the argument list $(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$ is evaluated. 1367 First, the argument list $(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$ is evaluated.
1214 1368
1369 \LMHash{}
1215 Let $C$ be the class in which the superinitializer appears and let $S$ be the su perclass of $C$. If $S$ is generic (\ref{generics}), let $U_1, , \ldots, U_m$ b e the actual type arguments passed to $S$ in the superclass clause of $C$. 1370 Let $C$ be the class in which the superinitializer appears and let $S$ be the su perclass of $C$. If $S$ is generic (\ref{generics}), let $U_1, , \ldots, U_m$ b e the actual type arguments passed to $S$ in the superclass clause of $C$.
1216 1371
1372 \LMHash{}
1217 Then, the initializer list of the constructor $S$ (respectively $S.id$) is execu ted with respect to the bindings that resulted from the evaluation of the argume nt list, with \THIS{} bound to the current binding of \THIS{}, and the type pa rameters (if any) of class $S$ bound to the current bindings of $U_1, , \ldots, U_m$. 1373 Then, the initializer list of the constructor $S$ (respectively $S.id$) is execu ted with respect to the bindings that resulted from the evaluation of the argume nt list, with \THIS{} bound to the current binding of \THIS{}, and the type pa rameters (if any) of class $S$ bound to the current bindings of $U_1, , \ldots, U_m$.
1218 1374
1375 \LMHash{}
1219 It is a compile-time error if class $S$ does not declare a generative constructo r named $S$ (respectively $S.id$). 1376 It is a compile-time error if class $S$ does not declare a generative constructo r named $S$ (respectively $S.id$).
1220 1377
1221 \subsubsection{Factories} 1378 \subsubsection{Factories}
1222 \label{factories} 1379 \LMLabel{factories}
1223 1380
1381 \LMHash{}
1224 A {\em factory} is a constructor prefaced by the built-in identifier (\ref{iden tifierReference}) \FACTORY{}. 1382 A {\em factory} is a constructor prefaced by the built-in identifier (\ref{iden tifierReference}) \FACTORY{}.
1225 1383
1226 \begin{grammar} 1384 \begin{grammar}
1227 {\bf factoryConstructorSignature:} 1385 {\bf factoryConstructorSignature:}
1228 \FACTORY{} identifier (`{\escapegrammar .}' identifier)? formalParameter List 1386 \FACTORY{} identifier (`{\escapegrammar .}' identifier)? formalParameter List
1229 . 1387 .
1230 \end{grammar} 1388 \end{grammar}
1231 1389
1232 1390
1233 %The enclosing scope of a factory constructor is the static scope \ref{} of the class in which it is declared. 1391 %The enclosing scope of a factory constructor is the static scope \ref{} of the class in which it is declared.
1234 1392
1393 \LMHash{}
1235 The {\em return type} of a factory whose signature is of the form \FACTORY{} $M$ or the form \FACTORY{} $M.id$ is $M$ if $M$ is not a generic type; otherwise th e return type is $M <T_1, \ldots, T_n>$ where $T_1, \ldots, T_n$ are the type p arameters of the enclosing class 1394 The {\em return type} of a factory whose signature is of the form \FACTORY{} $M$ or the form \FACTORY{} $M.id$ is $M$ if $M$ is not a generic type; otherwise th e return type is $M <T_1, \ldots, T_n>$ where $T_1, \ldots, T_n$ are the type p arameters of the enclosing class
1236 1395
1396 \LMHash{}
1237 It is a compile-time error if $M$ is not the name of the immediately enclosing c lass. 1397 It is a compile-time error if $M$ is not the name of the immediately enclosing c lass.
1238 1398
1399 \LMHash{}
1239 In checked mode, it is a dynamic type error if a factory returns a non-null obje ct whose type is not a subtype of its actual (\ref{actualTypeOfADeclaration}) re turn type. 1400 In checked mode, it is a dynamic type error if a factory returns a non-null obje ct whose type is not a subtype of its actual (\ref{actualTypeOfADeclaration}) re turn type.
1240 1401
1241 \rationale{It seems useless to allow a factory to return null. But it is more un iform to allow it, as the rules currently do.} 1402 \rationale{It seems useless to allow a factory to return null. But it is more un iform to allow it, as the rules currently do.}
1242 1403
1243 \rationale{Factories address classic weaknesses associated with constructors in other languages. 1404 \rationale{Factories address classic weaknesses associated with constructors in other languages.
1244 Factories can produce instances that are not freshly allocated: they can come fr om a cache. Likewise, factories can return instances of different classes. 1405 Factories can produce instances that are not freshly allocated: they can come fr om a cache. Likewise, factories can return instances of different classes.
1245 1406
1246 } 1407 }
1247 1408
1248 \paragraph{Redirecting Factory Constructors} 1409 \paragraph{Redirecting Factory Constructors}
1249 \label{redirectingFactoryConstructors} 1410 \LMLabel{redirectingFactoryConstructors}
1250 1411
1412 \LMHash{}
1251 A {\em redirecting factory constructor} specifies a call to a constructor of ano ther class that is to be used whenever the redirecting constructor is called. 1413 A {\em redirecting factory constructor} specifies a call to a constructor of ano ther class that is to be used whenever the redirecting constructor is called.
1252 1414
1253 \begin{grammar} 1415 \begin{grammar}
1254 {\bf redirectingFactoryConstructorSignature:} 1416 {\bf redirectingFactoryConstructorSignature:}
1255 \CONST{}? \FACTORY{} identifier (`{\escapegrammar .}' identifier)? formalP arameterList `=' type (`{\escapegrammar .}' identifier)? 1417 \CONST{}? \FACTORY{} identifier (`{\escapegrammar .}' identifier)? formalP arameterList `=' type (`{\escapegrammar .}' identifier)?
1256 . 1418 .
1257 \end{grammar} 1419 \end{grammar}
1258 1420
1421 \LMHash{}
1259 Calling a redirecting factory constructor $k$ causes the constructor $k^\prime$ denoted by $type$ (respectively, $type.identifier$) to be called with the actual arguments passed to $k$, and returns the result of $k^\prime$ as the result of $k$. The resulting constructor call is governed by the same rules as an instanc e creation expression using \NEW{} (\ref{instanceCreation}). 1422 Calling a redirecting factory constructor $k$ causes the constructor $k^\prime$ denoted by $type$ (respectively, $type.identifier$) to be called with the actual arguments passed to $k$, and returns the result of $k^\prime$ as the result of $k$. The resulting constructor call is governed by the same rules as an instanc e creation expression using \NEW{} (\ref{instanceCreation}).
1260 1423
1261 \commentary{ 1424 \commentary{
1262 It follows that if $type$ or $type.id$ are not defined, or do not refer to a cla ss or constructor, a dynamic error occurs, as with any other undefined construct or call. The same holds if $k$ is called with fewer required parameters or more positional parameters than $k^\prime$ expects, or if $k$ is called with a named parameter that is not declared by $k^\prime$. 1425 It follows that if $type$ or $type.id$ are not defined, or do not refer to a cla ss or constructor, a dynamic error occurs, as with any other undefined construct or call. The same holds if $k$ is called with fewer required parameters or more positional parameters than $k^\prime$ expects, or if $k$ is called with a named parameter that is not declared by $k^\prime$.
1263 } 1426 }
1264 1427
1428 \LMHash{}
1265 It is a compile-time error if $k$ explicitly specifies a default value for an op tional parameter.\commentary{ 1429 It is a compile-time error if $k$ explicitly specifies a default value for an op tional parameter.\commentary{
1266 Default values specified in $k$ would be ignored, since it is the {\em actual} p arameters that are passed to $k^\prime$. Hence, default values are disallowed. 1430 Default values specified in $k$ would be ignored, since it is the {\em actual} p arameters that are passed to $k^\prime$. Hence, default values are disallowed.
1267 } 1431 }
1268 1432
1433 \LMHash{}
1269 It is a run-time error if a redirecting factory constructor redirects to itself, either directly or indirectly via a sequence of redirections. %does not redirec t to a non-redirecting factory constructor or to a generative constructor in a f inite number of steps. 1434 It is a run-time error if a redirecting factory constructor redirects to itself, either directly or indirectly via a sequence of redirections. %does not redirec t to a non-redirecting factory constructor or to a generative constructor in a f inite number of steps.
1270 1435
1271 % Make this a runtime error so deferred loading works 1436 % Make this a runtime error so deferred loading works
1272 1437
1273 \rationale{ 1438 \rationale{
1274 If a redirecting factory $F_1$ redirects to another redirecting factory $F_2$ an d $F_2$ then redirects to $F_1$, then both $F_1$ and $F_2$ are ill-defined. Such cycles are therefore illegal. 1439 If a redirecting factory $F_1$ redirects to another redirecting factory $F_2$ an d $F_2$ then redirects to $F_1$, then both $F_1$ and $F_2$ are ill-defined. Such cycles are therefore illegal.
1275 } 1440 }
1276 1441
1277 1442
1443 \LMHash{}
1278 It is a static warning if $type$ does not denote a class accessible in the curre nt scope; if $type$ does denote such a class $C$ it is a static warning if the r eferenced constructor (be it $type$ or $type.id$) is not a constructor of $C$. 1444 It is a static warning if $type$ does not denote a class accessible in the curre nt scope; if $type$ does denote such a class $C$ it is a static warning if the r eferenced constructor (be it $type$ or $type.id$) is not a constructor of $C$.
1279 1445
1280 \commentary{ 1446 \commentary{
1281 Note that it is not possible to modify the arguments being passed to $k'$. 1447 Note that it is not possible to modify the arguments being passed to $k'$.
1282 } 1448 }
1283 % but we have the same issue with other redirecting constructors, no?) 1449 % but we have the same issue with other redirecting constructors, no?)
1284 \rationale{ 1450 \rationale{
1285 At first glance, one might think that ordinary factory constructors could simply create instances of other classes and return them, and that redirecting factori es are unnecessary. However, redirecting factories have several advantages: 1451 At first glance, one might think that ordinary factory constructors could simply create instances of other classes and return them, and that redirecting factori es are unnecessary. However, redirecting factories have several advantages:
1286 \begin{itemize} 1452 \begin{itemize}
1287 \item An abstract class may provide a constant constructor that utilizes the con stant constructor of another class. 1453 \item An abstract class may provide a constant constructor that utilizes the con stant constructor of another class.
(...skipping 21 matching lines...) Expand all
1309 1475
1310 %\CLASS{} A$<$T$>${ 1476 %\CLASS{} A$<$T$>${
1311 % \FACTORY{} A.idw(w) $=>$ F$<$T$>$.idw(w); 1477 % \FACTORY{} A.idw(w) $=>$ F$<$T$>$.idw(w);
1312 %// illegal - cannot pass type parameter to static method 1478 %// illegal - cannot pass type parameter to static method
1313 % \FACTORY{} A.idx(x) $=> \NEW{} $F$<$T$>$.idx(x); // works, but allocates a gr atuitous instance of F 1479 % \FACTORY{} A.idx(x) $=> \NEW{} $F$<$T$>$.idx(x); // works, but allocates a gr atuitous instance of F
1314 % \FACTORY{} A.idy(y) = Y$<$T$>$; // works 1480 % \FACTORY{} A.idy(y) = Y$<$T$>$; // works
1315 % \FACTORY{} A.idz(z) $=>$ F.idz(z); // wrong - returns Z$<$Dynamic$>$; no way to pass type argument 1481 % \FACTORY{} A.idz(z) $=>$ F.idz(z); // wrong - returns Z$<$Dynamic$>$; no way to pass type argument
1316 } 1482 }
1317 %\end{dartCode} 1483 %\end{dartCode}
1318 1484
1485 \LMHash{}
1319 It is a compile-time error if $k$ is prefixed with the \CONST{} modifier but $k^ \prime$ is not a constant constructor (\ref{constantConstructors}). 1486 It is a compile-time error if $k$ is prefixed with the \CONST{} modifier but $k^ \prime$ is not a constant constructor (\ref{constantConstructors}).
1320 1487
1488 \LMHash{}
1321 It is a static warning if the function type of $k^\prime$ is not a subtype of th e type of $k$. 1489 It is a static warning if the function type of $k^\prime$ is not a subtype of th e type of $k$.
1322 1490
1323 \commentary{ 1491 \commentary{
1324 This implies that the resulting object conforms to the interface of the immedia tely enclosing class of $k$. 1492 This implies that the resulting object conforms to the interface of the immedia tely enclosing class of $k$.
1325 } 1493 }
1326 1494
1495 \LMHash{}
1327 It is a static type warning if any of the type arguments to $k^\prime$ are not s ubtypes of the bounds of the corresponding formal type parameters of $type$. 1496 It is a static type warning if any of the type arguments to $k^\prime$ are not s ubtypes of the bounds of the corresponding formal type parameters of $type$.
1328 1497
1329 1498
1330 \subsubsection{Constant Constructors} 1499 \subsubsection{Constant Constructors}
1331 \label{constantConstructors} 1500 \LMLabel{constantConstructors}
1332 1501
1502 \LMHash{}
1333 A {\em constant constructor} may be used to create compile-time constant (\ref{ constants}) objects. A constant constructor is prefixed by the reserved word \CO NST{}. 1503 A {\em constant constructor} may be used to create compile-time constant (\ref{ constants}) objects. A constant constructor is prefixed by the reserved word \CO NST{}.
1334 1504
1335 \begin{grammar} 1505 \begin{grammar}
1336 {\bf constantConstructorSignature:} 1506 {\bf constantConstructorSignature:}
1337 \CONST{} qualified formalParameterList 1507 \CONST{} qualified formalParameterList
1338 . 1508 .
1339 \end{grammar} 1509 \end{grammar}
1340 1510
1341 1511
1342 %\commentary{Spell out subtleties: a constant constructor call within the initia lizer of a constant constructor is treated as a ordinary constructor call (a ne w), because the arguments cannot be assumed constant anymore. In practice, this means two versions are compiled and analyzed. One for new and one for const.} 1512 %\commentary{Spell out subtleties: a constant constructor call within the initia lizer of a constant constructor is treated as a ordinary constructor call (a ne w), because the arguments cannot be assumed constant anymore. In practice, this means two versions are compiled and analyzed. One for new and one for const.}
1343 1513
1344 % \Q{How to specify?} 1514 % \Q{How to specify?}
1345 1515
1346 \commentary{All the work of a constant constructor must be handled via its initi alizers.} 1516 \commentary{All the work of a constant constructor must be handled via its initi alizers.}
1347 1517
1518 \LMHash{}
1348 It is a compile-time error if a constant constructor is declared by a class that has a non-final instance variable. 1519 It is a compile-time error if a constant constructor is declared by a class that has a non-final instance variable.
1349 1520
1350 \commentary{ 1521 \commentary{
1351 The above refers to both locally declared and inherited instance variables. 1522 The above refers to both locally declared and inherited instance variables.
1352 } 1523 }
1353 1524
1525 \LMHash{}
1354 It is a compile-time error if a constant constructor is declared by a class $C$ if any instance variable declared in $C$ is initialized with an expression that is not a constant expression. 1526 It is a compile-time error if a constant constructor is declared by a class $C$ if any instance variable declared in $C$ is initialized with an expression that is not a constant expression.
1355 1527
1356 \commentary { 1528 \commentary {
1357 A superclass of $C$ cannot declare such an initializer either, because it must n ecessarily declare constant constructor as well (unless it is \code{Object}, whi ch declares no instance variables). 1529 A superclass of $C$ cannot declare such an initializer either, because it must n ecessarily declare constant constructor as well (unless it is \code{Object}, whi ch declares no instance variables).
1358 } 1530 }
1359 1531
1532 \LMHash{}
1360 The superinitializer that appears, explicitly or implicitly, in the initializer list of a constant constructor must specify a constant constructor of the superc lass of the immediately enclosing class or a compile-time error occurs. 1533 The superinitializer that appears, explicitly or implicitly, in the initializer list of a constant constructor must specify a constant constructor of the superc lass of the immediately enclosing class or a compile-time error occurs.
1361 1534
1535 \LMHash{}
1362 Any expression that appears within the initializer list of a constant constructo r must be a potentially constant expression, or a compile-time error occurs. 1536 Any expression that appears within the initializer list of a constant constructo r must be a potentially constant expression, or a compile-time error occurs.
1363 1537
1538 \LMHash{}
1364 A {\em potentially constant expression} is an expression $e$ that would be a val id constant expression if all formal parameters of $e$'s immediately enclosing c onstant constructor were treated as compile-time constants that were guaranteed to evaluate to an integer, boolean or string value as required by their immediat ely enclosing superexpression. 1539 A {\em potentially constant expression} is an expression $e$ that would be a val id constant expression if all formal parameters of $e$'s immediately enclosing c onstant constructor were treated as compile-time constants that were guaranteed to evaluate to an integer, boolean or string value as required by their immediat ely enclosing superexpression.
1365 1540
1366 \commentary{ 1541 \commentary{
1367 Note that a parameter that is not used in a superexpression that is restricted t o certain types can be a constant of any type. For example} 1542 Note that a parameter that is not used in a superexpression that is restricted t o certain types can be a constant of any type. For example}
1368 1543
1369 \begin{dartCode} 1544 \begin{dartCode}
1370 \CLASS{} A \{ 1545 \CLASS{} A \{
1371 \FINAL{} m; 1546 \FINAL{} m;
1372 \CONST{} A(this.m); 1547 \CONST{} A(this.m);
1373 \} 1548 \}
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 \commentary{ 1592 \commentary{
1418 The problem is not that the assignments to \code{w} are not potentially constant ; they are. However, all these run afoul of the rules for constant lists (\ref{ lists}), maps (\ref{maps}) and objects (\ref{const}), all of which independently require their subexpressions to be constant expressions. 1593 The problem is not that the assignments to \code{w} are not potentially constant ; they are. However, all these run afoul of the rules for constant lists (\ref{ lists}), maps (\ref{maps}) and objects (\ref{const}), all of which independently require their subexpressions to be constant expressions.
1419 } 1594 }
1420 1595
1421 \rationale{ 1596 \rationale{
1422 All of the illegal constructors of \code{D} above could not be sensibly invoked via \NEW{}, because an expression that must be constant cannot depend on a forma l parameter, which may or may not be constant. In contrast, the legal examples m ake sense regardless of whether the constructor is invoked via \CONST{} or via \ NEW{}. 1597 All of the illegal constructors of \code{D} above could not be sensibly invoked via \NEW{}, because an expression that must be constant cannot depend on a forma l parameter, which may or may not be constant. In contrast, the legal examples m ake sense regardless of whether the constructor is invoked via \CONST{} or via \ NEW{}.
1423 1598
1424 Careful readers will of course worry about cases where the actual arguments to \ code{C()} are constants, but are not numeric. This is precluded by the following rule, combined with the rules for evaluating constant objects (\ref{const}). 1599 Careful readers will of course worry about cases where the actual arguments to \ code{C()} are constants, but are not numeric. This is precluded by the following rule, combined with the rules for evaluating constant objects (\ref{const}).
1425 } 1600 }
1426 1601
1602 \LMHash{}
1427 When invoked from a constant object expression, a constant constructor must thro w an exception if any of its actual parameters is a value that would prevent one of the potentially constant expressions within it from being a valid compile-ti me constant. 1603 When invoked from a constant object expression, a constant constructor must thro w an exception if any of its actual parameters is a value that would prevent one of the potentially constant expressions within it from being a valid compile-ti me constant.
1428 1604
1429 %Discuss External Constructors in ne subsubsection here 1605 %Discuss External Constructors in ne subsubsection here
1430 1606
1431 \subsection{Static Methods} 1607 \subsection{Static Methods}
1432 \label{staticMethods} 1608 \LMLabel{staticMethods}
1433 1609
1610 \LMHash{}
1434 {\em Static methods} are functions, other than getters or setters, whose declara tions are immediately contained within a class declaration and that are declared \STATIC{}. The static methods of a class $C$ are those static methods declared by $C$. 1611 {\em Static methods} are functions, other than getters or setters, whose declara tions are immediately contained within a class declaration and that are declared \STATIC{}. The static methods of a class $C$ are those static methods declared by $C$.
1435 1612
1613 \LMHash{}
1436 The effect of a static method declaration in class $C$ is to add an instance met hod with the same name and signature to the \code{Type} object for class $C$ tha t forwards (\ref{functionDeclarations}) to the static method. 1614 The effect of a static method declaration in class $C$ is to add an instance met hod with the same name and signature to the \code{Type} object for class $C$ tha t forwards (\ref{functionDeclarations}) to the static method.
1437 1615
1438 \rationale{ 1616 \rationale{
1439 Inheritance of static methods has little utility in Dart. Static methods cannot be overridden. Any required static function can be obtained from its declaring l ibrary, and there is no need to bring it into scope via inheritance. Experience shows that developers are confused by the idea of inherited methods that are not instance methods. 1617 Inheritance of static methods has little utility in Dart. Static methods cannot be overridden. Any required static function can be obtained from its declaring l ibrary, and there is no need to bring it into scope via inheritance. Experience shows that developers are confused by the idea of inherited methods that are not instance methods.
1440 1618
1441 Of course, the entire notion of static methods is debatable, but it is retained here because so many programmers are familiar with it. Dart static methods may b e seen as functions of the enclosing library. 1619 Of course, the entire notion of static methods is debatable, but it is retained here because so many programmers are familiar with it. Dart static methods may b e seen as functions of the enclosing library.
1442 } 1620 }
1443 1621
1622 \LMHash{}
1444 It is a static warning if a class $C$ declares a static method named $n$ and has a setter named $n=$. 1623 It is a static warning if a class $C$ declares a static method named $n$ and has a setter named $n=$.
1445 %It is a static warning if a class has a static method with the same name as a s tatic member of one of its superclasses. 1624 %It is a static warning if a class has a static method with the same name as a s tatic member of one of its superclasses.
1446 1625
1447 %\rationale{ 1626 %\rationale{
1448 %This last restriction makes classes more brittle with respect to changes in the class hierarchy. It stems from a general observation that shadowing of names in the same scope is questionable and should elicit a warning. 1627 %This last restriction makes classes more brittle with respect to changes in the class hierarchy. It stems from a general observation that shadowing of names in the same scope is questionable and should elicit a warning.
1449 %} 1628 %}
1450 %\commentary{ 1629 %\commentary{
1451 %There is no hiding of static methods, or of static variables. 1630 %There is no hiding of static methods, or of static variables.
1452 %} 1631 %}
1453 1632
1454 1633
1455 \subsection{Static Variables} 1634 \subsection{Static Variables}
1456 \label{staticVariables} 1635 \LMLabel{staticVariables}
1457 1636
1637 \LMHash{}
1458 {\em Static variables} are variables whose declarations are immediately containe d within a class declaration and that are declared \STATIC{}. The static variabl es of a class $C$ are those static variables declared by $C$. 1638 {\em Static variables} are variables whose declarations are immediately containe d within a class declaration and that are declared \STATIC{}. The static variabl es of a class $C$ are those static variables declared by $C$.
1459 1639
1460 %A static variable declaration of one of the forms \code{\STATIC{} $T$ $v$;}, \code{\STATIC{} $T$ $v$ = $e$;} , \code{\STATIC{} \CONST{} $T$ $v$ = $e$;} or \code{\STATIC{} \FINAL{} $T$ $v$ = $e$;} always induces an implicit static gette r function (\ref{getters}) with signature 1640 %A static variable declaration of one of the forms \code{\STATIC{} $T$ $v$;}, \code{\STATIC{} $T$ $v$ = $e$;} , \code{\STATIC{} \CONST{} $T$ $v$ = $e$;} or \code{\STATIC{} \FINAL{} $T$ $v$ = $e$;} always induces an implicit static gette r function (\ref{getters}) with signature
1461 1641
1462 %\STATIC{} $T$ \GET{} $v$ 1642 %\STATIC{} $T$ \GET{} $v$
1463 1643
1464 %whose invocation evaluates as described below (\ref{evaluationOfStaticVariableG etters}).%to the value stored in $v$. 1644 %whose invocation evaluates as described below (\ref{evaluationOfStaticVariableG etters}).%to the value stored in $v$.
1465 1645
1466 1646
1467 %A static variable declaration of one of the forms \code{\STATIC{} \VAR{} $v$;} , \code{\STATIC{} \VAR{} $v$ = $e$;} , \code{\STATIC{} \CONST{} $v$ = $e$;} or \code{\STATIC{} \FINAL{} $v$ = $e$;} always induces an implicit static getter function with signature 1647 %A static variable declaration of one of the forms \code{\STATIC{} \VAR{} $v$;} , \code{\STATIC{} \VAR{} $v$ = $e$;} , \code{\STATIC{} \CONST{} $v$ = $e$;} or \code{\STATIC{} \FINAL{} $v$ = $e$;} always induces an implicit static getter function with signature
(...skipping 10 matching lines...) Expand all
1478 1658
1479 %A static variable declaration of the form \code{\STATIC{} \VAR{} $v$;} or the form \code{\STATIC{} \VAR{} $v$ = $e$;} always induces an implicit static set ter function with signature 1659 %A static variable declaration of the form \code{\STATIC{} \VAR{} $v$;} or the form \code{\STATIC{} \VAR{} $v$ = $e$;} always induces an implicit static set ter function with signature
1480 1660
1481 %\STATIC{} \SET{} $v=(x)$ 1661 %\STATIC{} \SET{} $v=(x)$
1482 1662
1483 %whose execution sets the value of $v$ to the incoming argument $x$. 1663 %whose execution sets the value of $v$ to the incoming argument $x$.
1484 1664
1485 %Extrernal static functions, getters, setters 1665 %Extrernal static functions, getters, setters
1486 1666
1487 %\subsubsection{Evaluation of Implicit Static Variable Getters} 1667 %\subsubsection{Evaluation of Implicit Static Variable Getters}
1488 %\label{evaluationOfStaticVariableGetters} 1668 %\LMLabel{evaluationOfStaticVariableGetters}
1489 1669
1490 %Let $d$ be the declaration of a static variable $v$. The implicit getter method of $v$ executes as follows: 1670 %Let $d$ be the declaration of a static variable $v$. The implicit getter method of $v$ executes as follows:
1491 %\begin{itemize} 1671 %\begin{itemize}
1492 %\item If $d$ is of one of the forms \code{\STATIC{} \VAR{} $v$ = $e$;} , \code{ \STATIC{} $T$ $v$ = $e$; }, \code{\STATIC{} \FINAL{} $v$ = $e$; } or \code{\STAT IC{} \FINAL{} $T$ $v$ = $e$;} and no value has yet been stored into $v$ then the initializer expression $e$ is evaluated. If, during the evaluation of $e$, the getter for $v$ is referenced, a \code{CyclicInitializationError} is thrown. If t he evaluation succeeded yielding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$ is stored into $v$. The result of executing the gette r is $r$. 1672 %\item If $d$ is of one of the forms \code{\STATIC{} \VAR{} $v$ = $e$;} , \code{ \STATIC{} $T$ $v$ = $e$; }, \code{\STATIC{} \FINAL{} $v$ = $e$; } or \code{\STAT IC{} \FINAL{} $T$ $v$ = $e$;} and no value has yet been stored into $v$ then the initializer expression $e$ is evaluated. If, during the evaluation of $e$, the getter for $v$ is referenced, a \code{CyclicInitializationError} is thrown. If t he evaluation succeeded yielding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$ is stored into $v$. The result of executing the gette r is $r$.
1493 %\item If $d$ is of one of the forms \code{\STATIC{} \CONST{} $v$ = $e$; } or \ code{\STATIC{} \CONST{} $T$ $v$ = $e$;} the result of the getter is the value of the compile time constant $e$. 1673 %\item If $d$ is of one of the forms \code{\STATIC{} \CONST{} $v$ = $e$; } or \ code{\STATIC{} \CONST{} $T$ $v$ = $e$;} the result of the getter is the value of the compile time constant $e$.
1494 %Otherwise 1674 %Otherwise
1495 %\item The result of executing the getter method is the value stored in $v$. 1675 %\item The result of executing the getter method is the value stored in $v$.
1496 %\end{itemize} 1676 %\end{itemize}
1497 1677
1498 1678
1499 1679
1500 \subsection{Superclasses} 1680 \subsection{Superclasses}
1501 \label{superclasses} 1681 \LMLabel{superclasses}
1502 1682
1683 \LMHash{}
1503 The superclass of a class $C$ that has a with clause \code{\WITH{} $M_1, \ldots, M_k$} and an extends clause \code{\EXTENDS{} S} is the application of mixin (\r ef{mixins}) $M_k* \cdots * M_1$ to S. If no \WITH{} clause is specified then the \EXTENDS{} clause of a class $C$ specifies its superclass. If no \EXTENDS{} clause is specified, then either: 1684 The superclass of a class $C$ that has a with clause \code{\WITH{} $M_1, \ldots, M_k$} and an extends clause \code{\EXTENDS{} S} is the application of mixin (\r ef{mixins}) $M_k* \cdots * M_1$ to S. If no \WITH{} clause is specified then the \EXTENDS{} clause of a class $C$ specifies its superclass. If no \EXTENDS{} clause is specified, then either:
1504 \begin{itemize} 1685 \begin{itemize}
1505 \item $C$ is \code{Object}, which has no superclass. OR 1686 \item $C$ is \code{Object}, which has no superclass. OR
1506 \item Class $C$ is deemed to have an \EXTENDS{} clause of the form \code{\EXTEN DS{} Object}, and the rules above apply. 1687 \item Class $C$ is deemed to have an \EXTENDS{} clause of the form \code{\EXTEN DS{} Object}, and the rules above apply.
1507 \end{itemize} 1688 \end{itemize}
1508 1689
1690 \LMHash{}
1509 It is a compile-time error to specify an \EXTENDS{} clause for class \code{Objec t}. 1691 It is a compile-time error to specify an \EXTENDS{} clause for class \code{Objec t}.
1510 1692
1511 \begin{grammar} 1693 \begin{grammar}
1512 {\bf superclass:} 1694 {\bf superclass:}
1513 \EXTENDS{} type 1695 \EXTENDS{} type
1514 . 1696 .
1515 \end{grammar} 1697 \end{grammar}
1516 1698
1517 %The superclass clause of a class C is processed within the enclosing scope of t he static scope of C. 1699 %The superclass clause of a class C is processed within the enclosing scope of t he static scope of C.
1518 %\commentary{ 1700 %\commentary{
1519 %This means that in a generic class, the type parameters of the generic are avai lable in the superclass clause. 1701 %This means that in a generic class, the type parameters of the generic are avai lable in the superclass clause.
1520 %} 1702 %}
1521 1703
1704 \LMHash{}
1522 %It is a compile-time error if the \EXTENDS{} clause of a class $C$ includes a type expression that does not denote a class available in the lexical scope of $ C$. 1705 %It is a compile-time error if the \EXTENDS{} clause of a class $C$ includes a type expression that does not denote a class available in the lexical scope of $ C$.
1523 It is a compile-time error if the \EXTENDS{} clause of a class $C$ specifies an enumerated type (\ref{enums}), a malformed type or a deferred type (\ref{stati cTypes}) as a superclass. 1706 It is a compile-time error if the \EXTENDS{} clause of a class $C$ specifies an enumerated type (\ref{enums}), a malformed type or a deferred type (\ref{stati cTypes}) as a superclass.
1524 % too strict? Do we e want extends List<Undeclared> to work as List<dynamic>? 1707 % too strict? Do we e want extends List<Undeclared> to work as List<dynamic>?
1525 1708
1526 \commentary{ The type parameters of a generic class are available in the lexical scope of the superclass clause, potentially shadowing classes in the surroundin g scope. The following code is therefore illegal and should cause a compile-time error: 1709 \commentary{ The type parameters of a generic class are available in the lexical scope of the superclass clause, potentially shadowing classes in the surroundin g scope. The following code is therefore illegal and should cause a compile-time error:
1527 } 1710 }
1528 1711
1529 \begin{dartCode} 1712 \begin{dartCode}
1530 class T \{\} 1713 class T \{\}
1531 1714
1532 /* Compilation error: Attempt to subclass a type parameter */ 1715 /* Compilation error: Attempt to subclass a type parameter */
1533 class G$<$T$>$ extends T \{\} 1716 class G$<$T$>$ extends T \{\}
1534 1717
1535 \end{dartCode} 1718 \end{dartCode}
1536 1719
1537 1720
1721 \LMHash{}
1538 A class $S$ is {\em a superclass} of a class $C$ iff either: 1722 A class $S$ is {\em a superclass} of a class $C$ iff either:
1539 \begin{itemize} 1723 \begin{itemize}
1540 \item $S$ is the superclass of $C$, or 1724 \item $S$ is the superclass of $C$, or
1541 \item $S$ is a superclass of a class $S^{\prime}$ and $S^{\prime}$ is a supercla ss of $C$. 1725 \item $S$ is a superclass of a class $S^{\prime}$ and $S^{\prime}$ is a supercla ss of $C$.
1542 \end{itemize} 1726 \end{itemize}
1543 1727
1728 \LMHash{}
1544 It is a compile-time error if a class $C$ is a superclass of itself. 1729 It is a compile-time error if a class $C$ is a superclass of itself.
1545 1730
1546 1731
1547 1732
1548 1733
1549 \subsubsection{Inheritance and Overriding} 1734 \subsubsection{Inheritance and Overriding}
1550 \label{inheritanceAndOverriding} 1735 \LMLabel{inheritanceAndOverriding}
1551 1736
1552 1737
1553 %A class $C$ {\em inherits} any accessible instance members of its superclass t hat are not overridden by members declared in $C$. 1738 %A class $C$ {\em inherits} any accessible instance members of its superclass t hat are not overridden by members declared in $C$.
1554 1739
1740 \LMHash{}
1555 Let $C$ be a class, let $A$ be a superclass of $C$, and let $S_1 \ldots S_k$ b e superclasses of $C$ that are also subclasses of $A$. $C$ {\em inherits} all ac cessible instance members of $A$ that have not been overridden by a declaratio n in $C$ or in at least one of $S_1 \ldots S_k$. 1741 Let $C$ be a class, let $A$ be a superclass of $C$, and let $S_1 \ldots S_k$ b e superclasses of $C$ that are also subclasses of $A$. $C$ {\em inherits} all ac cessible instance members of $A$ that have not been overridden by a declaratio n in $C$ or in at least one of $S_1 \ldots S_k$.
1556 1742
1557 \rationale { 1743 \rationale {
1558 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 1744 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
1559 to the library $L_1$ of $C$, whereas $S$ comes from a different library $L_2$, b ut 1745 to the library $L_1$ of $C$, whereas $S$ comes from a different library $L_2$, b ut
1560 the superclass chain of $S$ includes a class declared in $L_1$. 1746 the superclass chain of $S$ includes a class declared in $L_1$.
1561 } 1747 }
1562 1748
1749 \LMHash{}
1563 A class may override instance members that would otherwise have been inherited f rom its superclass. 1750 A class may override instance members that would otherwise have been inherited f rom its superclass.
1564 1751
1752 \LMHash{}
1565 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. 1753 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.
1566 1754
1567 %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. 1755 %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.
1568 1756
1569 \commentary{Fields never override each other. The getters and setters induced by fields do.} 1757 \commentary{Fields never override each other. The getters and setters induced by fields do.}
1570 1758
1571 \rationale{Again, a local definition of overriding would be preferable, but fail s to account for library privacy. 1759 \rationale{Again, a local definition of overriding would be preferable, but fail s to account for library privacy.
1572 } 1760 }
1573 1761
1762 \LMHash{}
1574 Whether an override is legal or not is described elsewhere in this specification (see \ref{instanceMethods}, \ref{getters} and \ref{setters}). 1763 Whether an override is legal or not is described elsewhere in this specification (see \ref{instanceMethods}, \ref{getters} and \ref{setters}).
1575 1764
1576 \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. 1765 \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.
1577 } 1766 }
1578 1767
1579 \rationale{ 1768 \rationale{
1580 It is nevertheless convenient to define the override relation between members in this way, so that we can concisely describe the illegal cases. 1769 It is nevertheless convenient to define the override relation between members in this way, so that we can concisely describe the illegal cases.
1581 } 1770 }
1582 1771
1583 \commentary{ 1772 \commentary{
1584 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. 1773 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.
1585 } 1774 }
1586 1775
1776 \LMHash{}
1587 It is a static warning if a non-abstract class inherits an abstract method. 1777 It is a static warning if a non-abstract class inherits an abstract method.
1588 1778
1589 \commentary { 1779 \commentary {
1590 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. 1780 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.
1591 1781
1592 \begin{enumerate} 1782 \begin{enumerate}
1593 1783
1594 \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}). 1784 \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}).
1595 \item You cannot have two members with the same name in the same class - be the y declared or inherited (\ref{scoping}, \ref{classes}). 1785 \item You cannot have two members with the same name in the same class - be the y declared or inherited (\ref{scoping}, \ref{classes}).
1596 \item Static members are never inherited. 1786 \item Static members are never inherited.
(...skipping 27 matching lines...) Expand all
1624 \item Rule \ref{typeSigAssignable} applies to interfaces as well as classes (\ ref{interfaceInheritanceAndOverriding}). 1814 \item Rule \ref{typeSigAssignable} applies to interfaces as well as classes (\ ref{interfaceInheritanceAndOverriding}).
1625 \item It is a static warning if a concrete class does not have an implementatio n for a method in any of its superinterfaces unless it declares its own \cd{n oSuchMethod} method (\ref{superinterfaces}). 1815 \item It is a static warning if a concrete class does not have an implementatio n for a method in any of its superinterfaces unless it declares its own \cd{n oSuchMethod} method (\ref{superinterfaces}).
1626 \item The identifier of a named constructor cannot be the same as the name of a member declared (as opposed to inherited) in the same class (\ref{constructors}) . 1816 \item The identifier of a named constructor cannot be the same as the name of a member declared (as opposed to inherited) in the same class (\ref{constructors}) .
1627 \end{enumerate} 1817 \end{enumerate}
1628 } 1818 }
1629 1819
1630 1820
1631 %Can we have abstract getters and setters? 1821 %Can we have abstract getters and setters?
1632 1822
1633 \subsection{ Superinterfaces} 1823 \subsection{ Superinterfaces}
1634 \label{superinterfaces} 1824 \LMLabel{superinterfaces}
1635 % what about rules about classes that fail to implement their interfaces? 1825 % what about rules about classes that fail to implement their interfaces?
1636 1826
1827 \LMHash{}
1637 A class has a set of direct superinterfaces. This set includes the interface of its superclass and the interfaces specified in the the \IMPLEMENTS{} clause of the class. 1828 A class has a set of direct superinterfaces. This set includes the interface of its superclass and the interfaces specified in the the \IMPLEMENTS{} clause of the class.
1638 % and any superinterfaces specified by interface injection (\ref{interfaceInject ion}). \Q{The latter needs to be worded carefully - when do interface injection clauses execute and in what scope?} 1829 % and any superinterfaces specified by interface injection (\ref{interfaceInject ion}). \Q{The latter needs to be worded carefully - when do interface injection clauses execute and in what scope?}
1639 1830
1640 \begin{grammar} 1831 \begin{grammar}
1641 {\bf interfaces:} 1832 {\bf interfaces:}
1642 \IMPLEMENTS{} typeList 1833 \IMPLEMENTS{} typeList
1643 . 1834 .
1644 \end{grammar} 1835 \end{grammar}
1645 1836
1837 \LMHash{}
1646 It is a compile-time error if the \IMPLEMENTS{} clause of a class $C$ specifie s a type variable as a superinterface. It is a compile-time error if the \IMPL EMENTS{} clause of a class $C$ specifies an enumerated type (\ref{enums}), a ma lformed type or deferred type (\ref{staticTypes}) as a superinterface It is a c ompile-time error if the \IMPLEMENTS{} clause of a class $C$ specifies type \DYN AMIC{} as a superinterface. It is a compile-time error if the \IMPLEMENTS{} cl ause of a class $C$ specifies a type $T$ as a superinterface more than once. 1838 It is a compile-time error if the \IMPLEMENTS{} clause of a class $C$ specifie s a type variable as a superinterface. It is a compile-time error if the \IMPL EMENTS{} clause of a class $C$ specifies an enumerated type (\ref{enums}), a ma lformed type or deferred type (\ref{staticTypes}) as a superinterface It is a c ompile-time error if the \IMPLEMENTS{} clause of a class $C$ specifies type \DYN AMIC{} as a superinterface. It is a compile-time error if the \IMPLEMENTS{} cl ause of a class $C$ specifies a type $T$ as a superinterface more than once.
1647 It is a compile-time error if the superclass of a class $C$ is specified as a su perinterface of $C$. 1839 It is a compile-time error if the superclass of a class $C$ is specified as a su perinterface of $C$.
1648 1840
1649 \rationale{ 1841 \rationale{
1650 One might argue that it is harmless to repeat a type in the superinterface list, so why make it an error? The issue is not so much that the situation described in program source is erroneous, but that it is pointless. As such, it is an indi cation that the programmer may very well have meant to say something else - and that is a mistake that should be called to her or his attention. Nevertheless, we could simply issue a warning; and perhaps we should and will. That said, prob lems like these are local and easily corrected on the spot, so we feel justified in taking a harder line. 1842 One might argue that it is harmless to repeat a type in the superinterface list, so why make it an error? The issue is not so much that the situation described in program source is erroneous, but that it is pointless. As such, it is an indi cation that the programmer may very well have meant to say something else - and that is a mistake that should be called to her or his attention. Nevertheless, we could simply issue a warning; and perhaps we should and will. That said, prob lems like these are local and easily corrected on the spot, so we feel justified in taking a harder line.
1651 } 1843 }
1652 1844
1845 \LMHash{}
1653 It is a compile-time error if the interface of a class $C$ is a superinterface o f itself. 1846 It is a compile-time error if the interface of a class $C$ is a superinterface o f itself.
1654 1847
1848 \LMHash{}
1655 Let $C$ be a concrete class that does not declare its own \code{noSuchMethod()} method. 1849 Let $C$ be a concrete class that does not declare its own \code{noSuchMethod()} method.
1656 It is a static warning if the implicit interface of $C$ includes an instance me mber $m$ of type $F$ and $C$ does not declare or inherit a corresponding non-abs tract instance member $m$ of type $F'$ such that $F' <: F$. 1850 It is a static warning if the implicit interface of $C$ includes an instance me mber $m$ of type $F$ and $C$ does not declare or inherit a corresponding non-abs tract instance member $m$ of type $F'$ such that $F' <: F$.
1657 1851
1658 \commentary{A class does not inherit members from its superinterfaces. However, its implicit interface does. 1852 \commentary{A class does not inherit members from its superinterfaces. However, its implicit interface does.
1659 } 1853 }
1660 1854
1661 1855
1662 \rationale { 1856 \rationale {
1663 We choose to issue these warnings only for concrete classes; an abstract class m ight legitimately be designed with the expectation that concrete subclasses will implement part of the interface. 1857 We choose to issue these warnings only for concrete classes; an abstract class m ight legitimately be designed with the expectation that concrete subclasses will implement part of the interface.
1664 We also disable these warnings if a \code{noSuchMethod()} declaration is present . In such cases, the supported interface is going to be implemented via \code{no SuchMethod()} and no actual declarations of the implemented interface's members are needed. This allows proxy classes for specific types to be implemented witho ut provoking type warnings. 1858 We also disable these warnings if a \code{noSuchMethod()} declaration is present . In such cases, the supported interface is going to be implemented via \code{no SuchMethod()} and no actual declarations of the implemented interface's members are needed. This allows proxy classes for specific types to be implemented witho ut provoking type warnings.
1665 1859
1666 In addition, it may be useful to suppress these warnings if \code{noSuchMethod} is inherited, However, this may suppress meaningful warnings and so we choose no t to do so. If one does want to suppress the warnings in a subclass, one can def ine a simple implementation of \code{noSuchMethod} in the subclass: 1860 In addition, it may be useful to suppress these warnings if \code{noSuchMethod} is inherited, However, this may suppress meaningful warnings and so we choose no t to do so. If one does want to suppress the warnings in a subclass, one can def ine a simple implementation of \code{noSuchMethod} in the subclass:
1667 } 1861 }
1668 1862
1669 \begin{dartCode} 1863 \begin{dartCode}
1670 noSuchMethod(inv) =$>$ \SUPER.noSuchMethod(inv); 1864 noSuchMethod(inv) =$>$ \SUPER.noSuchMethod(inv);
1671 \end{dartCode} 1865 \end{dartCode}
1672 1866
1867 \LMHash{}
1673 It is a static warning if the implicit interface of a class $C$ includes an ins tance member $m$ of type $F$ and $C$ declares or inherits a corresponding instan ce member $m$ of type $F'$ if $F'$ is not a subtype of $F$. 1868 It is a static warning if the implicit interface of a class $C$ includes an ins tance member $m$ of type $F$ and $C$ declares or inherits a corresponding instan ce member $m$ of type $F'$ if $F'$ is not a subtype of $F$.
1674 1869
1675 \rationale{ 1870 \rationale{
1676 However, if a class does explicitly declare a member that conflicts with its sup erinterface, this always yields a static warning. 1871 However, if a class does explicitly declare a member that conflicts with its sup erinterface, this always yields a static warning.
1677 1872
1678 } 1873 }
1679 %It is a static warning if an imported superinterface of a class $C$ declares pr ivate members. 1874 %It is a static warning if an imported superinterface of a class $C$ declares pr ivate members.
1680 1875
1681 % Should we ignore unimplemented private members? 1876 % Should we ignore unimplemented private members?
1682 1877
(...skipping 14 matching lines...) Expand all
1697 1892
1698 %class C implements I1, I2 {...}; // class declaration 1893 %class C implements I1, I2 {...}; // class declaration
1699 1894
1700 %this should not cause breakage. 1895 %this should not cause breakage.
1701 %} 1896 %}
1702 1897
1703 % \rationale{This avoids the issues with so-called miranda methods etc. } 1898 % \rationale{This avoids the issues with so-called miranda methods etc. }
1704 1899
1705 1900
1706 \section{Interfaces} 1901 \section{Interfaces}
1707 \label{interfaces} 1902 \LMLabel{interfaces}
1708 1903
1904 \LMHash{}
1709 An {\em interface} defines how one may interact with an object. An interface has methods, getters and setters and a set of superinterfaces. 1905 An {\em interface} defines how one may interact with an object. An interface has methods, getters and setters and a set of superinterfaces.
1710 1906
1711 \subsection{Superinterfaces} 1907 \subsection{Superinterfaces}
1712 \label{interfaceSuperinterfaces} 1908 \LMLabel{interfaceSuperinterfaces}
1713 1909
1910 \LMHash{}
1714 An interface has a set of direct superinterfaces. 1911 An interface has a set of direct superinterfaces.
1715 1912
1913 \LMHash{}
1716 An interface $J$ is a superinterface of an interface $I$ iff either $J$ is a dir ect superinterface of $I$ or $J$ is a superinterface of a direct superinterface of $I$. 1914 An interface $J$ is a superinterface of an interface $I$ iff either $J$ is a dir ect superinterface of $I$ or $J$ is a superinterface of a direct superinterface of $I$.
1717 1915
1718 1916
1719 1917
1720 1918
1721 \subsubsection{Inheritance and Overriding} 1919 \subsubsection{Inheritance and Overriding}
1722 \label{interfaceInheritanceAndOverriding} 1920 \LMLabel{interfaceInheritanceAndOverriding}
1723 1921
1922 \LMHash{}
1724 Let $J$ be an interface and $K$ be a library. We define $inherited(J, K)$ to be the set of members $m$ such that all of the following hold: 1923 Let $J$ be an interface and $K$ be a library. We define $inherited(J, K)$ to be the set of members $m$ such that all of the following hold:
1725 \begin{itemize} 1924 \begin{itemize}
1726 \item $m$ is accessible to $K$ and 1925 \item $m$ is accessible to $K$ and
1727 \item $A$ is a direct superinterface of $J$ and either 1926 \item $A$ is a direct superinterface of $J$ and either
1728 \begin{itemize} 1927 \begin{itemize}
1729 \item $A$ declares a member $m$ or 1928 \item $A$ declares a member $m$ or
1730 \item $m$ is a member of $inherited(A, K)$. 1929 \item $m$ is a member of $inherited(A, K)$.
1731 \end{itemize} 1930 \end{itemize}
1732 \item $m$ is not overridden by $J$. 1931 \item $m$ is not overridden by $J$.
1733 \end{itemize} 1932 \end{itemize}
1734 1933
1934 \LMHash{}
1735 Furthermore, we define $overrides(J, K)$ to be the set of members $m^\prime$ su ch that all of the following hold: 1935 Furthermore, we define $overrides(J, K)$ to be the set of members $m^\prime$ su ch that all of the following hold:
1736 \begin{itemize} 1936 \begin{itemize}
1737 \item $J$ is the implicit interface of a class $C$. 1937 \item $J$ is the implicit interface of a class $C$.
1738 \item $C$ declares a member $m$. 1938 \item $C$ declares a member $m$.
1739 \item $m^\prime$ has the same name as $m$. 1939 \item $m^\prime$ has the same name as $m$.
1740 \item $m^\prime$ is accessible to $K$. 1940 \item $m^\prime$ is accessible to $K$.
1741 \item $A$ is a direct superinterface of $J$ and either 1941 \item $A$ is a direct superinterface of $J$ and either
1742 \begin{itemize} 1942 \begin{itemize}
1743 \item $A$ declares a member $m^\prime$ or 1943 \item $A$ declares a member $m^\prime$ or
1744 \item $m^\prime$ is a member of $inherited(A, K)$. 1944 \item $m^\prime$ is a member of $inherited(A, K)$.
1745 \end{itemize} 1945 \end{itemize}
1746 \end{itemize} 1946 \end{itemize}
1747 1947
1748 1948
1949 \LMHash{}
1749 Let $I$ be the implicit interface of a class $C$ declared in library $L$. $I$ { \em inherits} all members of $inherited(I, L)$ and $I$ {\em overrides} $m^\prime $ if $m^\prime \in overrides(I, L)$. 1950 Let $I$ be the implicit interface of a class $C$ declared in library $L$. $I$ { \em inherits} all members of $inherited(I, L)$ and $I$ {\em overrides} $m^\prime $ if $m^\prime \in overrides(I, L)$.
1750 1951
1952 \LMHash{}
1751 All the static warnings pertaining to the overriding of instance members given i n section \ref{classes} above hold for overriding between interfaces as well. 1953 All the static warnings pertaining to the overriding of instance members given i n section \ref{classes} above hold for overriding between interfaces as well.
1752 1954
1955 \LMHash{}
1753 It is a static warning if $m$ is a method and $m^\prime$ is a getter, or if $m$ is a getter and $m^\prime$ is a method. 1956 It is a static warning if $m$ is a method and $m^\prime$ is a getter, or if $m$ is a getter and $m^\prime$ is a method.
1754 1957
1755 1958
1756 1959
1757 %Let $I = S_0$ be the implicit interface of a class $C$ declared in library $L$, and let $\{S_1 \ldots S_k\}$ be the set of all superinterfaces of $I$. 1960 %Let $I = S_0$ be the implicit interface of a class $C$ declared in library $L$, and let $\{S_1 \ldots S_k\}$ be the set of all superinterfaces of $I$.
1758 1961
1759 %Let $I$ be the implicit interface of a class $C$. $I$ inherits any instance me mbers of its superinterfaces that are not overridden by members declared in $C$. 1962 %Let $I$ be the implicit interface of a class $C$. $I$ inherits any instance me mbers of its superinterfaces that are not overridden by members declared in $C$.
1760 1963
1761 % tighten definition? do we need chain as for classes? Definition for interface override? 1964 % tighten definition? do we need chain as for classes? Definition for interface override?
1762 1965
1966 \LMHash{}
1763 However, if the above rules would cause multiple members $m_1, \ldots, m_k$ wit h the same name $n$ to be inherited (because identically named members existed i n several superinterfaces) then at most one member is inherited. 1967 However, if the above rules would cause multiple members $m_1, \ldots, m_k$ wit h the same name $n$ to be inherited (because identically named members existed i n several superinterfaces) then at most one member is inherited.
1764 1968
1969 \LMHash{}
1765 If some but not all of the $m_i, 1 \le i \le k$ are getters none of the $m_i$ ar e inherited, and a static warning is issued. 1970 If some but not all of the $m_i, 1 \le i \le k$ are getters none of the $m_i$ ar e inherited, and a static warning is issued.
1766 1971
1972 \LMHash{}
1767 Otherwise, if the static types $T_1, \ldots, T_k$ of the members $m_1, \ldots, m_k$ are not identical, then there must be a member $m_x$ such that $T_x <: T_ i, 1 \le x \le k$ for all $i \in 1..k$, or a static type warning occurs. The m ember that is inherited is $m_x$, if it exists; otherwise: 1973 Otherwise, if the static types $T_1, \ldots, T_k$ of the members $m_1, \ldots, m_k$ are not identical, then there must be a member $m_x$ such that $T_x <: T_ i, 1 \le x \le k$ for all $i \in 1..k$, or a static type warning occurs. The m ember that is inherited is $m_x$, if it exists; otherwise:
1768 let $numberOfPositionals(f)$ denote the number of positional parameters of a fu nction $f$, and let $numberOfRequiredParams(f)$ denote the number of required pa rameters of a function $f$. Furthermore, let $s$ denote the set of all named par ameters of the $m_1, \ldots, m_k$. Then let 1974 let $numberOfPositionals(f)$ denote the number of positional parameters of a fu nction $f$, and let $numberOfRequiredParams(f)$ denote the number of required pa rameters of a function $f$. Furthermore, let $s$ denote the set of all named par ameters of the $m_1, \ldots, m_k$. Then let
1769 1975
1770 $h = max(numberOfPositionals(m_i)), $ 1976 $h = max(numberOfPositionals(m_i)), $
1771 1977
1772 $r = min(numberOfRequiredParams(m_i)), i \in 1..k$. 1978 $r = min(numberOfRequiredParams(m_i)), i \in 1..k$.
1773 1979
1980 \LMHash{}
1774 Then $I$ has a method named $n$, with $r$ required parameters of type \DYNAMIC{} , $h$ positional parameters of type \DYNAMIC{}, named parameters $s$ of type \ DYNAMIC{} and return type \DYNAMIC{}. 1981 Then $I$ has a method named $n$, with $r$ required parameters of type \DYNAMIC{} , $h$ positional parameters of type \DYNAMIC{}, named parameters $s$ of type \ DYNAMIC{} and return type \DYNAMIC{}.
1775 1982
1776 1983
1777 1984
1778 \commentary{The only situation where the runtime would be concerned with this wo uld be during reflection, if a mirror attempted to obtain the signature of an in terface member. 1985 \commentary{The only situation where the runtime would be concerned with this wo uld be during reflection, if a mirror attempted to obtain the signature of an in terface member.
1779 } 1986 }
1780 1987
1781 \rationale{ 1988 \rationale{
1782 The current solution is a tad complex, but is robust in the face of type annotat ion changes. Alternatives: (a) No member is inherited in case of conflict. (b) The first m is selected (based on order of superinterface list) (c) Inherited me mber chosen at random. 1989 The current solution is a tad complex, but is robust in the face of type annotat ion changes. Alternatives: (a) No member is inherited in case of conflict. (b) The first m is selected (based on order of superinterface list) (c) Inherited me mber chosen at random.
1783 1990
1784 (a) means that the presence of an inherited member of an interface varies depend ing on type signatures. (b) is sensitive to irrelevant details of the declarati on and (c) is liable to give unpredictable results between implementations or ev en between different compilation sessions. 1991 (a) means that the presence of an inherited member of an interface varies depend ing on type signatures. (b) is sensitive to irrelevant details of the declarati on and (c) is liable to give unpredictable results between implementations or ev en between different compilation sessions.
1785 } 1992 }
1786 1993
1787 % Need warnings if overrider conflicts with overriddee either because signatures are incompatible or because done is a method and one is a getter or setter. 1994 % Need warnings if overrider conflicts with overriddee either because signatures are incompatible or because done is a method and one is a getter or setter.
1788 1995
1789 \section{Mixins} 1996 \section{Mixins}
1790 \label{mixins} 1997 \LMLabel{mixins}
1791 1998
1792 1999
2000 \LMHash{}
1793 A mixin describes the difference between a class and its superclass. A mixin is always derived from an existing class declaration. 2001 A mixin describes the difference between a class and its superclass. A mixin is always derived from an existing class declaration.
1794 2002
2003 \LMHash{}
1795 It is a compile-time error if a declared or derived mixin refers to \SUPER{}. It is a compile-time error if a declared or derived mixin explicitly declares a co nstructor. It is a compile-time error if a mixin is derived from a class whose s uperclass is not \code{Object}. 2004 It is a compile-time error if a declared or derived mixin refers to \SUPER{}. It is a compile-time error if a declared or derived mixin explicitly declares a co nstructor. It is a compile-time error if a mixin is derived from a class whose s uperclass is not \code{Object}.
1796 2005
1797 \rationale{ 2006 \rationale{
1798 These restrictions are temporary. We expect to remove them in later versions of Dart. 2007 These restrictions are temporary. We expect to remove them in later versions of Dart.
1799 2008
1800 The restriction on the use of \SUPER{} avoids the problem of rebinding \SUPER{} when the mixin is bound to difference superclasses. 2009 The restriction on the use of \SUPER{} avoids the problem of rebinding \SUPER{} when the mixin is bound to difference superclasses.
1801 2010
1802 The restriction on constructors simplifies the construction of mixin application s because the process of creating instances is simpler. 2011 The restriction on constructors simplifies the construction of mixin application s because the process of creating instances is simpler.
1803 2012
1804 The restriction on the superclass means that the type of a class from which a m ixin is derived is always implemented by any class that mixes it in. This allows us to defer the question of whether and how to express the type of the mixin in dependently of its superclass and super interface types. 2013 The restriction on the superclass means that the type of a class from which a m ixin is derived is always implemented by any class that mixes it in. This allows us to defer the question of whether and how to express the type of the mixin in dependently of its superclass and super interface types.
1805 2014
1806 Reasonable answers exist for all these issues, but their implementation is non-t rivial. 2015 Reasonable answers exist for all these issues, but their implementation is non-t rivial.
1807 } 2016 }
1808 2017
1809 \subsection{Mixin Application} 2018 \subsection{Mixin Application}
1810 \label{mixinApplication} 2019 \LMLabel{mixinApplication}
1811 2020
2021 \LMHash{}
1812 A mixin may be applied to a superclass, yielding a new class. Mixin application occurs when a mixin is mixed into a class declaration via its \WITH{} clause. T he mixin application may be used to extend a class per section (\ref{classes}); alternately, a class may be defined as a mixin application as described in this section. It is a compile-time error if the \WITH{} clause of a mixin applicati on $C$ includes a deferred type expression. 2022 A mixin may be applied to a superclass, yielding a new class. Mixin application occurs when a mixin is mixed into a class declaration via its \WITH{} clause. T he mixin application may be used to extend a class per section (\ref{classes}); alternately, a class may be defined as a mixin application as described in this section. It is a compile-time error if the \WITH{} clause of a mixin applicati on $C$ includes a deferred type expression.
1813 2023
1814 2024
1815 \begin{grammar} 2025 \begin{grammar}
1816 {\bf mixinApplicationClass:} 2026 {\bf mixinApplicationClass:}
1817 identifier typeParameters? `=' mixinApplication `{\escapegrammar ;}' . 2027 identifier typeParameters? `=' mixinApplication `{\escapegrammar ;}' .
1818 2028
1819 {\bf mixinApplication:} 2029 {\bf mixinApplication:}
1820 type mixins interfaces? 2030 type mixins interfaces?
1821 . 2031 .
1822 \end{grammar} 2032 \end{grammar}
1823 2033
2034 \LMHash{}
1824 A mixin application of the form \code{$S$ \WITH{} $M$;} defines a class $C$ w ith superclass $S$. 2035 A mixin application of the form \code{$S$ \WITH{} $M$;} defines a class $C$ w ith superclass $S$.
1825 2036
2037 \LMHash{}
1826 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$. 2038 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$.
1827 2039
2040 \LMHash{}
1828 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$. 2041 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$.
1829 2042
2043 \LMHash{}
1830 For each generative constructor named $q_i(T_{i1}$ $ a_{i1}, \ldots , T_{ik_i}$ $ a_{ik_i}), i \in 1..n$ of $S$, $C$ has an implicitly declared constructor name d 2044 For each generative constructor named $q_i(T_{i1}$ $ a_{i1}, \ldots , T_{ik_i}$ $ a_{ik_i}), i \in 1..n$ of $S$, $C$ has an implicitly declared constructor name d
1831 $q'_i = [C/S]q_i$ of the form 2045 $q'_i = [C/S]q_i$ of the form
1832 2046
1833 $q'_i(a_{i1}, \ldots , a_{ik_i}):\SUPER(a_{i1}, \ldots , a_{ik_i});$. 2047 $q'_i(a_{i1}, \ldots , a_{ik_i}):\SUPER(a_{i1}, \ldots , a_{ik_i});$.
1834 2048
2049 \LMHash{}
1835 If the mixin application declares support for interfaces, the resulting class im plements those interfaces. 2050 If the mixin application declares support for interfaces, the resulting class im plements those interfaces.
1836 2051
2052 \LMHash{}
1837 It is a compile-time error if $S$ is an enumerated type (\ref{enums}) or a malfo rmed type. It is a compile-time error if $M$ (respectively, any of $M_1, \ldots, M_k$) is an enumerated type (\ref{enums}) or a malformed type. It is a compile time error if a well formed mixin cannot be derived from $M$ (respectively, from each of $M_1, \ldots, M_k$). 2053 It is a compile-time error if $S$ is an enumerated type (\ref{enums}) or a malfo rmed type. It is a compile-time error if $M$ (respectively, any of $M_1, \ldots, M_k$) is an enumerated type (\ref{enums}) or a malformed type. It is a compile time error if a well formed mixin cannot be derived from $M$ (respectively, from each of $M_1, \ldots, M_k$).
1838 2054
2055 \LMHash{}
1839 Let $K$ be a class declaration with the same constructors, superclass and inter faces as $C$, and the instance members declared by $M$ (respectively $M_1, \ldo ts, M_k$). It is a static warning if the declaration of $K$ would cause a static warning. It is a compile-time error if the declaration of $K$ would cause a co mpile-time error. 2056 Let $K$ be a class declaration with the same constructors, superclass and inter faces as $C$, and the instance members declared by $M$ (respectively $M_1, \ldo ts, M_k$). It is a static warning if the declaration of $K$ would cause a static warning. It is a compile-time error if the declaration of $K$ would cause a co mpile-time error.
1840 2057
1841 \commentary{ 2058 \commentary{
1842 If, for example, $M$ declares an instance member $im$ whose type is at odds with the type of a member of the same name in $S$, this will result in a static warn ing just as if we had defined $K$ by means of an ordinary class declaration exte nding $S$, with a body that included $im$. 2059 If, for example, $M$ declares an instance member $im$ whose type is at odds with the type of a member of the same name in $S$, this will result in a static warn ing just as if we had defined $K$ by means of an ordinary class declaration exte nding $S$, with a body that included $im$.
1843 2060
1844 } 2061 }
1845 2062
2063 \LMHash{}
1846 The effect of a class definition of the form \code{\CLASS{} $C$ = $M$; } or the form 2064 The effect of a class definition of the form \code{\CLASS{} $C$ = $M$; } or the form
1847 \code{\CLASS{} $C<T_1, \ldots, T_n>$ = $M$; } in library $L$ is to introduce t he name $C$ into the scope of $L$, bound to the class (\ref{classes}) defined by the mixin application $M$. The name of the class is also set to $C$. Iff the c lass is prefixed by the built-in identifier \ABSTRACT{}, the class being defined is an abstract class. 2065 \code{\CLASS{} $C<T_1, \ldots, T_n>$ = $M$; } in library $L$ is to introduce t he name $C$ into the scope of $L$, bound to the class (\ref{classes}) defined by the mixin application $M$. The name of the class is also set to $C$. Iff the c lass is prefixed by the built-in identifier \ABSTRACT{}, the class being defined is an abstract class.
1848 2066
1849 2067
1850 \subsection{Mixin Composition} 2068 \subsection{Mixin Composition}
1851 \label{mixinComposition} 2069 \LMLabel{mixinComposition}
1852 2070
1853 \rationale{ 2071 \rationale{
1854 Dart does not directly support mixin composition, but the concept is useful when defining how the superclass of a class with a mixin clause is created. 2072 Dart does not directly support mixin composition, but the concept is useful when defining how the superclass of a class with a mixin clause is created.
1855 } 2073 }
1856 2074
2075 \LMHash{}
1857 The {\em composition of two mixins}, $M_1<T_1 \ldots T_{k_{M_1}}>$ and $M_2<U_1 \ldots U_{k_{M_2}}>$, written $M_1<T_1 \ldots T_{k_{M_1}}> * M_2<U_1 \ldots U_ {k_{M_2}}>$ defines an anonymous mixin such that for any class $S<V_1 \ldots V_{ k_S}>$, the application of 2076 The {\em composition of two mixins}, $M_1<T_1 \ldots T_{k_{M_1}}>$ and $M_2<U_1 \ldots U_{k_{M_2}}>$, written $M_1<T_1 \ldots T_{k_{M_1}}> * M_2<U_1 \ldots U_ {k_{M_2}}>$ defines an anonymous mixin such that for any class $S<V_1 \ldots V_{ k_S}>$, the application of
1858 2077
1859 $M_1<T_1 \ldots T_{k_{M_1}}> * M_2<U_1 \ldots U_{k_{M_2}}>$ 2078 $M_1<T_1 \ldots T_{k_{M_1}}> * M_2<U_1 \ldots U_{k_{M_2}}>$
1860 2079
1861 to $S<V_1 \ldots V_{k_S}>$ is equivalent to 2080 to $S<V_1 \ldots V_{k_S}>$ is equivalent to
1862 2081
1863 \begin{dartCode} 2082 \begin{dartCode}
1864 \ABSTRACT{} \CLASS{} $Id_1<T_1 \ldots T_{k_{M_1}}, U_1 \ldots U_{k_{M_2}}, V_1 \ldots V_{k_S}> = $ 2083 \ABSTRACT{} \CLASS{} $Id_1<T_1 \ldots T_{k_{M_1}}, U_1 \ldots U_{k_{M_2}}, V_1 \ldots V_{k_S}> = $
1865 $Id_2<U_1 \ldots U_{k_{M_2}}, V_1 \ldots V_{k_S}>$ \WITH{} $M_1 <T_1 \l dots T_{k_{M_1}}>$; 2084 $Id_2<U_1 \ldots U_{k_{M_2}}, V_1 \ldots V_{k_S}>$ \WITH{} $M_1 <T_1 \l dots T_{k_{M_1}}>$;
1866 \end{dartCode} 2085 \end{dartCode}
1867 2086
1868 where $Id_2$ denotes 2087 where $Id_2$ denotes
1869 2088
1870 \begin{dartCode} 2089 \begin{dartCode}
1871 \ABSTRACT{} \CLASS{} $Id_2<U_1 \ldots U_{k_{M_2}}, V_1 \ldots V_{k_S}> =$ 2090 \ABSTRACT{} \CLASS{} $Id_2<U_1 \ldots U_{k_{M_2}}, V_1 \ldots V_{k_S}> =$
1872 $S<V_1 \ldots V_{k_S}>$ \WITH{} $M_2<U_1 \ldots U_{k_{ M_2}}>$; 2091 $S<V_1 \ldots V_{k_S}>$ \WITH{} $M_2<U_1 \ldots U_{k_{ M_2}}>$;
1873 \end{dartCode} 2092 \end{dartCode}
1874 2093
1875 and $Id_1$ and $Id_2$ are unique identifiers that do not exist anywhere in the p rogram. 2094 and $Id_1$ and $Id_2$ are unique identifiers that do not exist anywhere in the p rogram.
1876 2095
1877 \rationale{ 2096 \rationale{
1878 The classes produced by mixin composition are regarded as abstract because they cannot be instantiated independently. They are only introduced as anonymous supe rclasses of ordinary class declarations and mixin applications. Consequently, no warning is given if a mixin composition includes abstract members, or incomplet ely implements an interface. 2097 The classes produced by mixin composition are regarded as abstract because they cannot be instantiated independently. They are only introduced as anonymous supe rclasses of ordinary class declarations and mixin applications. Consequently, no warning is given if a mixin composition includes abstract members, or incomplet ely implements an interface.
1879 } 2098 }
1880 2099
2100 \LMHash{}
1881 Mixin composition is associative. 2101 Mixin composition is associative.
1882 2102
1883 2103
1884 \commentary{ 2104 \commentary{
1885 Note that any subset of $M_1$, $M_2$ and $S$ may or may not be generic. For any non-generic declaration, the corresponding type parameters may be elided, and if no type parameters remain in the derived declarations $Id_1$ and/or $Id_2$ then the those declarations need not be generic either. 2105 Note that any subset of $M_1$, $M_2$ and $S$ may or may not be generic. For any non-generic declaration, the corresponding type parameters may be elided, and if no type parameters remain in the derived declarations $Id_1$ and/or $Id_2$ then the those declarations need not be generic either.
1886 } 2106 }
1887 2107
1888 2108
1889 \section{Enums} 2109 \section{Enums}
1890 \label{enums} 2110 \LMLabel{enums}
1891 2111
2112 \LMHash{}
1892 An {\em enumerated type}, or {\em enum}, is used to represent a fixed number of constant values. 2113 An {\em enumerated type}, or {\em enum}, is used to represent a fixed number of constant values.
1893 2114
1894 \begin{grammar} 2115 \begin{grammar}
1895 {\bf enumType:} 2116 {\bf enumType:}
1896 metadata \ENUM{} id `\{' id [`,' id]* [`,'] `\}' 2117 metadata \ENUM{} id `\{' id [`,' id]* [`,'] `\}'
1897 . 2118 .
1898 \end{grammar} 2119 \end{grammar}
1899 2120
2121 \LMHash{}
1900 The declaration of an enum of the form \code{metadata \ENUM{} E \{ id$_0$, \ldot s id$_{n-1}$\};} 2122 The declaration of an enum of the form \code{metadata \ENUM{} E \{ id$_0$, \ldot s id$_{n-1}$\};}
1901 has the same effect as a class declaration 2123 has the same effect as a class declaration
1902 2124
1903 \begin{dartCode} 2125 \begin{dartCode}
1904 metadata \CLASS{} E \{ 2126 metadata \CLASS{} E \{
1905 \FINAL{} int index; 2127 \FINAL{} int index;
1906 \CONST{} E(\THIS{}.index); 2128 \CONST{} E(\THIS{}.index);
1907 \STATIC{} \CONST{} E id$_0$ = \CONST{} E(0); 2129 \STATIC{} \CONST{} E id$_0$ = \CONST{} E(0);
1908 $\ldots$ 2130 $\ldots$
1909 \STATIC{} \CONST{} E id$_{n-1}$ = const E(n - 1); 2131 \STATIC{} \CONST{} E id$_{n-1}$ = const E(n - 1);
1910 \STATIC{} \CONST{} List$<$E$>$ values = const $<$E$>$[id$_0 \ldots $ id$_{n-1} $]; 2132 \STATIC{} \CONST{} List$<$E$>$ values = const $<$E$>$[id$_0 \ldots $ id$_{n-1} $];
1911 String toString() =$>$ \{ 0: `E.id$_0$', $\ldots$, n-1: `E.id$_{n-1}$'\}[index ] 2133 String toString() =$>$ \{ 0: `E.id$_0$', $\ldots$, n-1: `E.id$_{n-1}$'\}[index ]
1912 \} 2134 \}
1913 \end{dartCode} 2135 \end{dartCode}
1914 2136
1915 \commentary { 2137 \commentary {
1916 It is also a compile-time error to subclass, mix-in or implement an enum or to e xplicitly instantiate an enum. These restrictions are given in normative form i n sections \ref{superclasses}, \ref{superinterfaces}, \ref{mixinApplication} and \ref{instanceCreation} as appropriate. 2138 It is also a compile-time error to subclass, mix-in or implement an enum or to e xplicitly instantiate an enum. These restrictions are given in normative form i n sections \ref{superclasses}, \ref{superinterfaces}, \ref{mixinApplication} and \ref{instanceCreation} as appropriate.
1917 } 2139 }
1918 2140
1919 \section{Generics} 2141 \section{Generics}
1920 \label{generics} 2142 \LMLabel{generics}
1921 2143
2144 \LMHash{}
1922 A class declaration (\ref{classes}) or type alias (\ref{typedef}) 2145 A class declaration (\ref{classes}) or type alias (\ref{typedef})
1923 $G$ may be {\em generic}, that is, $G$ may have formal type parameters declared. A generic declaration induces a family of declarations, one for each set of act ual type parameters provided in the program. 2146 $G$ may be {\em generic}, that is, $G$ may have formal type parameters declared. A generic declaration induces a family of declarations, one for each set of act ual type parameters provided in the program.
1924 2147
1925 \begin{grammar} 2148 \begin{grammar}
1926 {\bf typeParameter:} 2149 {\bf typeParameter:}
1927 metadata identifier (\EXTENDS{} type)? 2150 metadata identifier (\EXTENDS{} type)?
1928 . 2151 .
1929 {\bf typeParameters:} 2152 {\bf typeParameters:}
1930 `<' typeParameter (`,' typeParameter)* `>' 2153 `<' typeParameter (`,' typeParameter)* `>'
1931 . 2154 .
1932 \end{grammar} 2155 \end{grammar}
1933 2156
2157 \LMHash{}
1934 A type parameter $T$ may be suffixed with an \EXTENDS{} clause that specifies th e {\em upper bound} for $T$. If no \EXTENDS{} clause is present, the upper boun d is \code{Object}. It is a static type warning if a type parameter is a supert ype of its upper bound. The bounds of type variables are a form of type annotati on and have no effect on execution in production mode. 2158 A type parameter $T$ may be suffixed with an \EXTENDS{} clause that specifies th e {\em upper bound} for $T$. If no \EXTENDS{} clause is present, the upper boun d is \code{Object}. It is a static type warning if a type parameter is a supert ype of its upper bound. The bounds of type variables are a form of type annotati on and have no effect on execution in production mode.
1935 2159
2160 \LMHash{}
1936 The type parameters of a generic $G$ are in scope in the bounds of all of the ty pe parameters of $G$. The type parameters of a generic class declaration $G$ are also in scope in the \EXTENDS{} and \IMPLEMENTS{} clauses of $G$ (if these exis t) and in the body of $G$. However, a type parameter is considered to be a mal formed type when referenced by a static member. 2161 The type parameters of a generic $G$ are in scope in the bounds of all of the ty pe parameters of $G$. The type parameters of a generic class declaration $G$ are also in scope in the \EXTENDS{} and \IMPLEMENTS{} clauses of $G$ (if these exis t) and in the body of $G$. However, a type parameter is considered to be a mal formed type when referenced by a static member.
1937 2162
1938 \rationale{ 2163 \rationale{
1939 The restriction is necessary since a type variable has no meaning in the context of a static member, because statics are shared among all instantiations of a ge neric. However, a type variable may be referenced from an instance initializer, even though \THIS{} is not available. 2164 The restriction is necessary since a type variable has no meaning in the context of a static member, because statics are shared among all instantiations of a ge neric. However, a type variable may be referenced from an instance initializer, even though \THIS{} is not available.
1940 } 2165 }
1941 2166
1942 \commentary{ 2167 \commentary{
1943 Because type parameters are in scope in their bounds, we support F-bounded quant ification (if you don't know what that is, don't ask). This enables typechecking code such as: 2168 Because type parameters are in scope in their bounds, we support F-bounded quant ification (if you don't know what that is, don't ask). This enables typechecking code such as:
1944 } 2169 }
1945 2170
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2001 2226
2002 2227
2003 %class T {...} 2228 %class T {...}
2004 2229
2005 %class G<T> extends T; 2230 %class G<T> extends T;
2006 2231
2007 %By current rules, this is illegal. Make sure we preserve this. 2232 %By current rules, this is illegal. Make sure we preserve this.
2008 2233
2009 2234
2010 %\subsection{Interface Injection} 2235 %\subsection{Interface Injection}
2011 %\label{interfaceInjection} 2236 %\LMLabel{interfaceInjection}
2012 2237
2013 %An {\em interface injection declaration} causes a pre-existing class $S$ to be considered a subinterface of another interface $I$. It is a static type warning if $S$ is not a structural subtype of $I$. However, the subinterface relations i mplied by the interface injection declaration are considered to hold by both the typechecker and the runtime, regardless. 2238 %An {\em interface injection declaration} causes a pre-existing class $S$ to be considered a subinterface of another interface $I$. It is a static type warning if $S$ is not a structural subtype of $I$. However, the subinterface relations i mplied by the interface injection declaration are considered to hold by both the typechecker and the runtime, regardless.
2014 2239
2015 %\begin{grammar} 2240 %\begin{grammar}
2016 %classInterfaceInjection: 2241 %classInterfaceInjection:
2017 %class qualified typeParameters? interfaces '{\escapegrammar ;}' 2242 %class qualified typeParameters? interfaces '{\escapegrammar ;}'
2018 % . 2243 % .
2019 2244
2020 2245
2021 %interfaceInterfaceInjection: 2246 %interfaceInterfaceInjection:
2022 %interface qualified typeParameters? superinterfaces '{\escapegrammar ;}' 2247 %interface qualified typeParameters? superinterfaces '{\escapegrammar ;}'
2023 %. 2248 %.
2024 %\end{grammar} 2249 %\end{grammar}
2025 2250
2026 %\rationale{Since subinterface relations can be tested dynamically via \IS{}, in terface injection is not just a directive to the static checker. The dynamic rel ations implied must hold regardless of whether a static typecheck has succeeded , or has been performed at all. This makes sense from the perspective of preserv ing programmer intent. The injection describes a nominal type relation that the programmer wishes to hold. Just as a supertype mentioned within a class declarat ion is considered a supertype even though type errors might arise among (say) ov erridden and overriding methods, so it must be that the relation implied by an i njection holds regardless of type errors. 2251 %\rationale{Since subinterface relations can be tested dynamically via \IS{}, in terface injection is not just a directive to the static checker. The dynamic rel ations implied must hold regardless of whether a static typecheck has succeeded , or has been performed at all. This makes sense from the perspective of preserv ing programmer intent. The injection describes a nominal type relation that the programmer wishes to hold. Just as a supertype mentioned within a class declarat ion is considered a supertype even though type errors might arise among (say) ov erridden and overriding methods, so it must be that the relation implied by an i njection holds regardless of type errors.
2027 %In addition, this decision helps to produce meaningful and localized error mess ages. Any errors are reported at the point of injection rather than at program p oints that rely on the relation (a well known problem with structural subtyping in OO systems). 2252 %In addition, this decision helps to produce meaningful and localized error mess ages. Any errors are reported at the point of injection rather than at program p oints that rely on the relation (a well known problem with structural subtyping in OO systems).
2028 %} 2253 %}
2029 2254
2030 %\Q{When does an interface injection take effect? When the containing library is loaded? 2255 %\Q{When does an interface injection take effect? When the containing library is loaded?
2031 %What is the scope of such a declaration? Is it global, or only in the scope of the containing library? The scope of such a declaration is global. 2256 %What is the scope of such a declaration? Is it global, or only in the scope of the containing library? The scope of such a declaration is global.
2032 %An injection must be at top level. Who has the right to inject an interface $I$ into another class $C$? Anybody? But since this affects dynamic behavior, is th is a weird security issue? 2257 %An injection must be at top level. Who has the right to inject an interface $I$ into another class $C$? Anybody? But since this affects dynamic behavior, is th is a weird security issue?
2033 %The current theory is that there is no security within an isolate, and one can never refer to a type from another isolate, so supposedly not an issue. This ass umption (no mutually suspicious code in the same isolate) is suspect but it seem s there is nothing to be done at this point. 2258 %The current theory is that there is no security within an isolate, and one can never refer to a type from another isolate, so supposedly not an issue. This ass umption (no mutually suspicious code in the same isolate) is suspect but it seem s there is nothing to be done at this point.
2034 %If libs are first class, they get created dynamically in order, and new libs mi ght modify the type relations among other libs types - but then it is clear when that happened and order is ok. 2259 %If libs are first class, they get created dynamically in order, and new libs mi ght modify the type relations among other libs types - but then it is clear when that happened and order is ok.
2035 %} 2260 %}
2036 2261
2037 %It is a compile-time error if a type $T$ appears more than once in the implemen ts or eextends clause of an interface injection. 2262 %It is a compile-time error if a type $T$ appears more than once in the implemen ts or eextends clause of an interface injection.
2038 2263
2039 2264
2040 \section{Metadata} 2265 \section{Metadata}
2041 \label{metadata} 2266 \LMLabel{metadata}
2042 2267
2268 \LMHash{}
2043 Dart supports metadata which is used to attach user defined annotations to progr am structures. 2269 Dart supports metadata which is used to attach user defined annotations to progr am structures.
2044 2270
2045 \begin{grammar} 2271 \begin{grammar}
2046 {\bf metadata:} 2272 {\bf metadata:}
2047 (`@' qualified ({\escapegrammar `.'} identifier)? (arguments)?)* 2273 (`@' qualified ({\escapegrammar `.'} identifier)? (arguments)?)*
2048 . 2274 .
2049 \end{grammar} 2275 \end{grammar}
2050 2276
2277 \LMHash{}
2051 Metadata consists of a series of annotations, each of which begin with the chara cter @, followed by a constant expression that starts with an identifier. It is a compile time error if the expression is not one of the following: 2278 Metadata consists of a series of annotations, each of which begin with the chara cter @, followed by a constant expression that starts with an identifier. It is a compile time error if the expression is not one of the following:
2052 \begin{itemize} 2279 \begin{itemize}
2053 \item A reference to a compile-time constant variable. 2280 \item A reference to a compile-time constant variable.
2054 \item A call to a constant constructor. 2281 \item A call to a constant constructor.
2055 \end{itemize} 2282 \end{itemize}
2056 2283
2284 \LMHash{}
2057 Metadata is associated with the abstract syntax tree of the program construct $p $ that immediately follows the metadata, assuming $p$ is not itself metadata or a comment. Metadata can be retrieved at runtime via a reflective call, provided the annotated program construct $p$ is accessible via reflection. 2285 Metadata is associated with the abstract syntax tree of the program construct $p $ that immediately follows the metadata, assuming $p$ is not itself metadata or a comment. Metadata can be retrieved at runtime via a reflective call, provided the annotated program construct $p$ is accessible via reflection.
2058 2286
2059 \commentary{ 2287 \commentary{
2060 Obviously, metadata can also be retrieved statically by parsing the program and evaluating the constants via a suitable interpreter. In fact many if not most us es of metadata are entirely static. 2288 Obviously, metadata can also be retrieved statically by parsing the program and evaluating the constants via a suitable interpreter. In fact many if not most us es of metadata are entirely static.
2061 } 2289 }
2062 2290
2063 \rationale{ 2291 \rationale{
2064 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. 2292 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.
2065 } 2293 }
2066 2294
2067 \commentary{ 2295 \commentary{
2068 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. 2296 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.
2069 } 2297 }
2070 2298
2299 \LMHash{}
2071 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. 2300 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.
2072 2301
2302 \LMHash{}
2073 The constant expression given in an annotation is type checked and evaluated in the scope surrounding the declaration being annotated. 2303 The constant expression given in an annotation is type checked and evaluated in the scope surrounding the declaration being annotated.
2074 2304
2075 2305
2076 \section{Expressions} 2306 \section{Expressions}
2077 \label{expressions} 2307 \LMLabel{expressions}
2078 2308
2309 \LMHash{}
2079 An {\em expression} is a fragment of Dart code that can be evaluated at run time to yield a {\em value}, which is always an object. Every expression has an asso ciated static type (\ref{staticTypes}). Every value has an associated dynamic ty pe (\ref{dynamicTypeSystem}). 2310 An {\em expression} is a fragment of Dart code that can be evaluated at run time to yield a {\em value}, which is always an object. Every expression has an asso ciated static type (\ref{staticTypes}). Every value has an associated dynamic ty pe (\ref{dynamicTypeSystem}).
2080 2311
2081 2312
2082 \begin{grammar} 2313 \begin{grammar}
2083 2314
2084 {\bf expression:}assignableExpression assignmentOperator expression; 2315 {\bf expression:}assignableExpression assignmentOperator expression;
2085 conditionalExpression cascadeSection*; 2316 conditionalExpression cascadeSection*;
2086 throwExpression 2317 throwExpression
2087 . 2318 .
2088 2319
(...skipping 14 matching lines...) Expand all
2103 functionExpression; 2334 functionExpression;
2104 literal; 2335 literal;
2105 identifier; 2336 identifier;
2106 newExpression; 2337 newExpression;
2107 constObjectExpression; 2338 constObjectExpression;
2108 `(' expression `)' 2339 `(' expression `)'
2109 . 2340 .
2110 2341
2111 \end{grammar} 2342 \end{grammar}
2112 2343
2344 \LMHash{}
2113 An expression $e$ may always be enclosed in parentheses, but this never has any semantic effect on $e$. 2345 An expression $e$ may always be enclosed in parentheses, but this never has any semantic effect on $e$.
2114 2346
2115 \commentary{ 2347 \commentary{
2116 Sadly, it may have an effect on the surrounding expression. Given a class $C$ wi th static method $m => 42$, $C.m()$ returns 42, but $(C).m()$ produces a \code{N oSuchMethodError}. This anomaly can be corrected by removing the restrictions o n calling the members of instances of \code{Type}. This issue may be addressed i n future versions of Dart. 2348 Sadly, it may have an effect on the surrounding expression. Given a class $C$ wi th static method $m => 42$, $C.m()$ returns 42, but $(C).m()$ produces a \code{N oSuchMethodError}. This anomaly can be corrected by removing the restrictions o n calling the members of instances of \code{Type}. This issue may be addressed i n future versions of Dart.
2117 } 2349 }
2118 2350
2119 \subsubsection{Object Identity} 2351 \subsubsection{Object Identity}
2120 \label{objectIdentity} 2352 \LMLabel{objectIdentity}
2121 2353
2354 \LMHash{}
2122 The predefined Dart function \cd{identical()} is defined such that \code{identic al($c_1$, $c_2$)} iff: 2355 The predefined Dart function \cd{identical()} is defined such that \code{identic al($c_1$, $c_2$)} iff:
2123 \begin{itemize} 2356 \begin{itemize}
2124 \item $c_1$ evaluates to either \NULL{} or an instance of \code{bool} and \co de{$c_1$ == $c_2$}, OR 2357 \item $c_1$ evaluates to either \NULL{} or an instance of \code{bool} and \co de{$c_1$ == $c_2$}, OR
2125 \item $c_1$ and $c_2$ are instances of \code{int} and \code{$c_1$ == $c_2$}, OR 2358 \item $c_1$ and $c_2$ are instances of \code{int} and \code{$c_1$ == $c_2$}, OR
2126 \item $c_1$ and $c_2$ are constant strings and \code{$c_1$ == $c_2$}, OR 2359 \item $c_1$ and $c_2$ are constant strings and \code{$c_1$ == $c_2$}, OR
2127 \item $c_1$ and $c_2$ are instances of \cd{double} and one of the following holds: 2360 \item $c_1$ and $c_2$ are instances of \cd{double} and one of the following holds:
2128 \begin{itemize} 2361 \begin{itemize}
2129 \item $c_1$ and $c_2$ are non-zero and \code{$c_1$ == $c_2$}. 2362 \item $c_1$ and $c_2$ are non-zero and \code{$c_1$ == $c_2$}.
2130 \item Both $c_1$ and $c_2$ are $+0.0$. 2363 \item Both $c_1$ and $c_2$ are $+0.0$.
2131 \item Both $c_1$ and $c_2$ are $-0.0$. 2364 \item Both $c_1$ and $c_2$ are $-0.0$.
(...skipping 13 matching lines...) Expand all
2145 \rationale{ 2378 \rationale{
2146 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. 2379 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.
2147 2380
2148 The definition of identity is not constrained in the same way. Instead, it assum es that bit-identical doubles are identical. 2381 The definition of identity is not constrained in the same way. Instead, it assum es that bit-identical doubles are identical.
2149 2382
2150 The rules for identity make it impossible for a Dart programmer to observe wheth er a boolean or numerical value is boxed or unboxed. 2383 The rules for identity make it impossible for a Dart programmer to observe wheth er a boolean or numerical value is boxed or unboxed.
2151 } 2384 }
2152 2385
2153 2386
2154 \subsection{Constants} 2387 \subsection{Constants}
2155 \label{constants} 2388 \LMLabel{constants}
2156 2389
2390 \LMHash{}
2157 A {\em constant expression} is an expression whose value can never change, and t hat can be evaluated entirely at compile time. 2391 A {\em constant expression} is an expression whose value can never change, and t hat can be evaluated entirely at compile time.
2158 2392
2393 \LMHash{}
2159 A constant expression is one of the following: 2394 A constant expression is one of the following:
2160 \begin{itemize} 2395 \begin{itemize}
2161 \item A literal number (\ref{numbers}). 2396 \item A literal number (\ref{numbers}).
2162 \item A literal boolean (\ref{booleans}). 2397 \item A literal boolean (\ref{booleans}).
2163 \item A literal string (\ref{strings}) where any interpolated expression (\ref{ stringInterpolation}) is a compile-time constant that evaluates to a numeric, st ring or boolean value or to \NULL{}. 2398 \item A literal string (\ref{strings}) where any interpolated expression (\ref{ stringInterpolation}) is a compile-time constant that evaluates to a numeric, st ring or boolean value or to \NULL{}.
2164 \rationale{It would be tempting to allow string interpolation where the interpol ated value is any compile-time constant. However, this would require running th e \code{toString()} method for constant objects, which could contain arbitrary c ode.} 2399 \rationale{It would be tempting to allow string interpolation where the interpol ated value is any compile-time constant. However, this would require running th e \code{toString()} method for constant objects, which could contain arbitrary c ode.}
2165 \item A literal symbol (\ref{symbols}). 2400 \item A literal symbol (\ref{symbols}).
2166 \item \NULL{} (\ref{null}). 2401 \item \NULL{} (\ref{null}).
2167 \item A qualified reference to a static constant variable (\ref{variables}) that is not qualified by a deferred prefix. 2402 \item A qualified reference to a static constant variable (\ref{variables}) that is not qualified by a deferred prefix.
2168 \commentary {For example, If class C declares a constant static variable v, C.v is a constant. The same is true if C is accessed via a prefix p; p.C.v is a cons tant unless p is a deferred prefix. 2403 \commentary {For example, If class C declares a constant static variable v, C.v is a constant. The same is true if C is accessed via a prefix p; p.C.v is a cons tant unless p is a deferred prefix.
(...skipping 14 matching lines...) Expand all
2183 \item An expression of the form \code{$e_1 + e_2$} where $e_1$ and $e_2$ are con stant expressions that evaluate to a numeric or string value or to \NULL{}. 2418 \item An expression of the form \code{$e_1 + e_2$} where $e_1$ and $e_2$ are con stant expressions that evaluate to a numeric or string value or to \NULL{}.
2184 \item An expression of one of the forms \code{$-e$}, \code{$e_1$ - $e_2$}, \code {$e_1$ * $e_2$}, \code{$e_1$ / $e_2$,} \code{$e_1$ \~{}/ $e_2$}, \code{$e_1 > e_2$}, \code{$e_1 < e_2$}, \code{$e_1$ $>$= $e_2$}, \code{$e_1$ $<$= $e_2$} o r \code{$e_1$ \% $e_2$}, where $e$, $e_1$ and $e_2$ are constant expressions th at evaluate to a numeric value or to \NULL{}. 2419 \item An expression of one of the forms \code{$-e$}, \code{$e_1$ - $e_2$}, \code {$e_1$ * $e_2$}, \code{$e_1$ / $e_2$,} \code{$e_1$ \~{}/ $e_2$}, \code{$e_1 > e_2$}, \code{$e_1 < e_2$}, \code{$e_1$ $>$= $e_2$}, \code{$e_1$ $<$= $e_2$} o r \code{$e_1$ \% $e_2$}, where $e$, $e_1$ and $e_2$ are constant expressions th at evaluate to a numeric value or to \NULL{}.
2185 \item An expression of the form \code{$e_1$?$e_2$:$e3$} where $e_1$, $e_2$ and $ e_3$ are constant expressions and $e_1$ evaluates to a boolean value. 2420 \item An expression of the form \code{$e_1$?$e_2$:$e3$} where $e_1$, $e_2$ and $ e_3$ are constant expressions and $e_1$ evaluates to a boolean value.
2186 \item An expression of the form \code{$e$.length} where $e$ is a constant expres sion that evaluates to a string value. 2421 \item An expression of the form \code{$e$.length} where $e$ is a constant expres sion that evaluates to a string value.
2187 \end{itemize} 2422 \end{itemize}
2188 2423
2189 % null in all the expressions 2424 % null in all the expressions
2190 2425
2191 % designed so constants do not depend on check diode being on or not. 2426 % designed so constants do not depend on check diode being on or not.
2192 2427
2428 \LMHash{}
2193 It is a compile-time error if an expression is required to be a constant express ion but its evaluation would raise an exception. 2429 It is a compile-time error if an expression is required to be a constant express ion but its evaluation would raise an exception.
2194 2430
2195 % so, checked mode? analyzers? editor/development compilers? 2431 % so, checked mode? analyzers? editor/development compilers?
2196 \commentary{ 2432 \commentary{
2197 Note that there is no requirement that every constant expression evaluate correc tly. Only when a constant expression is required (e.g., to initialize a constant variable, or as a default value of a formal parameter, or as metadata) do we in sist that a constant expression actually be evaluated successfully at compile ti me. 2433 Note that there is no requirement that every constant expression evaluate correc tly. Only when a constant expression is required (e.g., to initialize a constant variable, or as a default value of a formal parameter, or as metadata) do we in sist that a constant expression actually be evaluated successfully at compile ti me.
2198 2434
2199 The above is not dependent on program control-flow. The mere presence of a requi red compile time constant whose evaluation would fail within a program is an err or. This also holds recursively: since compound constants are composed out of c onstants, if any subpart of a constant would raise an exception when evaluated, that is an error. 2435 The above is not dependent on program control-flow. The mere presence of a requi red compile time constant whose evaluation would fail within a program is an err or. This also holds recursively: since compound constants are composed out of c onstants, if any subpart of a constant would raise an exception when evaluated, that is an error.
2200 2436
2201 On the other hand, since implementations are free to compile code late, some com pile-time errors may manifest quite late. 2437 On the other hand, since implementations are free to compile code late, some com pile-time errors may manifest quite late.
2202 } 2438 }
(...skipping 22 matching lines...) Expand all
2225 } 2461 }
2226 2462
2227 \rationale{ 2463 \rationale{
2228 The treatment of \NULL{} merits some discussion. Consider \code{\NULL{} + 2}. T his expression always causes an error. We could have chosen not to treat it as a constant expression (and in general, not to allow \NULL{} as a subexpression of numeric or boolean constant expressions). There are two arguments for includin g it: 2464 The treatment of \NULL{} merits some discussion. Consider \code{\NULL{} + 2}. T his expression always causes an error. We could have chosen not to treat it as a constant expression (and in general, not to allow \NULL{} as a subexpression of numeric or boolean constant expressions). There are two arguments for includin g it:
2229 \begin{enumerate} 2465 \begin{enumerate}
2230 \item It is constant. We can evaluate it at compile-time. 2466 \item It is constant. We can evaluate it at compile-time.
2231 \item It seems more useful to give the error stemming from the evaluation explic itly. 2467 \item It seems more useful to give the error stemming from the evaluation explic itly.
2232 \end{enumerate} 2468 \end{enumerate}
2233 } 2469 }
2234 2470
2471 \LMHash{}
2235 It is a compile-time error if the value of a compile-time constant expression de pends on itself. 2472 It is a compile-time error if the value of a compile-time constant expression de pends on itself.
2236 2473
2237 \commentary{ 2474 \commentary{
2238 As an example, consider: 2475 As an example, consider:
2239 } 2476 }
2240 2477
2241 \begin{dartCode} 2478 \begin{dartCode}
2242 \CLASS{} CircularConsts\{ 2479 \CLASS{} CircularConsts\{
2243 // Illegal program - mutually recursive compile-time constants 2480 // Illegal program - mutually recursive compile-time constants
2244 \STATIC{} \CONST{} i = j; // a compile-time constant 2481 \STATIC{} \CONST{} i = j; // a compile-time constant
2245 \STATIC{} \CONST{} j = i; // a compile-time constant 2482 \STATIC{} \CONST{} j = i; // a compile-time constant
2246 \} 2483 \}
2247 \end{dartCode} 2484 \end{dartCode}
2248 2485
2249 2486
2250 \begin{grammar} 2487 \begin{grammar}
2251 {\bf literal:}nullLiteral; 2488 {\bf literal:}nullLiteral;
2252 booleanLiteral; 2489 booleanLiteral;
2253 numericLiteral; 2490 numericLiteral;
2254 stringLiteral; 2491 stringLiteral;
2255 symbolLiteral; 2492 symbolLiteral;
2256 mapLiteral; 2493 mapLiteral;
2257 listLiteral 2494 listLiteral
2258 . 2495 .
2259 \end{grammar} 2496 \end{grammar}
2260 2497
2261 2498
2262 2499
2263 \subsection{Null} 2500 \subsection{Null}
2264 \label{null} 2501 \LMLabel{null}
2265 2502
2503 \LMHash{}
2266 The reserved word \NULL{} denotes the {\em null object}. 2504 The reserved word \NULL{} denotes the {\em null object}.
2267 %\Q{Any methods, such as \code{isNull}?} 2505 %\Q{Any methods, such as \code{isNull}?}
2268 2506
2269 \begin{grammar} 2507 \begin{grammar}
2270 {\bf nullLiteral:} 2508 {\bf nullLiteral:}
2271 \NULL{} 2509 \NULL{}
2272 . 2510 .
2273 \end{grammar} 2511 \end{grammar}
2274 2512
2513 \LMHash{}
2275 The null object is the sole instance of the built-in class \code{Null}. Attempti ng to instantiate \code{Null} causes a run-time error. It is a compile-time erro r for a class to attempt to extend or implement \code{Null}. 2514 The null object is the sole instance of the built-in class \code{Null}. Attempti ng to instantiate \code{Null} causes a run-time error. It is a compile-time erro r for a class to attempt to extend or implement \code{Null}.
2276 Invoking a method on \NULL{} yields a \code{NoSuchMethodError} unless the metho d is explicitly implemented by class \code{Null}. 2515 Invoking a method on \NULL{} yields a \code{NoSuchMethodError} unless the metho d is explicitly implemented by class \code{Null}.
2277 2516
2517 \LMHash{}
2278 The static type of \NULL{} is $\bot$. 2518 The static type of \NULL{} is $\bot$.
2279 2519
2280 \rationale{The decision to use $\bot$ instead of \code{Null} allows \NULL{} to b e be assigned everywhere without complaint by the static checker. 2520 \rationale{The decision to use $\bot$ instead of \code{Null} allows \NULL{} to b e be assigned everywhere without complaint by the static checker.
2281 } 2521 }
2282 2522
2283 2523
2284 \subsection{Numbers} 2524 \subsection{Numbers}
2285 \label{numbers} 2525 \LMLabel{numbers}
2286 2526
2527 \LMHash{}
2287 A {\em numeric literal} is either a decimal or hexadecimal integer of arbitrary size, or a decimal double. 2528 A {\em numeric literal} is either a decimal or hexadecimal integer of arbitrary size, or a decimal double.
2288 2529
2289 \begin{grammar} 2530 \begin{grammar}
2290 {\bf numericLiteral:}NUMBER; 2531 {\bf numericLiteral:}NUMBER;
2291 HEX\_NUMBER 2532 HEX\_NUMBER
2292 . 2533 .
2293 2534
2294 {\bf NUMBER:} DIGIT+ (`{\escapegrammar.}' DIGIT+)? EXPONENT?; 2535 {\bf NUMBER:} DIGIT+ (`{\escapegrammar.}' DIGIT+)? EXPONENT?;
2295 {`\escapegrammar .}' DIGIT+ EXPONENT? 2536 {`\escapegrammar .}' DIGIT+ EXPONENT?
2296 . 2537 .
2297 2538
2298 {\bf EXPONENT:} 2539 {\bf EXPONENT:}
2299 (`e' $|$ `E') ('+' $|$ `-`)? DIGIT+ 2540 (`e' $|$ `E') ('+' $|$ `-`)? DIGIT+
2300 . 2541 .
2301 2542
2302 {\bf HEX\_NUMBER:}`0x' HEX\_DIGIT+; 2543 {\bf HEX\_NUMBER:}`0x' HEX\_DIGIT+;
2303 `0X' HEX\_DIGIT+ 2544 `0X' HEX\_DIGIT+
2304 . 2545 .
2305 2546
2306 {\bf HEX\_DIGIT:}`a'{\escapegrammar ..}'f'; 2547 {\bf HEX\_DIGIT:}`a'{\escapegrammar ..}'f';
2307 `A'{\escapegrammar ..}'F'; 2548 `A'{\escapegrammar ..}'F';
2308 DIGIT 2549 DIGIT
2309 . 2550 .
2310 \end{grammar} 2551 \end{grammar}
2311 2552
2553 \LMHash{}
2312 If a numeric literal begins with the prefix `0x' or `0X', it denotes the hexadec imal integer represented by the part of the literal following `0x' (respectively `0X'). Otherwise, if the numeric literal does not include a decimal point it d enotes a decimal integer. Otherwise, the numeric literal denotes a 64 bit doub le precision floating point number as specified by the IEEE 754 standard. 2554 If a numeric literal begins with the prefix `0x' or `0X', it denotes the hexadec imal integer represented by the part of the literal following `0x' (respectively `0X'). Otherwise, if the numeric literal does not include a decimal point it d enotes a decimal integer. Otherwise, the numeric literal denotes a 64 bit doub le precision floating point number as specified by the IEEE 754 standard.
2313 2555
2556 \LMHash{}
2314 In principle, the range of integers supported by a Dart implementations is unlim ited. In practice, it is limited by available memory. Implementations may also b e limited by other considerations. 2557 In principle, the range of integers supported by a Dart implementations is unlim ited. In practice, it is limited by available memory. Implementations may also b e limited by other considerations.
2315 2558
2316 \commentary{ 2559 \commentary{
2317 For example, implementations may choose to limit the range to facilitate efficie nt compilation to Javascript. These limitations should be relaxed as soon as tec hnologically feasible. 2560 For example, implementations may choose to limit the range to facilitate efficie nt compilation to Javascript. These limitations should be relaxed as soon as tec hnologically feasible.
2318 } 2561 }
2319 2562
2563 \LMHash{}
2320 It is a compile-time error for a class to attempt to extend or implement \code{i nt}. It is a compile-time error for a class to attempt to extend or implement \c ode{double}. It is a compile-time error for any type other than the types \code{ int} and \code{double} to attempt to extend or implement \code{num}. 2564 It is a compile-time error for a class to attempt to extend or implement \code{i nt}. It is a compile-time error for a class to attempt to extend or implement \c ode{double}. It is a compile-time error for any type other than the types \code{ int} and \code{double} to attempt to extend or implement \code{num}.
2321 2565
2566 \LMHash{}
2322 An {\em integer literal} is either a hexadecimal integer literal or a decimal i nteger literal. Invoking the getter \code{runtimeType} on an integer literal ret urns the \code{Type} object that is the value of the expression \code{int}. The static type of an integer literal is \code{int}. 2567 An {\em integer literal} is either a hexadecimal integer literal or a decimal i nteger literal. Invoking the getter \code{runtimeType} on an integer literal ret urns the \code{Type} object that is the value of the expression \code{int}. The static type of an integer literal is \code{int}.
2323 2568
2569 \LMHash{}
2324 A {\em literal double} is a numeric literal that is not an integer literal. Invo king the getter \code{runtimeType} on a literal double returns the \code{Type} o bject that is the value of the expression \code{double}. 2570 A {\em literal double} is a numeric literal that is not an integer literal. Invo king the getter \code{runtimeType} on a literal double returns the \code{Type} o bject that is the value of the expression \code{double}.
2325 The static type of a literal double is \code{double}. 2571 The static type of a literal double is \code{double}.
2326 2572
2327 \subsection{Booleans} 2573 \subsection{Booleans}
2328 \label{booleans} 2574 \LMLabel{booleans}
2329 2575
2576 \LMHash{}
2330 The reserved words \TRUE{} and \FALSE{} denote objects that represent the boolea n values true and false respectively. They are the {\em boolean literals}. 2577 The reserved words \TRUE{} and \FALSE{} denote objects that represent the boolea n values true and false respectively. They are the {\em boolean literals}.
2331 2578
2332 \begin{grammar} 2579 \begin{grammar}
2333 {\bf booleanLiteral:}\TRUE{}; 2580 {\bf booleanLiteral:}\TRUE{};
2334 \FALSE{} 2581 \FALSE{}
2335 . 2582 .
2336 \end{grammar} 2583 \end{grammar}
2337 2584
2585 \LMHash{}
2338 Both \TRUE{} and \FALSE{} implement the built-in class \code{bool}. It is a co mpile-time error for a class to attempt to extend or implement\code{ bool}. 2586 Both \TRUE{} and \FALSE{} implement the built-in class \code{bool}. It is a co mpile-time error for a class to attempt to extend or implement\code{ bool}.
2339 2587
2340 \commentary{ 2588 \commentary{
2341 It follows that the two boolean literals are the only two instances of \code{boo l}. 2589 It follows that the two boolean literals are the only two instances of \code{boo l}.
2342 } 2590 }
2343 2591
2592 \LMHash{}
2344 Invoking the getter \code{runtimeType} on a boolean literal returns the \code{Ty pe} object that is the value of the expression \code{bool}. The static type of a boolean literal is \code{bool}. 2593 Invoking the getter \code{runtimeType} on a boolean literal returns the \code{Ty pe} object that is the value of the expression \code{bool}. The static type of a boolean literal is \code{bool}.
2345 2594
2346 \subsubsection{Boolean Conversion} 2595 \subsubsection{Boolean Conversion}
2347 \label{booleanConversion} 2596 \LMLabel{booleanConversion}
2348 2597
2598 \LMHash{}
2349 {\em Boolean conversion} maps any object $o$ into a boolean. Boolean conversion is defined by the function application 2599 {\em Boolean conversion} maps any object $o$ into a boolean. Boolean conversion is defined by the function application
2350 2600
2351 \begin{dartCode} 2601 \begin{dartCode}
2352 (bool v)\{ 2602 (bool v)\{
2353 \ASSERT{}(v != \NULL{}); 2603 \ASSERT{}(v != \NULL{});
2354 % \IF{} (\NULL{} == v) \{ \THROW{} \NEW{} AssertionError('null is not a bo ol')\}; 2604 % \IF{} (\NULL{} == v) \{ \THROW{} \NEW{} AssertionError('null is not a bo ol')\};
2355 \RETURN{} identical(v, \TRUE{}); 2605 \RETURN{} identical(v, \TRUE{});
2356 \}(o) 2606 \}(o)
2357 \end{dartCode} 2607 \end{dartCode}
2358 2608
2359 \rationale{ 2609 \rationale{
2360 Boolean conversion is used as part of control-flow constructs and boolean expres sions. Ideally, one would simply insist that control-flow decisions be based ex clusively on booleans. This is straightforward in a statically typed setting. I n a dynamically typed language, it requires a dynamic check. Sophisticated virtu al machines can minimize the penalty involved. Alas, Dart must be compiled into Javascript. Boolean conversion allows this to be done efficiently. 2610 Boolean conversion is used as part of control-flow constructs and boolean expres sions. Ideally, one would simply insist that control-flow decisions be based ex clusively on booleans. This is straightforward in a statically typed setting. I n a dynamically typed language, it requires a dynamic check. Sophisticated virtu al machines can minimize the penalty involved. Alas, Dart must be compiled into Javascript. Boolean conversion allows this to be done efficiently.
2361 2611
2362 At the same time, this formulation differs radically from Javascript, where most numbers and objects are interpreted as \TRUE{}. Dart's approach prevents usage s such \code{\IF{} (a-b) ... ; }because it does not agree with the low level con ventions whereby non-null objects or non-zero numbers are treated as \TRUE{}. In deed, there is no way to derive \TRUE{} from a non-boolean object via boolean co nversion, so this kind of low level hackery is nipped in the bud. 2612 At the same time, this formulation differs radically from Javascript, where most numbers and objects are interpreted as \TRUE{}. Dart's approach prevents usage s such \code{\IF{} (a-b) ... ; }because it does not agree with the low level con ventions whereby non-null objects or non-zero numbers are treated as \TRUE{}. In deed, there is no way to derive \TRUE{} from a non-boolean object via boolean co nversion, so this kind of low level hackery is nipped in the bud.
2363 2613
2364 Dart also avoids the strange behaviors that can arise due to the interaction of boolean conversion with autoboxing in Javascript. A notorious example is the sit uation where \FALSE{} can be interpreted as \TRUE{}. In Javascript, booleans are not objects, and instead are autoboxed into objects where ``needed''. If \FALS E{} gets autoboxed into an object, that object can be coerced into \TRUE{} (as i t is a non-null object). 2614 Dart also avoids the strange behaviors that can arise due to the interaction of boolean conversion with autoboxing in Javascript. A notorious example is the sit uation where \FALSE{} can be interpreted as \TRUE{}. In Javascript, booleans are not objects, and instead are autoboxed into objects where ``needed''. If \FALS E{} gets autoboxed into an object, that object can be coerced into \TRUE{} (as i t is a non-null object).
2365 } 2615 }
2366 2616
2367 \commentary{Because boolean conversion requires its parameter to be a boolean, a ny construct that makes use of boolean conversion will cause a dynamic type erro r in checked mode if the value to be converted is not a boolean. 2617 \commentary{Because boolean conversion requires its parameter to be a boolean, a ny construct that makes use of boolean conversion will cause a dynamic type erro r in checked mode if the value to be converted is not a boolean.
2368 } 2618 }
2369 2619
2370 \subsection{Strings} 2620 \subsection{Strings}
2371 \label{strings} 2621 \LMLabel{strings}
2372 2622
2623 \LMHash{}
2373 A {\em string} is a sequence of UTF-16 code units. 2624 A {\em string} is a sequence of UTF-16 code units.
2374 2625
2375 \rationale{ 2626 \rationale{
2376 This decision was made for compatibility with web browsers and Javascript. Earli er versions of the specification required a string to be a sequence of valid Uni code code points. Programmers should not depend on this distinction. 2627 This decision was made for compatibility with web browsers and Javascript. Earli er versions of the specification required a string to be a sequence of valid Uni code code points. Programmers should not depend on this distinction.
2377 } 2628 }
2378 2629
2379 \begin{grammar} 2630 \begin{grammar}
2380 {\bf stringLiteral:}(multilineString $|$ singleLineString)+ 2631 {\bf stringLiteral:}(multilineString $|$ singleLineString)+
2381 . 2632 .
2382 \end{grammar} 2633 \end{grammar}
2383 2634
2635 \LMHash{}
2384 A string can be either a sequence of single line strings or a multiline string. 2636 A string can be either a sequence of single line strings or a multiline string.
2385 2637
2386 \begin{grammar} 2638 \begin{grammar}
2387 {\bf singleLineString:}`{\escapegrammar \code{"}}' stringContentDQ* `{\escapegr ammar \code{"}}'; 2639 {\bf singleLineString:}`{\escapegrammar \code{"}}' stringContentDQ* `{\escapegr ammar \code{"}}';
2388 `{\escapegrammar \code{'}}' stringContentSQ* `{\escapegrammar \code{'}}'; 2640 `{\escapegrammar \code{'}}' stringContentSQ* `{\escapegrammar \code{'}}';
2389 `r' `{\escapegrammar \code{'}}' (\~{}( `{\escapegrammar \code{'}}' $|$ NEW LINE ))* `{\escapegrammar \code{'}}'; 2641 `r' `{\escapegrammar \code{'}}' (\~{}( `{\escapegrammar \code{'}}' $|$ NEW LINE ))* `{\escapegrammar \code{'}}';
2390 `r' `{\escapegrammar \code{"}}' (\~{}( `{\escapegrammar \code{"}}' $|$ NEW LINE ))* `{\escapegrammar \code{"}}' 2642 `r' `{\escapegrammar \code{"}}' (\~{}( `{\escapegrammar \code{"}}' $|$ NEW LINE ))* `{\escapegrammar \code{"}}'
2391 . 2643 .
2392 \end{grammar} 2644 \end{grammar}
2393 2645
2646 \LMHash{}
2394 A single line string is delimited by either matching single quotes or matching d ouble quotes. 2647 A single line string is delimited by either matching single quotes or matching d ouble quotes.
2395 2648
2396 \commentary{ 2649 \commentary{
2397 Hence, `abc' and ``abc'' are both legal strings, as are `He said ``To be or not to be'' did he not?' and ``He said `To be or not to be' didn't he''. However ` `This ` is not a valid string, nor is `this''. 2650 Hence, `abc' and ``abc'' are both legal strings, as are `He said ``To be or not to be'' did he not?' and ``He said `To be or not to be' didn't he''. However ` `This ` is not a valid string, nor is `this''.
2398 } 2651 }
2399 2652
2400 \commentary{The grammar ensures that a single line string cannot span more than one line of source code, unless it includes an interpolated expression that span s multiple lines. 2653 \commentary{The grammar ensures that a single line string cannot span more than one line of source code, unless it includes an interpolated expression that span s multiple lines.
2401 } 2654 }
2402 2655
2656 \LMHash{}
2403 Adjacent 2657 Adjacent
2404 %single line 2658 %single line
2405 strings are implicitly concatenated to form a single string literal. 2659 strings are implicitly concatenated to form a single string literal.
2406 %, and so are adjacent multiline strings, but the two forms may not be mixed. 2660 %, and so are adjacent multiline strings, but the two forms may not be mixed.
2407 2661
2408 2662
2409 \commentary{Here is an example} 2663 \commentary{Here is an example}
2410 2664
2411 \begin{dartCode} 2665 \begin{dartCode}
2412 print("A string" "and then another"); // prints: A stringand then another 2666 print("A string" "and then another"); // prints: A stringand then another
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2465 `$\backslash$ u' HEX\_DIGIT HEX\_DIGIT HEX\_DIGIT HEX\_DIGIT; 2719 `$\backslash$ u' HEX\_DIGIT HEX\_DIGIT HEX\_DIGIT HEX\_DIGIT;
2466 `$\backslash$ u\{' HEX\_DIGIT\_SEQUENCE `\}' 2720 `$\backslash$ u\{' HEX\_DIGIT\_SEQUENCE `\}'
2467 . 2721 .
2468 2722
2469 {\bf HEX\_DIGIT\_SEQUENCE:} 2723 {\bf HEX\_DIGIT\_SEQUENCE:}
2470 HEX\_DIGIT HEX\_DIGIT? HEX\_DIGIT? HEX\_DIGIT? HEX\_DIGIT? HEX\_DIGIT? 2724 HEX\_DIGIT HEX\_DIGIT? HEX\_DIGIT? HEX\_DIGIT? HEX\_DIGIT? HEX\_DIGIT?
2471 . 2725 .
2472 2726
2473 \end{grammar} 2727 \end{grammar}
2474 2728
2729 \LMHash{}
2475 Multiline strings are delimited by either matching triples of single quotes or m atching triples of double quotes. If the first line of a multiline string consis ts solely of the whitespace characters defined by the production {\em WHITESPACE } \ref{lexicalRules}), possibly prefixed by $\backslash$, then that line is ign ored, including the new line at its end. 2730 Multiline strings are delimited by either matching triples of single quotes or m atching triples of double quotes. If the first line of a multiline string consis ts solely of the whitespace characters defined by the production {\em WHITESPACE } \ref{lexicalRules}), possibly prefixed by $\backslash$, then that line is ign ored, including the new line at its end.
2476 2731
2477 2732
2478 \rationale{ 2733 \rationale{
2479 The idea is to ignore whitespace, where whitespace is defined as tabs, spaces a nd newlines. These can be represented directly, but since for most characters pr efixing by backslash is an identity, we allow those forms as well. 2734 The idea is to ignore whitespace, where whitespace is defined as tabs, spaces a nd newlines. These can be represented directly, but since for most characters pr efixing by backslash is an identity, we allow those forms as well.
2480 } 2735 }
2481 2736
2737 \LMHash{}
2482 Strings support escape sequences for special characters. The escapes are: 2738 Strings support escape sequences for special characters. The escapes are:
2483 \begin{itemize} 2739 \begin{itemize}
2484 \item $\backslash$n for newline, equivalent to $\backslash$x0A. 2740 \item $\backslash$n for newline, equivalent to $\backslash$x0A.
2485 \item $\backslash$r for carriage return, equivalent to $\backslash$x0D. 2741 \item $\backslash$r for carriage return, equivalent to $\backslash$x0D.
2486 \item $\backslash$f for form feed, equivalent to $\backslash$x0C. 2742 \item $\backslash$f for form feed, equivalent to $\backslash$x0C.
2487 \item $\backslash$b for backspace, equivalent to $\backslash$x08. 2743 \item $\backslash$b for backspace, equivalent to $\backslash$x08.
2488 \item $\backslash$t for tab, equivalent to $\backslash$x09. 2744 \item $\backslash$t for tab, equivalent to $\backslash$x09.
2489 \item $\backslash$v for vertical tab, equivalent to $\backslash$x0B 2745 \item $\backslash$v for vertical tab, equivalent to $\backslash$x0B
2490 \item $\backslash$x $HEX\_DIGIT_1$ $HEX\_DIGIT_2$, equivalent to 2746 \item $\backslash$x $HEX\_DIGIT_1$ $HEX\_DIGIT_2$, equivalent to
2491 2747
2492 $\backslash$u\{$HEX\_DIGIT_1$ $HEX\_DIGIT_2$\}. 2748 $\backslash$u\{$HEX\_DIGIT_1$ $HEX\_DIGIT_2$\}.
2493 \item $\backslash$u $HEX\_DIGIT_1$ $HEX\_DIGIT_2$ $HEX\_DIGIT_3$ $HEX\_DIGIT_4$, equivalent to $\backslash$u\{$HEX\_DIGIT_1$ $HEX\_DIGIT_2$ $HEX\_DIGIT_3$ $HEX\ _DIGIT_4$\}. 2749 \item $\backslash$u $HEX\_DIGIT_1$ $HEX\_DIGIT_2$ $HEX\_DIGIT_3$ $HEX\_DIGIT_4$, equivalent to $\backslash$u\{$HEX\_DIGIT_1$ $HEX\_DIGIT_2$ $HEX\_DIGIT_3$ $HEX\ _DIGIT_4$\}.
2494 \item $\backslash$u\{$HEX\_DIGIT\_SEQUENCE$\} is the unicode scalar value repres ented by the $HEX\_DIGIT\_SEQUENCE$. It is a compile-time error if the value of the $HEX\_DIGIT\_SEQUENCE$ is not a valid unicode scalar value. 2750 \item $\backslash$u\{$HEX\_DIGIT\_SEQUENCE$\} is the unicode scalar value repres ented by the $HEX\_DIGIT\_SEQUENCE$. It is a compile-time error if the value of the $HEX\_DIGIT\_SEQUENCE$ is not a valid unicode scalar value.
2495 \item \$ indicating the beginning of an interpolated expression. 2751 \item \$ indicating the beginning of an interpolated expression.
2496 \item Otherwise, $\backslash k$ indicates the character $k$ for any $k$ not in $ \{n, r, f, b, t, v, x, u\}$. 2752 \item Otherwise, $\backslash k$ indicates the character $k$ for any $k$ not in $ \{n, r, f, b, t, v, x, u\}$.
2497 \end{itemize} 2753 \end{itemize}
2498 2754
2755 \LMHash{}
2499 Any string may be prefixed with the character `r', indicating that it is a {\em raw string}, in which case no escapes or interpolations are recognized. 2756 Any string may be prefixed with the character `r', indicating that it is a {\em raw string}, in which case no escapes or interpolations are recognized.
2500 2757
2758 \LMHash{}
2501 It is a compile-time error if a non-raw string literal contains a character sequ ence of the form $\backslash$x that is not followed by a sequence of two hexadec imal digits. It is a compile-time error if a non-raw string literal contains a character sequence of the form $\backslash$u that is not followed by either a se quence of four hexadecimal digits, or by curly brace delimited sequence of hexad ecimal digits. 2759 It is a compile-time error if a non-raw string literal contains a character sequ ence of the form $\backslash$x that is not followed by a sequence of two hexadec imal digits. It is a compile-time error if a non-raw string literal contains a character sequence of the form $\backslash$u that is not followed by either a se quence of four hexadecimal digits, or by curly brace delimited sequence of hexad ecimal digits.
2502 2760
2503 2761
2504 2762
2505 \begin{grammar} 2763 \begin{grammar}
2506 {\bf stringContentDQ:}\~{}( `$\backslash$' $|$ `{\escapegrammar \texttt{"}}' $| $ `\$' $|$ NEWLINE ); 2764 {\bf stringContentDQ:}\~{}( `$\backslash$' $|$ `{\escapegrammar \texttt{"}}' $| $ `\$' $|$ NEWLINE );
2507 `$\backslash$' \~{}( NEWLINE ); 2765 `$\backslash$' \~{}( NEWLINE );
2508 stringInterpolation 2766 stringInterpolation
2509 . 2767 .
2510 2768
(...skipping 10 matching lines...) Expand all
2521 {\bf stringContentTSQ:}\~{}( `$\backslash$' $|$ `{\escapegrammar \code{'}\code{ '}\code{'}}' $|$ `\$'); 2779 {\bf stringContentTSQ:}\~{}( `$\backslash$' $|$ `{\escapegrammar \code{'}\code{ '}\code{'}}' $|$ `\$');
2522 stringInterpolation 2780 stringInterpolation
2523 . 2781 .
2524 2782
2525 {\bf NEWLINE:}$\backslash$ n; 2783 {\bf NEWLINE:}$\backslash$ n;
2526 $\backslash$ r 2784 $\backslash$ r
2527 . 2785 .
2528 2786
2529 \end{grammar} 2787 \end{grammar}
2530 2788
2789 \LMHash{}
2531 All string literals implement the built-in class \code{String}. It is a compile- time error for a class to attempt to extend or implement \code{String}. Invoking the getter \code{runtimeType} on a string literal returns the \code{Type} objec t that is the value of the expression \code{String}. The static type of a string literal is \code{String}. 2790 All string literals implement the built-in class \code{String}. It is a compile- time error for a class to attempt to extend or implement \code{String}. Invoking the getter \code{runtimeType} on a string literal returns the \code{Type} objec t that is the value of the expression \code{String}. The static type of a string literal is \code{String}.
2532 2791
2533 \subsubsection{String Interpolation} 2792 \subsubsection{String Interpolation}
2534 \label{stringInterpolation} 2793 \LMLabel{stringInterpolation}
2535 2794
2795 \LMHash{}
2536 It is possible to embed expressions within non-raw string literals, such that th e these expressions are evaluated, and the resulting values are converted into s trings and concatenated with the enclosing string. This process is known as {\em string interpolation}. 2796 It is possible to embed expressions within non-raw string literals, such that th e these expressions are evaluated, and the resulting values are converted into s trings and concatenated with the enclosing string. This process is known as {\em string interpolation}.
2537 2797
2538 \begin{grammar} 2798 \begin{grammar}
2539 {\bf stringInterpolation:}`\$' IDENTIFIER\_NO\_DOLLAR; 2799 {\bf stringInterpolation:}`\$' IDENTIFIER\_NO\_DOLLAR;
2540 `\$' `\{' expression `\}' % could be top level expression, no? 2800 `\$' `\{' expression `\}' % could be top level expression, no?
2541 . 2801 .
2542 \end{grammar} 2802 \end{grammar}
2543 2803
2544 \commentary{The reader will note that the expression inside the interpolation co uld itself include strings, which could again be interpolated recursively. 2804 \commentary{The reader will note that the expression inside the interpolation co uld itself include strings, which could again be interpolated recursively.
2545 } 2805 }
2546 2806
2807 \LMHash{}
2547 An unescaped \$ character in a string signifies the beginning of an interpolated expression. The \$ sign may be followed by either: 2808 An unescaped \$ character in a string signifies the beginning of an interpolated expression. The \$ sign may be followed by either:
2548 \begin{itemize} 2809 \begin{itemize}
2549 \item A single identifier $id$ that must not contain the \$ character. 2810 \item A single identifier $id$ that must not contain the \$ character.
2550 \item An expression $e$ delimited by curly braces. 2811 \item An expression $e$ delimited by curly braces.
2551 \end{itemize} 2812 \end{itemize}
2552 2813
2814 \LMHash{}
2553 The form \code{\$id} is equivalent to the form \code{\$\{id\}}. An interpolated string \code{`$s_1$\$\{$e$\}$s_2$'} is equivalent to the concatenation of the strings \code{`$s_1$'}, \code{$e$.toString()} and \code{$`s_2$'}. Likewise an interpolated string \code{``$s_1$\$\{e\}$s_2$''} is equivalent to the concatena tion of the strings \code{``$s_1$''}, \code{$e$.toString()} and \code{``$s_2$'' }. 2815 The form \code{\$id} is equivalent to the form \code{\$\{id\}}. An interpolated string \code{`$s_1$\$\{$e$\}$s_2$'} is equivalent to the concatenation of the strings \code{`$s_1$'}, \code{$e$.toString()} and \code{$`s_2$'}. Likewise an interpolated string \code{``$s_1$\$\{e\}$s_2$''} is equivalent to the concatena tion of the strings \code{``$s_1$''}, \code{$e$.toString()} and \code{``$s_2$'' }.
2554 2816
2555 \subsection{Symbols} 2817 \subsection{Symbols}
2556 \label{symbols} 2818 \LMLabel{symbols}
2557 2819
2820 \LMHash{}
2558 A {\em symbol literal} denotes the name of a declaration in a Dart program. 2821 A {\em symbol literal} denotes the name of a declaration in a Dart program.
2559 2822
2560 \begin{grammar} 2823 \begin{grammar}
2561 {\bf symbolLiteral:} 2824 {\bf symbolLiteral:}
2562 `\#' (operator $|$ (identifier (`{\escapegrammar .}' identifier)*)) . 2825 `\#' (operator $|$ (identifier (`{\escapegrammar .}' identifier)*)) .
2563 \end{grammar} 2826 \end{grammar}
2564 2827
2565 A symbol literal \code{\#id} where \code{id} does not begin with an underscore ( Ô\code{\_}Õ) is equivalent to the expression \code{\CONST{} Symbol(ÔidÕ)}. 2828 \LMHash{}
2829 A symbol literal \code{\#id} where \code{id} does not begin with an underscore ( `\code{\_}') is equivalent to the expression \code{\CONST{} Symbol(`id')}.
2566 2830
2567 A symbol literal \code{\#\_id} evaluates to the object that would be returned by the call \code{mirror.getPrivateSymbol(ÔidÕ)} where mirror is an instance of th e class \code{LibraryMirror} defined in the library \code{dart:mirrors}, reflect ing the current library. 2831 \LMHash{}
2832 A symbol literal \code{\#\_id} evaluates to the object that would be returned by the call \code{mirror.getPrivateSymbol(`id')} where mirror is an instance of th e class \code{LibraryMirror} defined in the library \code{dart:mirrors}, reflect ing the current library.
2568 2833
2569 \rationale{ 2834 \rationale{
2570 One may well ask what is the motivation for introducing literal symbols? In some languages, symbols are canonicalized whereas strings are not. However literal s trings are already canonicalized in Dart. Symbols are slightly easier to type c ompared to strings and their use can become strangely addictive, but this is not nearly sufficient justification for adding a literal form to the language. The primary motivation is related to the use of reflection and a web specific practi ce known as minification. 2835 One may well ask what is the motivation for introducing literal symbols? In some languages, symbols are canonicalized whereas strings are not. However literal s trings are already canonicalized in Dart. Symbols are slightly easier to type c ompared to strings and their use can become strangely addictive, but this is not nearly sufficient justification for adding a literal form to the language. The primary motivation is related to the use of reflection and a web specific practi ce known as minification.
2571 2836
2572 Minification compresses identifiers consistently throughout a program in order t o reduce download size. This practice poses difficulties for reflective program s that refer to program declarations via strings. A string will refer to an iden tifier in the source, but the identifier will no longer be used in the minified code, and reflective code using these truing would fail. Therefore, Dart reflec tion uses objects of type \code{Symbol} rather than strings. Instances of \code {Symbol} are guaranteed to be stable with repeat to minification. Providing a li teral form for symbols makes reflective code easier to read and write. The fact that symbols are easy to type and can often act as convenient substitutes for en ums are secondary benefits. 2837 Minification compresses identifiers consistently throughout a program in order t o reduce download size. This practice poses difficulties for reflective program s that refer to program declarations via strings. A string will refer to an iden tifier in the source, but the identifier will no longer be used in the minified code, and reflective code using these truing would fail. Therefore, Dart reflec tion uses objects of type \code{Symbol} rather than strings. Instances of \code {Symbol} are guaranteed to be stable with repeat to minification. Providing a li teral form for symbols makes reflective code easier to read and write. The fact that symbols are easy to type and can often act as convenient substitutes for en ums are secondary benefits.
2573 } 2838 }
2574 2839
2840 \LMHash{}
2575 The static type of a symbol literal is \code{Symbol}. 2841 The static type of a symbol literal is \code{Symbol}.
2576 2842
2577 \subsection{Lists} 2843 \subsection{Lists}
2578 \label{lists} 2844 \LMLabel{lists}
2579 2845
2846 \LMHash{}
2580 A {\em list literal} denotes a list, which is an integer indexed collection of o bjects. 2847 A {\em list literal} denotes a list, which is an integer indexed collection of o bjects.
2581 2848
2582 \begin{grammar} 2849 \begin{grammar}
2583 {\bf listLiteral:} 2850 {\bf listLiteral:}
2584 \CONST{}? typeArguments? `[' (expressionList `,'?)? `]' 2851 \CONST{}? typeArguments? `[' (expressionList `,'?)? `]'
2585 . 2852 .
2586 \end{grammar} 2853 \end{grammar}
2587 2854
2855 \LMHash{}
2588 A list may contain zero or more objects. The number of elements in a list is its size. A list has an associated set of indices. An empty list has an empty set of indices. A non-empty list has the index set $\{0 \ldots n -1\}$ where $n$ is the size of the list. It is a runtime error to attempt to access a list using an index that is not a member of its set of indices. 2856 A list may contain zero or more objects. The number of elements in a list is its size. A list has an associated set of indices. An empty list has an empty set of indices. A non-empty list has the index set $\{0 \ldots n -1\}$ where $n$ is the size of the list. It is a runtime error to attempt to access a list using an index that is not a member of its set of indices.
2589 2857
2590 2858
2859 \LMHash{}
2591 If a list literal begins with the reserved word \CONST{}, it is a {\em constant list literal} which is a compile-time constant (\ref{constants}) and therefore e valuated at compile-time. Otherwise, it is a {\em run-time list literal} and it is evaluated at run-time. Only run-time list literals can be mutated 2860 If a list literal begins with the reserved word \CONST{}, it is a {\em constant list literal} which is a compile-time constant (\ref{constants}) and therefore e valuated at compile-time. Otherwise, it is a {\em run-time list literal} and it is evaluated at run-time. Only run-time list literals can be mutated
2592 after they are created. Attempting to mutate a constant list literal will result in a dynamic error. 2861 after they are created. Attempting to mutate a constant list literal will result in a dynamic error.
2593 2862
2863 \LMHash{}
2594 It is a compile-time error if an element of a constant list literal is not a com pile-time constant. It is a compile-time error if the type argument of a constan t list literal includes a type parameter. 2864 It is a compile-time error if an element of a constant list literal is not a com pile-time constant. It is a compile-time error if the type argument of a constan t list literal includes a type parameter.
2595 \rationale{The binding of a type parameter is not known at compile-time, so we c annot use type parameters inside compile-time constants.} 2865 \rationale{The binding of a type parameter is not known at compile-time, so we c annot use type parameters inside compile-time constants.}
2596 2866
2867 \LMHash{}
2597 The value of a constant list literal \CONST{} $<E>[e_1\ldots e_n]$ is an object $a$ whose class implements the built-in class $List<E>$. The $i$th element of $ a$ is $v_{i+1}$, where $v_i$ is the value of the compile-time expression $e_i$. The value of a constant list literal \CONST{} $[e_1 \ldots e_n]$ is defined as the value of the constant list literal \CONST{}$ < \DYNAMIC{}>[e_1\ldots e_n]$. 2868 The value of a constant list literal \CONST{} $<E>[e_1\ldots e_n]$ is an object $a$ whose class implements the built-in class $List<E>$. The $i$th element of $ a$ is $v_{i+1}$, where $v_i$ is the value of the compile-time expression $e_i$. The value of a constant list literal \CONST{} $[e_1 \ldots e_n]$ is defined as the value of the constant list literal \CONST{}$ < \DYNAMIC{}>[e_1\ldots e_n]$.
2598 2869
2870 \LMHash{}
2599 Let $list_1 =$ \CONST{} $<V>[e_{11} \ldots e_{1n}]$ and $list_2 =$ \CONST{} $<U >[e_{21} \ldots e_{2n}]$ be two constant list literals and let the elements of $list_1$ and $list_2$ evaluate to $o_{11} \ldots o_{1n}$ and $o_{21} \ldots o_ {2n}$ respectively. Iff \code{identical($o_{1i}$, $o_{2i}$)} for $i \in 1.. n$ a nd $V = U$ then \code{identical($list_1$, $list_2$)}. 2871 Let $list_1 =$ \CONST{} $<V>[e_{11} \ldots e_{1n}]$ and $list_2 =$ \CONST{} $<U >[e_{21} \ldots e_{2n}]$ be two constant list literals and let the elements of $list_1$ and $list_2$ evaluate to $o_{11} \ldots o_{1n}$ and $o_{21} \ldots o_ {2n}$ respectively. Iff \code{identical($o_{1i}$, $o_{2i}$)} for $i \in 1.. n$ a nd $V = U$ then \code{identical($list_1$, $list_2$)}.
2600 2872
2601 \commentary{In other words, constant list literals are canonicalized.} 2873 \commentary{In other words, constant list literals are canonicalized.}
2602 2874
2875 \LMHash{}
2603 A run-time list literal $<E>[e_1 \ldots e_n]$ is evaluated as follows: 2876 A run-time list literal $<E>[e_1 \ldots e_n]$ is evaluated as follows:
2604 \begin{itemize} 2877 \begin{itemize}
2605 \item 2878 \item
2606 First, the expressions $e_1 \ldots e_n$ are evaluated in order they appear in th e program, yielding objects $o_1 \ldots o_n$. 2879 First, the expressions $e_1 \ldots e_n$ are evaluated in order they appear in th e program, yielding objects $o_1 \ldots o_n$.
2607 \item A fresh instance (\ref{generativeConstructors}) $a$, of size $n$, whose class implements the built-in class $List<E>$ is allocated. 2880 \item A fresh instance (\ref{generativeConstructors}) $a$, of size $n$, whose class implements the built-in class $List<E>$ is allocated.
2608 \item 2881 \item
2609
2610 The operator \code{[]=} is invoked on $a$ with first argument $i$ and second a rgument 2882 The operator \code{[]=} is invoked on $a$ with first argument $i$ and second a rgument
2611 %The $i$th element of $a$ is set to 2883 %The $i$th element of $a$ is set to
2612 $o_{i+1}, 0 \le i < n$. 2884 $o_{i+1}, 0 \le i < n$.
2613 \item 2885 \item
2614 The result of the evaluation is $a$. 2886 The result of the evaluation is $a$.
2615 \end{itemize} 2887 \end{itemize}
2616 2888
2617 2889
2618 \commentary{ 2890 \commentary{
2619 Note that this document does not specify an order in which the elements are set. This allows for parallel assignments into the list if an implementation so desi res. The order can only be observed in checked mode (and may not be relied upon ): if element $i$ is not a subtype of the element type of the list, a dynamic ty pe error will occur when $a[i]$ is assigned $o_{i-1}$. 2891 Note that this document does not specify an order in which the elements are set. This allows for parallel assignments into the list if an implementation so desi res. The order can only be observed in checked mode (and may not be relied upon ): if element $i$ is not a subtype of the element type of the list, a dynamic ty pe error will occur when $a[i]$ is assigned $o_{i-1}$.
2620 } 2892 }
2621 2893
2894 \LMHash{}
2622 A runtime list literal $[e_1 \ldots e_n]$ is evaluated as $< \DYNAMIC{}>[e_1\l dots e_n]$. 2895 A runtime list literal $[e_1 \ldots e_n]$ is evaluated as $< \DYNAMIC{}>[e_1\l dots e_n]$.
2623 2896
2624 2897
2625 \commentary{ 2898 \commentary{
2626 There is no restriction precluding nesting of list literals. It follows from the rules above that 2899 There is no restriction precluding nesting of list literals. It follows from the rules above that
2627 $<List<int>>[[1, 2, 3], [4, 5, 6]]$ is a list with type parameter $List<int>$, c ontaining two lists with type parameter \DYNAMIC{}. 2900 $<List<int>>[[1, 2, 3], [4, 5, 6]]$ is a list with type parameter $List<int>$, c ontaining two lists with type parameter \DYNAMIC{}.
2628 } 2901 }
2629 2902
2903 \LMHash{}
2630 The static type of a list literal of the form \CONST{}$ <E>[e_1\ldots e_n]$ or the form $<E>[e_1 \ldots e_n]$ is $List<E>$. The static type a list literal of the form \CONST{} $[e_1 \ldots e_n$] or the form $[e_1\ldots e_n$] is $List< \ DYNAMIC{}>$. 2904 The static type of a list literal of the form \CONST{}$ <E>[e_1\ldots e_n]$ or the form $<E>[e_1 \ldots e_n]$ is $List<E>$. The static type a list literal of the form \CONST{} $[e_1 \ldots e_n$] or the form $[e_1\ldots e_n$] is $List< \ DYNAMIC{}>$.
2631 2905
2632 \rationale{ 2906 \rationale{
2633 It is tempting to assume that the type of the list literal would be computed bas ed on the types of its elements. However, for mutable lists this may be unwarran ted. Even for constant lists, we found this behavior to be problematic. Since co mpile-time is often actually runtime, the runtime system must be able to perform a complex least upper bound computation to determine a reasonably precise type. It is better to leave this task to a tool in the IDE. It is also much more unif orm (and therefore predictable and understandable) to insist that whenever types are unspecified they are assumed to be the unknown type \DYNAMIC{}. 2907 It is tempting to assume that the type of the list literal would be computed bas ed on the types of its elements. However, for mutable lists this may be unwarran ted. Even for constant lists, we found this behavior to be problematic. Since co mpile-time is often actually runtime, the runtime system must be able to perform a complex least upper bound computation to determine a reasonably precise type. It is better to leave this task to a tool in the IDE. It is also much more unif orm (and therefore predictable and understandable) to insist that whenever types are unspecified they are assumed to be the unknown type \DYNAMIC{}.
2634 } 2908 }
2635 2909
2636 %Invoking the getter \code{runtimeType} on a list literal returns the \code{Type } object that is the value of the expression \code{List}. The static type of a l ist literal is \code{List}. 2910 %Invoking the getter \code{runtimeType} on a list literal returns the \code{Type } object that is the value of the expression \code{List}. The static type of a l ist literal is \code{List}.
2637 % what about generics? 2911 % what about generics?
2638 2912
2639 \subsection{Maps} 2913 \subsection{Maps}
2640 \label{maps} 2914 \LMLabel{maps}
2641 2915
2916 \LMHash{}
2642 A {\em map literal} denotes a map object. 2917 A {\em map literal} denotes a map object.
2643 2918
2644 \begin{grammar} 2919 \begin{grammar}
2645 {\bf mapLiteral:} 2920 {\bf mapLiteral:}
2646 \CONST{}? typeArguments? `\{' (mapLiteralEntry (`,' mapLiteralEntry)* `,' ?)? `\}' 2921 \CONST{}? typeArguments? `\{' (mapLiteralEntry (`,' mapLiteralEntry)* `,' ?)? `\}'
2647 . 2922 .
2648 2923
2649 {\bf mapLiteralEntry:} 2924 {\bf mapLiteralEntry:}
2650 % identifier `{\escapegrammar :}' expression; 2925 % identifier `{\escapegrammar :}' expression;
2651 expression `{\escapegrammar :}' expression 2926 expression `{\escapegrammar :}' expression
2652 . 2927 .
2653 \end{grammar} 2928 \end{grammar}
2654 2929
2930 \LMHash{}
2655 A {\em map literal} consists of zero or more entries. Each entry has a {\em key} and a {\em value}. Each key and each value is denoted by an expression. 2931 A {\em map literal} consists of zero or more entries. Each entry has a {\em key} and a {\em value}. Each key and each value is denoted by an expression.
2656 2932
2933 \LMHash{}
2657 If a map literal begins with the reserved word \CONST{}, it is a {\em constant m ap literal} which is a compile-time constant (\ref{constants}) and therefore eva luated at compile-time. Otherwise, it is a {\em run-time map literal} and it is evaluated at run-time. Only run-time map literals can be mutated 2934 If a map literal begins with the reserved word \CONST{}, it is a {\em constant m ap literal} which is a compile-time constant (\ref{constants}) and therefore eva luated at compile-time. Otherwise, it is a {\em run-time map literal} and it is evaluated at run-time. Only run-time map literals can be mutated
2658 after they are created. Attempting to mutate a constant map literal will result in a dynamic error. 2935 after they are created. Attempting to mutate a constant map literal will result in a dynamic error.
2659 2936
2937 \LMHash{}
2660 It is a compile-time error if either a key or a value of an entry in a constant map literal is not a compile-time constant. It is a compile-time error if the ke y of an entry in a constant map literal is an instance of a class that implement s the operator $==$ unless the key is a 2938 It is a compile-time error if either a key or a value of an entry in a constant map literal is not a compile-time constant. It is a compile-time error if the ke y of an entry in a constant map literal is an instance of a class that implement s the operator $==$ unless the key is a
2661 %symbol, 2939 %symbol,
2662 string, an integer, a literal symbol or the result of invoking a constant constr uctor of class \cd{Symbol}. 2940 string, an integer, a literal symbol or the result of invoking a constant constr uctor of class \cd{Symbol}.
2663 It is a compile-time error if the type arguments of a constant map literal inclu de a type parameter. 2941 It is a compile-time error if the type arguments of a constant map literal inclu de a type parameter.
2664 2942
2943 \LMHash{}
2665 The value of a constant map literal \CONST{}$ <K, V>\{k_1:e_1\ldots k_n :e_n\}$ is an object $m$ whose class implements the built-in class $Map<K, V>$. The ent ries of $m$ are $u_i:v_i, i \in 1 .. n$, where $u_i$ is the value of the compile -time expression $k_i$ and $v_i$ is the value of the compile-time expression $e_ i$. The value of a constant map literal \CONST{} $\{k_1:e_1\ldots k_n :e_n\}$ is defined as the value of a constant map literal \CONST{} $<\DYNAMIC{}, \DYNAMI C{}>\{k_1:e_1\ldots k_n :e_n\}$. 2944 The value of a constant map literal \CONST{}$ <K, V>\{k_1:e_1\ldots k_n :e_n\}$ is an object $m$ whose class implements the built-in class $Map<K, V>$. The ent ries of $m$ are $u_i:v_i, i \in 1 .. n$, where $u_i$ is the value of the compile -time expression $k_i$ and $v_i$ is the value of the compile-time expression $e_ i$. The value of a constant map literal \CONST{} $\{k_1:e_1\ldots k_n :e_n\}$ is defined as the value of a constant map literal \CONST{} $<\DYNAMIC{}, \DYNAMI C{}>\{k_1:e_1\ldots k_n :e_n\}$.
2666 2945
2946 \LMHash{}
2667 Let $map_1 =$ \CONST{}$ <K, V>\{k_{11}:e_{11} \ldots k_{1n} :e_{1n}\}$ and $map _2 =$ \CONST{}$ <J, U>\{k_{21}:e_{21} \ldots k_{2n} :e_{2n}\}$ be two constant map literals. Let the keys of $map_1$ and $map_2$ evaluate to $s_{11} \ldots s _{1n}$ and $s_{21} \ldots s_{2n}$ respectively, and let the elements of $map _1$ and $map_2$ evaluate to $o_{11} \ldots o_{1n}$ and $o_{21} \ldots o_{2n}$ respectively. Iff \code{identical($o_{1i}$, $o_{2i}$)} and \code{identical($s_{ 1i}$, $s_{2i}$)} for $i \in 1.. n$, and $K = J, V = U$ then \code{identical($map _1$, $map_2$)}. 2947 Let $map_1 =$ \CONST{}$ <K, V>\{k_{11}:e_{11} \ldots k_{1n} :e_{1n}\}$ and $map _2 =$ \CONST{}$ <J, U>\{k_{21}:e_{21} \ldots k_{2n} :e_{2n}\}$ be two constant map literals. Let the keys of $map_1$ and $map_2$ evaluate to $s_{11} \ldots s _{1n}$ and $s_{21} \ldots s_{2n}$ respectively, and let the elements of $map _1$ and $map_2$ evaluate to $o_{11} \ldots o_{1n}$ and $o_{21} \ldots o_{2n}$ respectively. Iff \code{identical($o_{1i}$, $o_{2i}$)} and \code{identical($s_{ 1i}$, $s_{2i}$)} for $i \in 1.. n$, and $K = J, V = U$ then \code{identical($map _1$, $map_2$)}.
2668 2948
2669 \commentary{In other words, constant map literals are canonicalized.} 2949 \commentary{In other words, constant map literals are canonicalized.}
2670 2950
2951 \LMHash{}
2671 A runtime map literal $<K, V>\{k_1:e_1\ldots k_n :e_n\}$ is evaluated as follow s: 2952 A runtime map literal $<K, V>\{k_1:e_1\ldots k_n :e_n\}$ is evaluated as follow s:
2672 \begin{itemize} 2953 \begin{itemize}
2673 \item 2954 \item
2674 First, the expression $k_i$ is evaluated yielding object $u_i$, the $e_i$ is vau lted yielding object $o_i$, for $i \in 1..n$ in left to right order, yielding ob jects $u_1, o_1\ldots u_n, o_n$. 2955 First, the expression $k_i$ is evaluated yielding object $u_i$, the $e_i$ is vau lted yielding object $o_i$, for $i \in 1..n$ in left to right order, yielding ob jects $u_1, o_1\ldots u_n, o_n$.
2675 \item A fresh instance (\ref{generativeConstructors}) $m$ whose class implement s the built-in class 2956 \item A fresh instance (\ref{generativeConstructors}) $m$ whose class implement s the built-in class
2676 2957
2677 $Map<K, V>$ is allocated. 2958 $Map<K, V>$ is allocated.
2678 \item 2959 \item
2679 The operator \code{[]=} is invoked on $m$ with first argument $u_i$ and second argument $o_i, i \in 1.. n$. 2960 The operator \code{[]=} is invoked on $m$ with first argument $u_i$ and second argument $o_i, i \in 1.. n$.
2680 \item 2961 \item
2681 The result of the evaluation is $m$. 2962 The result of the evaluation is $m$.
2682 \end{itemize} 2963 \end{itemize}
2683 2964
2684 2965
2966 \LMHash{}
2685 A runtime map literal $\{k_1:e_1\ldots k_n :e_n\}$ is evaluated as 2967 A runtime map literal $\{k_1:e_1\ldots k_n :e_n\}$ is evaluated as
2686 2968
2687 $<\DYNAMIC{}, \DYNAMIC{}>\{k_1:e_1\ldots k_n :e_n\}$. 2969 $<\DYNAMIC{}, \DYNAMIC{}>\{k_1:e_1\ldots k_n :e_n\}$.
2688 2970
2971 \LMHash{}
2689 Iff all the keys in a map literal are compile-time constants, it is a static war ning if the values of any two keys in a map literal are equal. 2972 Iff all the keys in a map literal are compile-time constants, it is a static war ning if the values of any two keys in a map literal are equal.
2690 2973
2974 \LMHash{}
2691 A map literal is ordered: iterating over the keys and/or values of the maps alwa ys happens in the 2975 A map literal is ordered: iterating over the keys and/or values of the maps alwa ys happens in the
2692 order the keys appeared in the source code. 2976 order the keys appeared in the source code.
2693 2977
2694 \commentary{ 2978 \commentary{
2695 Of course, if a key repeats, the order is defined by first occurrence, but the v alue is defined by the last. 2979 Of course, if a key repeats, the order is defined by first occurrence, but the v alue is defined by the last.
2696 } 2980 }
2697 2981
2982 \LMHash{}
2698 The static type of a map literal of the form \CONST{}$ <K, V>\{k_1:e_1\ldots k_ n :e_n\}$ or the form $<K, V>\{k_1:e_1\ldots k_n :e_n\}$ is $Map<K, V>$. The sta tic type a map literal of the form \CONST{}$\{k_1:e_1\ldots k_n :e_n\}$ or the form $\{k_1:e_1\ldots k_n :e_n\}$ is $Map<\DYNAMIC{}, \DYNAMIC{}>$. 2983 The static type of a map literal of the form \CONST{}$ <K, V>\{k_1:e_1\ldots k_ n :e_n\}$ or the form $<K, V>\{k_1:e_1\ldots k_n :e_n\}$ is $Map<K, V>$. The sta tic type a map literal of the form \CONST{}$\{k_1:e_1\ldots k_n :e_n\}$ or the form $\{k_1:e_1\ldots k_n :e_n\}$ is $Map<\DYNAMIC{}, \DYNAMIC{}>$.
2699 2984
2700 2985
2701 \subsection{Throw} 2986 \subsection{Throw}
2702 \label{throw} 2987 \LMLabel{throw}
2703 2988
2989 \LMHash{}
2704 The {\em throw expression} is used to raise an exception. 2990 The {\em throw expression} is used to raise an exception.
2705 2991
2706 \begin{grammar} 2992 \begin{grammar}
2707 {\bf throwExpression:} 2993 {\bf throwExpression:}
2708 \THROW{} expression 2994 \THROW{} expression
2709 . 2995 .
2710 2996
2711 {\bf throwExpressionWithoutCascade:} 2997 {\bf throwExpressionWithoutCascade:}
2712 \THROW{} expressionWithoutCascade 2998 \THROW{} expressionWithoutCascade
2713 . 2999 .
2714 3000
2715 \end{grammar} 3001 \end{grammar}
2716 3002
3003 \LMHash{}
2717 The {\em current exception} is the last exception raised and not subsequently c aught at a given moment during runtime. 3004 The {\em current exception} is the last exception raised and not subsequently c aught at a given moment during runtime.
2718 3005
3006 \LMHash{}
2719 Evaluation of a throw expression of the form \code{\THROW{} $e$;} proceeds as follows: 3007 Evaluation of a throw expression of the form \code{\THROW{} $e$;} proceeds as follows:
2720 3008
3009 \LMHash{}
2721 The expression $e$ is evaluated yielding a value $v$. 3010 The expression $e$ is evaluated yielding a value $v$.
2722 3011
2723 \commentary{ 3012 \commentary{
2724 There is no requirement that the expression $e$ evaluate to a special kind of ex ception or error object. 3013 There is no requirement that the expression $e$ evaluate to a special kind of ex ception or error object.
2725 } 3014 }
2726 3015
3016 \LMHash{}
2727 If $e$ evaluates to \NULL{} (\ref{null}), then a \code{NullThrownError} is throw n. Otherwise the current exception is set to $v$ and the current return value (\ ref{return}) becomes undefined. 3017 If $e$ evaluates to \NULL{} (\ref{null}), then a \code{NullThrownError} is throw n. Otherwise the current exception is set to $v$ and the current return value (\ ref{return}) becomes undefined.
2728 3018
2729 \rationale{The current exception and the current return value must never be simu ltaneously defined, as they represent mutually exclusive options for exiting the current function. 3019 \rationale{The current exception and the current return value must never be simu ltaneously defined, as they represent mutually exclusive options for exiting the current function.
2730 } 3020 }
2731 3021
3022 \LMHash{}
2732 Let $f$ be the immediately enclosing function. 3023 Let $f$ be the immediately enclosing function.
2733 3024
3025 \LMHash{}
2734 If $f$ is synchronous (\ref{functions}), control is transferred to the nearest d ynamically enclosing exception handler. 3026 If $f$ is synchronous (\ref{functions}), control is transferred to the nearest d ynamically enclosing exception handler.
2735 3027
2736 \commentary{ 3028 \commentary{
2737 If $f$ is marked \SYNC* then a dynamically enclosing exception handler encloses the call to \code{moveNext()} that initiated the evaluation of the throw express ion. 3029 If $f$ is marked \SYNC* then a dynamically enclosing exception handler encloses the call to \code{moveNext()} that initiated the evaluation of the throw express ion.
2738 } 3030 }
2739 3031
3032 \LMHash{}
2740 If $f$ is asynchronous then if there is a dynamically enclosing exception handl er $h$ (\ref{try}) introduced by the current activation, control is transferred to $h$, otherwise $f$ terminates. 3033 If $f$ is asynchronous then if there is a dynamically enclosing exception handl er $h$ (\ref{try}) introduced by the current activation, control is transferred to $h$, otherwise $f$ terminates.
2741 3034
2742 \rationale{ 3035 \rationale{
2743 The rules for where a thrown exception will be handled must necessarily differ b etween the synchronous and asynchronous cases. Asynchronous functions cannot tra nsfer control to an exception handler defined outside themselves. Asynchronous generators post exceptions to their stream. Other asynchronous functions report exceptions via their future. 3036 The rules for where a thrown exception will be handled must necessarily differ b etween the synchronous and asynchronous cases. Asynchronous functions cannot tra nsfer control to an exception handler defined outside themselves. Asynchronous generators post exceptions to their stream. Other asynchronous functions report exceptions via their future.
2744 } 3037 }
2745 3038
3039 \LMHash{}
2746 If the object being thrown is an instance of class \code{Error} or a subclass th ereof, its \code{stackTrace} getter will return the stack trace current at the p oint where the the object was first thrown. 3040 If the object being thrown is an instance of class \code{Error} or a subclass th ereof, its \code{stackTrace} getter will return the stack trace current at the p oint where the the object was first thrown.
2747 3041
3042 \LMHash{}
2748 The static type of a throw expression is $\bot$. 3043 The static type of a throw expression is $\bot$.
2749 3044
2750 3045
2751 \subsection{ Function Expressions} 3046 \subsection{ Function Expressions}
2752 \label{functionExpressions} 3047 \LMLabel{functionExpressions}
2753 3048
3049 \LMHash{}
2754 A {\em function literal} is an object that encapsulates an executable unit of co de. 3050 A {\em function literal} is an object that encapsulates an executable unit of co de.
2755 3051
2756 \begin{grammar} 3052 \begin{grammar}
2757 {\bf functionExpression:} 3053 {\bf functionExpression:}
2758 formalParameterList functionBody 3054 formalParameterList functionBody
2759 . 3055 .
2760 \end{grammar} 3056 \end{grammar}
2761 3057
3058 \LMHash{}
2762 The class of a function literal implements the built-in class \code{Function}. 3059 The class of a function literal implements the built-in class \code{Function}.
2763 %Invoking the getter \code{runtimeType} on a function literal returns the \code{ Type} object that is the value of the expression \code{Function}. 3060 %Invoking the getter \code{runtimeType} on a function literal returns the \code{ Type} object that is the value of the expression \code{Function}.
2764 % not necessarily 3061 % not necessarily
2765 3062
2766 3063
2767 %Q{Can anyone implement it? Then we should define things via call} 3064 %Q{Can anyone implement it? Then we should define things via call}
2768 3065
3066 \LMHash{}
2769 The static type of a function literal of the form 3067 The static type of a function literal of the form
2770 3068
2771 $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{ n+k} = d_k]) => e$ 3069 $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{ n+k} = d_k]) => e$
2772 is 3070 is
2773 3071
2774 $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarrow T _0$, where $T_0$ is the static type of $e$. 3072 $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarrow T _0$, where $T_0$ is the static type of $e$.
2775 3073
3074 \LMHash{}
2776 The static type of a function literal of the form 3075 The static type of a function literal of the form
2777 3076
2778 $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{ n+k} = d_k])$ \ASYNC{} $=> e$ 3077 $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{ n+k} = d_k])$ \ASYNC{} $=> e$
2779 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Future<T_0>$, where $T_0$ is the static type of $e$. 3078 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Future<T_0>$, where $T_0$ is the static type of $e$.
2780 3079
3080 \LMHash{}
2781 The static type of a function literal of the form 3081 The static type of a function literal of the form
2782 3082
2783 $(T_1$ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_ {n+k} : d_k\}) => e$ 3083 $(T_1$ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_ {n+k} : d_k\}) => e$
2784 is 3084 is
2785 3085
2786 $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightarrow T_0$, where $T_0$ is the static type of $e$. 3086 $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightarrow T_0$, where $T_0$ is the static type of $e$.
2787 3087
3088 \LMHash{}
2788 The static type of a function literal of the form 3089 The static type of a function literal of the form
2789 3090
2790 $(T_1$ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_ {n+k} : d_k\})$ \ASYNC{} $=> e$ 3091 $(T_1$ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_ {n+k} : d_k\})$ \ASYNC{} $=> e$
2791 3092
2792 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar row Future<T_0>$, where $T_0$ is the static type of $e$. 3093 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar row Future<T_0>$, where $T_0$ is the static type of $e$.
2793 3094
3095 \LMHash{}
2794 The static type of a function literal of the form 3096 The static type of a function literal of the form
2795 3097
2796 $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{ n+k}= d_k])\{s\}$ 3098 $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{ n+k}= d_k])\{s\}$
2797 3099
2798 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w \DYNAMIC{}$. 3100 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w \DYNAMIC{}$.
2799 3101
3102 \LMHash{}
2800 The static type of a function literal of the form 3103 The static type of a function literal of the form
2801 3104
2802 $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{ n+k}= d_k])$ $ \ASYNC{}$ $\{s\}$ 3105 $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{ n+k}= d_k])$ $ \ASYNC{}$ $\{s\}$
2803 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Future$. 3106 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Future$.
2804 3107
3108 \LMHash{}
2805 The static type of a function literal of the form 3109 The static type of a function literal of the form
2806 3110
2807 $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{ n+k}= d_k])$ $ \ASYNC*{}$ $\{s\}$ 3111 $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{ n+k}= d_k])$ $ \ASYNC*{}$ $\{s\}$
2808 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Stream$. 3112 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Stream$.
2809 3113
3114 \LMHash{}
2810 The static type of a function literal of the form 3115 The static type of a function literal of the form
2811 3116
2812 $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{ n+k}= d_k])$ $ \SYNC*{}$ $\{s\}$ 3117 $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{ n+k}= d_k])$ $ \SYNC*{}$ $\{s\}$
2813 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Iterable$. 3118 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Iterable$.
2814 3119
2815 3120
3121 \LMHash{}
2816 The static type of a function literal of the form 3122 The static type of a function literal of the form
2817 3123
2818 $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{ n+k}= d_k])\{s\}$ 3124 $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{ n+k}= d_k])\{s\}$
2819 3125
2820 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w \DYNAMIC{}$. 3126 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w \DYNAMIC{}$.
2821 3127
2822 3128
3129 \LMHash{}
2823 The static type of a function literal of the form 3130 The static type of a function literal of the form
2824 3131
2825 $(T_1$ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_ {n+k} : d_k\})$ $\ASYNC{}$ $\{s\}$ 3132 $(T_1$ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_ {n+k} : d_k\})$ $\ASYNC{}$ $\{s\}$
2826 3133
2827 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar row Future{}$. 3134 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar row Future{}$.
2828 3135
3136 \LMHash{}
2829 The static type of a function literal of the form 3137 The static type of a function literal of the form
2830 3138
2831 $(T_1$ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_ {n+k} : d_k\})$ $\ASYNC*{}$ $\{s\}$ 3139 $(T_1$ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_ {n+k} : d_k\})$ $\ASYNC*{}$ $\{s\}$
2832 3140
2833 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar row Stream{}$. 3141 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar row Stream{}$.
2834 3142
3143 \LMHash{}
2835 The static type of a function literal of the form 3144 The static type of a function literal of the form
2836 3145
2837 $(T_1$ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_ {n+k} : d_k\})$ $\SYNC*{}$ $\{s\}$ 3146 $(T_1$ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_ {n+k} : d_k\})$ $\SYNC*{}$ $\{s\}$
2838 3147
2839 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar row Iterable{}$. 3148 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar row Iterable{}$.
2840 3149
3150 \LMHash{}
2841 In all of the above cases, whenever $T_i, 1 \le i \le n+k$, is not specified, it is considered to have been specified as \DYNAMIC{}. 3151 In all of the above cases, whenever $T_i, 1 \le i \le n+k$, is not specified, it is considered to have been specified as \DYNAMIC{}.
2842 3152
2843 3153
2844 \subsection{ This} 3154 \subsection{ This}
2845 \label{this} 3155 \LMLabel{this}
2846 3156
3157 \LMHash{}
2847 The reserved word \THIS{} denotes the target of the current instance member invo cation. 3158 The reserved word \THIS{} denotes the target of the current instance member invo cation.
2848 3159
2849 \begin{grammar} 3160 \begin{grammar}
2850 {\bf thisExpression:} 3161 {\bf thisExpression:}
2851 \THIS{} 3162 \THIS{}
2852 . 3163 .
2853 \end{grammar} 3164 \end{grammar}
2854 3165
3166 \LMHash{}
2855 The static type of \THIS{} is the interface of the immediately enclosing class. 3167 The static type of \THIS{} is the interface of the immediately enclosing class.
2856 3168
2857 \commentary{ 3169 \commentary{
2858 We do not support self-types at this point. 3170 We do not support self-types at this point.
2859 } 3171 }
2860 3172
3173 \LMHash{}
2861 It is a compile-time error if \THIS{} appears, implicitly or explicitly, in a t op-level function or variable initializer, in a factory constructor, or in a st atic method or variable initializer, or in the initializer of an instance variab le. 3174 It is a compile-time error if \THIS{} appears, implicitly or explicitly, in a t op-level function or variable initializer, in a factory constructor, or in a st atic method or variable initializer, or in the initializer of an instance variab le.
2862 3175
2863 \subsection{ Instance Creation} 3176 \subsection{ Instance Creation}
2864 \label{instanceCreation} 3177 \LMLabel{instanceCreation}
2865 3178
3179 \LMHash{}
2866 Instance creation expressions invoke constructors to produce instances. 3180 Instance creation expressions invoke constructors to produce instances.
2867 3181
2868 %It is a compile-time error if any of the type arguments to a constructor of a g eneric type invoked by a new expression or a constant object expression do not d enote types in the enclosing lexical scope. 3182 %It is a compile-time error if any of the type arguments to a constructor of a g eneric type invoked by a new expression or a constant object expression do not d enote types in the enclosing lexical scope.
2869 3183
2870 %It is a compile-time error if a constructor of a non-generic type invoked by a new expression or a constant object expression is passed any type arguments. It is a compile-time error if a constructor of a generic type with $n$ type paramet ers invoked by a new expression or a constant object expression is passed $m$ ty pe arguments where $m \ne n$, or if any of its type arguments is misconstructed (\ref{parameterizedTypes}). 3184 %It is a compile-time error if a constructor of a non-generic type invoked by a new expression or a constant object expression is passed any type arguments. It is a compile-time error if a constructor of a generic type with $n$ type paramet ers invoked by a new expression or a constant object expression is passed $m$ ty pe arguments where $m \ne n$, or if any of its type arguments is misconstructed (\ref{parameterizedTypes}).
2871 3185
3186 \LMHash{}
2872 It is a static type warning if 3187 It is a static type warning if
2873 the type $T$ in an instance creation expression of one of the forms 3188 the type $T$ in an instance creation expression of one of the forms
2874 3189
2875 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 3190 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
2876 3191
2877 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 3192 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
2878 3193
2879 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 3194 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
2880 3195
2881 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ is malformed (\ref{dynamicTypeSystem}) or malbounded (\ref{parameterizedTypes}). 3196 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ is malformed (\ref{dynamicTypeSystem}) or malbounded (\ref{parameterizedTypes}).
2882 3197
3198 \LMHash{}
2883 It is a compile-time error if the type $T$ in an instance creation expression of one of the forms 3199 It is a compile-time error if the type $T$ in an instance creation expression of one of the forms
2884 3200
2885 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 3201 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
2886 3202
2887 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 3203 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
2888 3204
2889 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 3205 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
2890 3206
2891 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3207 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
2892 3208
2893 is an enumerated type (\ref{enums}). 3209 is an enumerated type (\ref{enums}).
2894 %any of the type arguments to a constructor of a generic type $G$ invoked by a n ew expression or a constant object expression are not subtypes of the bounds of the corresponding formal type parameters of $G$. 3210 %any of the type arguments to a constructor of a generic type $G$ invoked by a n ew expression or a constant object expression are not subtypes of the bounds of the corresponding formal type parameters of $G$.
2895 3211
2896 3212
2897 \subsubsection{ New} 3213 \subsubsection{ New}
2898 \label{new} 3214 \LMLabel{new}
2899 3215
3216 \LMHash{}
2900 The {\em new expression} invokes a constructor (\ref{constructors}). 3217 The {\em new expression} invokes a constructor (\ref{constructors}).
2901 3218
2902 \begin{grammar} 3219 \begin{grammar}
2903 {\bf newExpression:} 3220 {\bf newExpression:}
2904 \NEW{} type (`{\escapegrammar .}' identifier)? arguments 3221 \NEW{} type (`{\escapegrammar .}' identifier)? arguments
2905 . 3222 .
2906 \end{grammar} 3223 \end{grammar}
2907 3224
3225 \LMHash{}
2908 Let $e$ be a new expression of the form 3226 Let $e$ be a new expression of the form
2909 3227
2910 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ or the form 3228 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ or the form
2911 3229
2912 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. 3230 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$.
2913 3231
2914 %It is a runtime type error if 3232 %It is a runtime type error if
2915 %the type $T$ is malformed. 3233 %the type $T$ is malformed.
2916 %It is a static warning if $T$ is a malformed type. 3234 %It is a static warning if $T$ is a malformed type.
2917 3235
2918 %not a class accessible in the current scope, optionally followed by type argum ents. 3236 %not a class accessible in the current scope, optionally followed by type argum ents.
2919 3237
3238 \LMHash{}
2920 If $T$ is a class or parameterized type accessible in the current scope then: 3239 If $T$ is a class or parameterized type accessible in the current scope then:
2921 \begin{itemize} 3240 \begin{itemize}
2922 \item 3241 \item
2923 If $e$ is of the form \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ it is a static warning if $T.id$ is not the name of a constr uctor declared by the type $T$. If $e$ is of the form \NEW{} $T(a_1, \ldots , a _n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ it is a static warning if the type $T$ does not declare a constructor with the same name as the declaration of $T$. 3242 If $e$ is of the form \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ it is a static warning if $T.id$ is not the name of a constr uctor declared by the type $T$. If $e$ is of the form \NEW{} $T(a_1, \ldots , a _n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ it is a static warning if the type $T$ does not declare a constructor with the same name as the declaration of $T$.
2924 \end{itemize} 3243 \end{itemize}
2925 3244
3245 \LMHash{}
2926 If $T$ is a parameterized type (\ref{parameterizedTypes}) $S<U_1, \ldots, U_m>$ , let $R = S$. 3246 If $T$ is a parameterized type (\ref{parameterizedTypes}) $S<U_1, \ldots, U_m>$ , let $R = S$.
2927 %It is a 3247 %It is a
2928 %compile-time CHANGED 3248 %compile-time CHANGED
2929 %runtime type 3249 %runtime type
2930 %error if $S$ is not a generic (\ref{generics}) type with $m$ type parameters. 3250 %error if $S$ is not a generic (\ref{generics}) type with $m$ type parameters.
2931 If $T$ is not a parameterized type, let $R = T$. 3251 If $T$ is not a parameterized type, let $R = T$.
2932 Furthermore, if $e$ is of the form \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n +1}, \ldots , x_{n+k}: a_{n+k})$ then let $q$ be the constructor $T.id$, other wise let $q$ be the constructor $T$. 3252 Furthermore, if $e$ is of the form \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n +1}, \ldots , x_{n+k}: a_{n+k})$ then let $q$ be the constructor $T.id$, other wise let $q$ be the constructor $T$.
2933 3253
3254 \LMHash{}
2934 If $R$ is a generic with $l = m$ type parameters then 3255 If $R$ is a generic with $l = m$ type parameters then
2935 \begin{itemize} 3256 \begin{itemize}
2936 \item If $T$ is not a parameterized type, then for $ i \in 1 .. l$, let $V_i = \DYNAMIC{}$. 3257 \item If $T$ is not a parameterized type, then for $ i \in 1 .. l$, let $V_i = \DYNAMIC{}$.
2937 \item If $T$ is a parameterized type then let $V_i = U_i$ for $ i \in 1 .. m$. 3258 \item If $T$ is a parameterized type then let $V_i = U_i$ for $ i \in 1 .. m$.
2938 \end{itemize} 3259 \end{itemize}
2939 3260
3261 \LMHash{}
2940 If $R$ is a generic with $l \ne m$ type parameters then for $ i \in 1 .. l$, let $V_i = \DYNAMIC{}$. In any other case, let $V_i = U_i$ for $ i \in 1 .. m$. 3262 If $R$ is a generic with $l \ne m$ type parameters then for $ i \in 1 .. l$, let $V_i = \DYNAMIC{}$. In any other case, let $V_i = U_i$ for $ i \in 1 .. m$.
2941 3263
3264 \LMHash{}
2942 Evaluation of $e$ proceeds as follows: 3265 Evaluation of $e$ proceeds as follows:
2943 3266
3267 \LMHash{}
2944 First, the argument list $(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k} : a_{n+k})$ is evaluated. 3268 First, the argument list $(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k} : a_{n+k})$ is evaluated.
2945 3269
3270 \LMHash{}
2946 If $T$ is a deferred type with prefix $p$, then if $p$ has not been successfully loaded, a dynamic error occurs. 3271 If $T$ is a deferred type with prefix $p$, then if $p$ has not been successfully loaded, a dynamic error occurs.
2947 3272
3273 \LMHash{}
2948 Then, if $q$ is a non-factory constructor of an abstract class then an \code{Abs tractClassInstantiationError} is thrown. 3274 Then, if $q$ is a non-factory constructor of an abstract class then an \code{Abs tractClassInstantiationError} is thrown.
2949 3275
3276 \LMHash{}
2950 If $T$ is malformed or if $T$ is a type variable a dynamic error occurs. In che cked mode, if $T$ or any of its superclasses is malbounded a dynamic error occur s. 3277 If $T$ is malformed or if $T$ is a type variable a dynamic error occurs. In che cked mode, if $T$ or any of its superclasses is malbounded a dynamic error occur s.
2951 Otherwise, if $q$ is not defined or not accessible, a \code{NoSuchMethodError} is thrown. If $q$ has less than $n$ positional parameters or more than $n$ req uired parameters, or if $q$ lacks any of the keyword parameters $\{ x_{n+1}, \ld ots, x_{n+k}\}$ a \code{NoSuchMethodError} is thrown. 3278 Otherwise, if $q$ is not defined or not accessible, a \code{NoSuchMethodError} is thrown. If $q$ has less than $n$ positional parameters or more than $n$ req uired parameters, or if $q$ lacks any of the keyword parameters $\{ x_{n+1}, \ld ots, x_{n+k}\}$ a \code{NoSuchMethodError} is thrown.
2952 3279
3280 \LMHash{}
2953 Otherwise, if $q$ is a generative constructor (\ref{generativeConstructors}), th en: 3281 Otherwise, if $q$ is a generative constructor (\ref{generativeConstructors}), th en:
2954 3282
2955 \commentary{Note that it this point we are assured that the number of actual typ e arguments match the number of formal type parameters.} 3283 \commentary{Note that it this point we are assured that the number of actual typ e arguments match the number of formal type parameters.}
2956 3284
3285 \LMHash{}
2957 A fresh instance (\ref{generativeConstructors}), $i$, of class $R$ is allocated . For each instance variable $f$ of $i$, if the variable declaration of $f$ has an initializer expression $e_f$, then $e_f$ is evaluated to an object $o_f$ and $f$ is bound to $o_f$. Otherwise $f$ is bound to \NULL{}. 3286 A fresh instance (\ref{generativeConstructors}), $i$, of class $R$ is allocated . For each instance variable $f$ of $i$, if the variable declaration of $f$ has an initializer expression $e_f$, then $e_f$ is evaluated to an object $o_f$ and $f$ is bound to $o_f$. Otherwise $f$ is bound to \NULL{}.
2958 3287
2959 \commentary{ 3288 \commentary{
2960 Observe that \THIS{} is not in scope in $e_f$. Hence, the initialization cannot depend on other properties of the object being instantiated. 3289 Observe that \THIS{} is not in scope in $e_f$. Hence, the initialization cannot depend on other properties of the object being instantiated.
2961 } 3290 }
2962 3291
3292 \LMHash{}
2963 Next, $q$ is executed with \THIS{} bound to $i$, the type parameters (if any) of $R$ bound to the actual type arguments $V_1, \ldots, V_l$ and the formal par ameter bindings that resulted from the evaluation of the argument list. The resu lt of the evaluation of $e$ is $i$. 3293 Next, $q$ is executed with \THIS{} bound to $i$, the type parameters (if any) of $R$ bound to the actual type arguments $V_1, \ldots, V_l$ and the formal par ameter bindings that resulted from the evaluation of the argument list. The resu lt of the evaluation of $e$ is $i$.
2964 3294
3295 \LMHash{}
2965 Otherwise, $q$ is a factory constructor (\ref{factories}). Then: 3296 Otherwise, $q$ is a factory constructor (\ref{factories}). Then:
2966 3297
3298 \LMHash{}
2967 If $q$ is a redirecting factory constructor of the form $T(p_1, \ldots, p_{n+k}) = c;$ or of the form $T.id(p_1, \ldots, p_{n+k}) = c;$ then the result of the evaluation of $e$ is equivalent to evaluating the expression 3299 If $q$ is a redirecting factory constructor of the form $T(p_1, \ldots, p_{n+k}) = c;$ or of the form $T.id(p_1, \ldots, p_{n+k}) = c;$ then the result of the evaluation of $e$ is equivalent to evaluating the expression
2968 3300
2969 $[V_1, \ldots, V_m/T_1, \ldots, T_m]($\code{\NEW{} $c(a_1, \ldots, a_n, x_{n+1 }: a_{n+1}, \ldots, x_{n+k}: a_{n+k}))$}. If evaluation of $q$ causes $q$ to be re-evaluated cyclically, a runtime error occurs. 3301 $[V_1, \ldots, V_m/T_1, \ldots, T_m]($\code{\NEW{} $c(a_1, \ldots, a_n, x_{n+1 }: a_{n+1}, \ldots, x_{n+k}: a_{n+k}))$}. If evaluation of $q$ causes $q$ to be re-evaluated cyclically, a runtime error occurs.
2970 3302
2971 3303
3304 \LMHash{}
2972 Otherwise, the body of $q$ is executed with respect to the bindings that resulte d from the evaluation of the argument list and the type parameters (if any) of $ q$ bound to the actual type arguments $V_1, \ldots, V_l$ resulting in an object $i$. The result of the evaluation of $e$ is $i$. 3305 Otherwise, the body of $q$ is executed with respect to the bindings that resulte d from the evaluation of the argument list and the type parameters (if any) of $ q$ bound to the actual type arguments $V_1, \ldots, V_l$ resulting in an object $i$. The result of the evaluation of $e$ is $i$.
2973 3306
3307 \LMHash{}
2974 It is a static warning if $q$ is a constructor of an abstract class and $q$ is n ot a factory constructor. 3308 It is a static warning if $q$ is a constructor of an abstract class and $q$ is n ot a factory constructor.
2975 3309
2976 \commentary{The above gives precise meaning to the idea that instantiating an ab stract class leads to a warning. 3310 \commentary{The above gives precise meaning to the idea that instantiating an ab stract class leads to a warning.
2977 A similar clause applies to constant object creation in the next section. 3311 A similar clause applies to constant object creation in the next section.
2978 } 3312 }
2979 3313
2980 \rationale{In particular, a factory constructor can be declared in an abstract c lass and used safely, as it will either produce a valid instance or lead to a wa rning inside its own declaration. 3314 \rationale{In particular, a factory constructor can be declared in an abstract c lass and used safely, as it will either produce a valid instance or lead to a wa rning inside its own declaration.
2981 } 3315 }
2982 3316
3317 \LMHash{}
2983 The static type of an instance creation expression of either the form 3318 The static type of an instance creation expression of either the form
2984 3319
2985 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3320 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
2986 3321
2987 or the form 3322 or the form
2988 3323
2989 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3324 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
2990 3325
2991 is $T$. 3326 is $T$.
2992 It is a static warning if the static type of $a_i, 1 \le i \le n+ k$ may not be assigned to the type of the corresponding formal parameter of the constructor $T .id$ (respectively $T$). 3327 It is a static warning if the static type of $a_i, 1 \le i \le n+ k$ may not be assigned to the type of the corresponding formal parameter of the constructor $T .id$ (respectively $T$).
2993 3328
2994 3329
2995 3330
2996 \subsubsection{ Const} 3331 \subsubsection{ Const}
2997 \label{const} 3332 \LMLabel{const}
2998 3333
3334 \LMHash{}
2999 A {\em constant object expression} invokes a constant constructor (\ref{constant Constructors}). 3335 A {\em constant object expression} invokes a constant constructor (\ref{constant Constructors}).
3000 3336
3001 \begin{grammar} 3337 \begin{grammar}
3002 {\bf constObjectExpression:} 3338 {\bf constObjectExpression:}
3003 \CONST{} type ('{\escapegrammar .}' identifier)? arguments 3339 \CONST{} type ('{\escapegrammar .}' identifier)? arguments
3004 . 3340 .
3005 \end{grammar} 3341 \end{grammar}
3006 3342
3343 \LMHash{}
3007 Let $e$ be a constant object expression of the form 3344 Let $e$ be a constant object expression of the form
3008 3345
3009 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3346 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
3010 3347
3011 or the form \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. It is a compile-time error if $T$ does not denote a class accessible in the current scope. It is a compile-time error if $T$ is a deferred type (\re f{staticTypes}). 3348 or the form \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. It is a compile-time error if $T$ does not denote a class accessible in the current scope. It is a compile-time error if $T$ is a deferred type (\re f{staticTypes}).
3012 3349
3013 \commentary{In particular, $T$ may not be a type variable.} 3350 \commentary{In particular, $T$ may not be a type variable.}
3014 3351
3352 \LMHash{}
3015 If $T$ is a parameterized type, it is a compile-time error if $T$ includes a typ e variable among its type arguments. 3353 If $T$ is a parameterized type, it is a compile-time error if $T$ includes a typ e variable among its type arguments.
3016 3354
3355 \LMHash{}
3017 If $e$ is of the form \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ it is a compile-time error if $T.id$ is not the name of a constant constructor declared by the type $T$. If $e$ is of the form \CONST{} $ T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ it is a compi le-time error if the type $T$ does not declare a constant constructor with the s ame name as the declaration of $T$. 3356 If $e$ is of the form \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ it is a compile-time error if $T.id$ is not the name of a constant constructor declared by the type $T$. If $e$ is of the form \CONST{} $ T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ it is a compi le-time error if the type $T$ does not declare a constant constructor with the s ame name as the declaration of $T$.
3018 3357
3358 \LMHash{}
3019 In all of the above cases, it is a compile-time error if $a_i, i\in 1 .. n + k$ , is not a compile-time constant expression. 3359 In all of the above cases, it is a compile-time error if $a_i, i\in 1 .. n + k$ , is not a compile-time constant expression.
3020 3360
3021 %If $T$ is a parameterized type (\ref{parameterizedTypes}) $S<U_1, \ldots, U_m> $, let $R = S$. It is a compile-time error if $T$ is is malformed. If $T$ is no t a parameterized type, let $R = T$. 3361 %If $T$ is a parameterized type (\ref{parameterizedTypes}) $S<U_1, \ldots, U_m> $, let $R = S$. It is a compile-time error if $T$ is is malformed. If $T$ is no t a parameterized type, let $R = T$.
3022 %Finally, 3362 %Finally,
3023 % If $T$ is a generic with $l$ retype parameters, then for all $ i \in 1 .. l$, let $V_i = \DYNAMIC{}$. 3363 % If $T$ is a generic with $l$ retype parameters, then for all $ i \in 1 .. l$, let $V_i = \DYNAMIC{}$.
3024 3364
3365 \LMHash{}
3025 Evaluation of $e$ proceeds as follows: 3366 Evaluation of $e$ proceeds as follows:
3026 3367
3368 \LMHash{}
3027 First, if $e$ is of the form 3369 First, if $e$ is of the form
3028 3370
3029 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3371 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
3030 3372
3031 then let $i$ be the value of the expression 3373 then let $i$ be the value of the expression
3032 3374
3033 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. 3375 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$.
3034 3376
3377 \LMHash{}
3035 Otherwise, $e$ must be of the form 3378 Otherwise, $e$ must be of the form
3036 3379
3037 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 3380 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
3038 3381
3039 in which case let $i$ be the result of evaluating 3382 in which case let $i$ be the result of evaluating
3040 3383
3041 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. 3384 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$.
3042 3385
3386 \LMHash{}
3043 Then: 3387 Then:
3044 \begin{itemize} 3388 \begin{itemize}
3045 \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: 3389 \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:
3046 \begin{itemize} 3390 \begin{itemize}
3047 \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$. 3391 \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$.
3048 \end{itemize} 3392 \end{itemize}
3049 \item Otherwise the value of $e$ is $i$. 3393 \item Otherwise the value of $e$ is $i$.
3050 \end{itemize} 3394 \end{itemize}
3051 3395
3052 \commentary{ 3396 \commentary{
3053 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. 3397 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.
3054 } 3398 }
3055 3399
3400 \LMHash{}
3056 The static type of a constant object expression of either the form 3401 The static type of a constant object expression of either the form
3057 3402
3058 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3403 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
3059 3404
3060 or the form 3405 or the form
3061 3406
3062 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3407 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
3063 3408
3064 is $T$. It is a static warning if the static type of $a_i, 1 \le i \le n+ k$ may not be assigned to the type of the corresponding formal parameter of the constr uctor $T.id$ (respectively $T$). 3409 is $T$. It is a static warning if the static type of $a_i, 1 \le i \le n+ k$ may not be assigned to the type of the corresponding formal parameter of the constr uctor $T.id$ (respectively $T$).
3065 3410
3411 \LMHash{}
3066 It is a compile-time error if evaluation of a constant object results in an unca ught exception being thrown. 3412 It is a compile-time error if evaluation of a constant object results in an unca ught exception being thrown.
3067 3413
3068 \commentary{ 3414 \commentary{
3069 To see how such situations might arise, consider the following examples: 3415 To see how such situations might arise, consider the following examples:
3070 } 3416 }
3071 3417
3072 \begin{dartCode} 3418 \begin{dartCode}
3073 \CLASS{} A \{ 3419 \CLASS{} A \{
3074 \FINAL{} x; 3420 \FINAL{} x;
3075 \CONST{} A(p): x = p * 10; 3421 \CONST{} A(p): x = p * 10;
(...skipping 11 matching lines...) Expand all
3087 \} 3433 \}
3088 3434
3089 \CONST{} A(\CONST{} IntPair(1,2)); // compile-time error: illegal in a subtler w ay 3435 \CONST{} A(\CONST{} IntPair(1,2)); // compile-time error: illegal in a subtler w ay
3090 \end{dartCode} 3436 \end{dartCode}
3091 3437
3092 \commentary{ 3438 \commentary{
3093 Due to the rules governing constant constructors, evaluating the constructor \co de{A()} with the argument \code{''x''} or the argument \code{\CONST{} IntPair(1, 2)} would cause it to throw an exception, resulting in a compile-time error. 3439 Due to the rules governing constant constructors, evaluating the constructor \co de{A()} with the argument \code{''x''} or the argument \code{\CONST{} IntPair(1, 2)} would cause it to throw an exception, resulting in a compile-time error.
3094 } 3440 }
3095 3441
3096 3442
3443 \LMHash{}
3097 Given an instance creation expression of the form \CONST{} $q(a_1, \ldots , a_n) $ it is a static warning if $q$ is a constructor of an abstract class (\ref{abs tractInstanceMembers}) but $q$ is not a factory constructor. 3444 Given an instance creation expression of the form \CONST{} $q(a_1, \ldots , a_n) $ it is a static warning if $q$ is a constructor of an abstract class (\ref{abs tractInstanceMembers}) but $q$ is not a factory constructor.
3098 3445
3099 3446
3100 \subsection{ Spawning an Isolate} 3447 \subsection{ Spawning an Isolate}
3101 \label{spawningAnIsolate} 3448 \LMLabel{spawningAnIsolate}
3102 3449
3450 \LMHash{}
3103 Spawning an isolate is accomplished via what is syntactically an ordinary librar y call, invoking one of the functions \code{spawnUri()} or \code{spawnFunction() }defined in the \code{dart:isolate} library. However, such calls have the sema ntic effect of creating a new isolate with its own memory and thread of control. 3451 Spawning an isolate is accomplished via what is syntactically an ordinary librar y call, invoking one of the functions \code{spawnUri()} or \code{spawnFunction() }defined in the \code{dart:isolate} library. However, such calls have the sema ntic effect of creating a new isolate with its own memory and thread of control.
3104 3452
3453 \LMHash{}
3105 An isolate's memory is finite, as is the space available to its thread's call st ack. It is possible for a running isolate to exhaust its memory or stack, result ing in a run-time error that cannot be effectively caught, which will force the isolate to be suspended. 3454 An isolate's memory is finite, as is the space available to its thread's call st ack. It is possible for a running isolate to exhaust its memory or stack, result ing in a run-time error that cannot be effectively caught, which will force the isolate to be suspended.
3106 3455
3107 \commentary{ 3456 \commentary{
3108 As discussed in section \ref{errorsAndWarnings}, the handling of a suspended iso late is the responsibility of the embedder. 3457 As discussed in section \ref{errorsAndWarnings}, the handling of a suspended iso late is the responsibility of the embedder.
3109 } 3458 }
3110 3459
3111 3460
3112 3461
3113 \subsection{ Function Invocation} 3462 \subsection{ Function Invocation}
3114 \label{functionInvocation} 3463 \LMLabel{functionInvocation}
3115 3464
3465 \LMHash{}
3116 Function invocation occurs in the following cases: when a function expression ( \ref{functionExpressions}) is invoked (\ref{functionExpressionInvocation}), when a method (\ref{methodInvocation}), getter (\ref{topLevelGetterInvocation}, \ref {propertyExtraction}) or setter (\ref{assignment}) is invoked or when a construc tor is invoked (either via instance creation (\ref{instanceCreation}), construct or redirection (\ref{redirectingConstructors}) or super initialization). The var ious kinds of function invocation differ as to how the function to be invoked, $ f$, is determined, as well as whether \THIS{} (\ref{this}) is bound. Once $f$ h as been determined, the formal parameters of $f$ are bound to corresponding actu al arguments. When the body of $f$ is executed it will be executed with the afor ementioned bindings. 3466 Function invocation occurs in the following cases: when a function expression ( \ref{functionExpressions}) is invoked (\ref{functionExpressionInvocation}), when a method (\ref{methodInvocation}), getter (\ref{topLevelGetterInvocation}, \ref {propertyExtraction}) or setter (\ref{assignment}) is invoked or when a construc tor is invoked (either via instance creation (\ref{instanceCreation}), construct or redirection (\ref{redirectingConstructors}) or super initialization). The var ious kinds of function invocation differ as to how the function to be invoked, $ f$, is determined, as well as whether \THIS{} (\ref{this}) is bound. Once $f$ h as been determined, the formal parameters of $f$ are bound to corresponding actu al arguments. When the body of $f$ is executed it will be executed with the afor ementioned bindings.
3117 3467
3468 \LMHash{}
3118 If $f$ is marked \ASYNC{} (\ref{functions}), then a fresh instance (\ref{generat iveConstructors}) $o$ implementing the built-in class \code{Future} is associate d with the invocation and immediately returned to the caller. The body of $f$ is scheduled for execution at some future time. The future $o$ will complete when $f$ terminates. The value used to complete $o$ is the current return value (\ref {return}), if it is defined, and the current exception (\ref{throw}) otherwise. 3469 If $f$ is marked \ASYNC{} (\ref{functions}), then a fresh instance (\ref{generat iveConstructors}) $o$ implementing the built-in class \code{Future} is associate d with the invocation and immediately returned to the caller. The body of $f$ is scheduled for execution at some future time. The future $o$ will complete when $f$ terminates. The value used to complete $o$ is the current return value (\ref {return}), if it is defined, and the current exception (\ref{throw}) otherwise.
3119 3470
3471 \LMHash{}
3120 If $f$ is marked \ASYNC* (\ref{functions}), then a fresh instance $s$ implementi ng the built-in class \code{Stream} is associated with the invocation and immedi ately returned. When $s$ is listened to, execution of the body of $f$ will begin . When $f$ terminates: 3472 If $f$ is marked \ASYNC* (\ref{functions}), then a fresh instance $s$ implementi ng the built-in class \code{Stream} is associated with the invocation and immedi ately returned. When $s$ is listened to, execution of the body of $f$ will begin . When $f$ terminates:
3121 \begin{itemize} 3473 \begin{itemize}
3122 \item If the current return value is defined then, if $s$ has been canceled then its cancellation future is completed with \NULL{} (\ref{null}). 3474 \item If the current return value is defined then, if $s$ has been canceled then its cancellation future is completed with \NULL{} (\ref{null}).
3123 \item If the current exception $x$ is defined: 3475 \item If the current exception $x$ is defined:
3124 \begin{itemize} 3476 \begin{itemize}
3125 \item $x$ is added to $s$. 3477 \item $x$ is added to $s$.
3126 \item If $s$ has been canceled then its cancellation future is completed with $x$ as an error. 3478 \item If $s$ has been canceled then its cancellation future is completed with $x$ as an error.
3127 \end{itemize} 3479 \end{itemize}
3128 \item $s$ is closed. 3480 \item $s$ is closed.
3129 \end{itemize} 3481 \end{itemize}
3130 3482
3131 \rationale{ 3483 \rationale{
3132 When an asynchronous generator's stream has been canceled, cleanup will occur in the \FINALLY{} clauses (\ref{try}) inside the generator. We choose to direct an y exceptions that occur at this time to the cancellation future rather than have them be lost. 3484 When an asynchronous generator's stream has been canceled, cleanup will occur in the \FINALLY{} clauses (\ref{try}) inside the generator. We choose to direct an y exceptions that occur at this time to the cancellation future rather than have them be lost.
3133 } 3485 }
3134 3486
3487 \LMHash{}
3135 If $f$ is asynchronous then, when $f$ terminates, any open stream subscriptions associated with any asynchronous for loops (\ref{asynchronousFor-in}) or yield- each statements (\ref{yieldEach}) executing within $f$ are canceled. 3488 If $f$ is asynchronous then, when $f$ terminates, any open stream subscriptions associated with any asynchronous for loops (\ref{asynchronousFor-in}) or yield- each statements (\ref{yieldEach}) executing within $f$ are canceled.
3136 3489
3137 \rationale{Such streams may be left open by for loops that were escaped when an exception was thrown within them for example. 3490 \rationale{Such streams may be left open by for loops that were escaped when an exception was thrown within them for example.
3138 } 3491 }
3139 3492
3493 \LMHash{}
3140 If $f$ is marked \SYNC* (\ref{functions}), then a fresh instance $i$ implementin g the built-in class \code{Iterable} is associated with the invocation and immed iately returned. When iteration over the iterable is started, by getting an iter ator $j$ from the iterable and calling \code{moveNext()} on it, execution of the body of $f$ will begin. When $f$ terminates, $j$ is positioned after its last e lement, so that its current value is \NULL{} and the current call to \code{moveN ext()} on $j$ returns false, as will all further calls. 3494 If $f$ is marked \SYNC* (\ref{functions}), then a fresh instance $i$ implementin g the built-in class \code{Iterable} is associated with the invocation and immed iately returned. When iteration over the iterable is started, by getting an iter ator $j$ from the iterable and calling \code{moveNext()} on it, execution of the body of $f$ will begin. When $f$ terminates, $j$ is positioned after its last e lement, so that its current value is \NULL{} and the current call to \code{moveN ext()} on $j$ returns false, as will all further calls.
3141 3495
3496 \LMHash{}
3142 If $f$ is synchronous and is not a generator (\ref{functions}) then execution of the body of $f$ begins immediately. When $f$ terminates the current return val ue is returned to the caller. 3497 If $f$ is synchronous and is not a generator (\ref{functions}) then execution of the body of $f$ begins immediately. When $f$ terminates the current return val ue is returned to the caller.
3143 3498
3144 3499
3500 \LMHash{}
3145 Execution of $f$ terminates when the first of the following occurs: 3501 Execution of $f$ terminates when the first of the following occurs:
3146 \begin{itemize} 3502 \begin{itemize}
3147 \item An exception is thrown and not caught within the current function activati on. 3503 \item An exception is thrown and not caught within the current function activati on.
3148 \item A return statement (\ref{return}) immediately nested in the body of $f$ is executed and not intercepted in a \FINALLY{} (\ref{try}) clause. 3504 \item A return statement (\ref{return}) immediately nested in the body of $f$ is executed and not intercepted in a \FINALLY{} (\ref{try}) clause.
3149 \item The last statement of the body completes execution. 3505 \item The last statement of the body completes execution.
3150 \end{itemize} 3506 \end{itemize}
3151 3507
3152 3508
3153 3509
3154 3510
3155 \subsubsection{ Actual Argument List Evaluation} 3511 \subsubsection{ Actual Argument List Evaluation}
3156 \label{actualArguments} 3512 \LMLabel{actualArguments}
3157 3513
3514 \LMHash{}
3158 Function invocation involves evaluation of the list of actual arguments to the f unction and binding of the results to the function's formal parameters. 3515 Function invocation involves evaluation of the list of actual arguments to the f unction and binding of the results to the function's formal parameters.
3159 3516
3160 \begin{grammar} 3517 \begin{grammar}
3161 {\bf arguments:} 3518 {\bf arguments:}
3162 `(' argumentList? `)' 3519 `(' argumentList? `)'
3163 . 3520 .
3164 3521
3165 {\bf argumentList:}namedArgument (`,' namedArgument)*; 3522 {\bf argumentList:}namedArgument (`,' namedArgument)*;
3166 % expressionList ',' spreadArgument; 3523 % expressionList ',' spreadArgument;
3167 expressionList (`,' namedArgument)* 3524 expressionList (`,' namedArgument)*
3168 % spreadArgument 3525 % spreadArgument
3169 . 3526 .
3170 3527
3171 {\bf namedArgument:} 3528 {\bf namedArgument:}
3172 label expression % could be top level expression? 3529 label expression % could be top level expression?
3173 . 3530 .
3174 \end{grammar} 3531 \end{grammar}
3175 3532
3533 \LMHash{}
3176 Evaluation of an actual argument list of the form 3534 Evaluation of an actual argument list of the form
3177 3535
3178 $(a_1, \ldots, a_m, q_1: a_{m+1}, \ldots, q_l: a_{m+l})$ 3536 $(a_1, \ldots, a_m, q_1: a_{m+1}, \ldots, q_l: a_{m+l})$
3179 3537
3180 proceeds as follows: 3538 proceeds as follows:
3181 3539
3540 \LMHash{}
3182 The arguments $a_1, \ldots, a_{m+l}$ are evaluated in the order they appear in t he program, yielding objects $o_1, \ldots, o_{m+l}$. 3541 The arguments $a_1, \ldots, a_{m+l}$ are evaluated in the order they appear in t he program, yielding objects $o_1, \ldots, o_{m+l}$.
3183 3542
3184 \commentary{Simply stated, an argument list consisting of $m$ positional argumen ts and $l$ named arguments is evaluated from left to right. 3543 \commentary{Simply stated, an argument list consisting of $m$ positional argumen ts and $l$ named arguments is evaluated from left to right.
3185 } 3544 }
3186 3545
3187 3546
3188 \subsubsection{ Binding Actuals to Formals} 3547 \subsubsection{ Binding Actuals to Formals}
3189 \label{bindingActualsToFormals} 3548 \LMLabel{bindingActualsToFormals}
3190 3549
3550 \LMHash{}
3191 Let $f$ be a function with $h$ required parameters, let $p_1 \ldots p_n$ be the positional parameters of $f$ and let $p_{h+1}, \ldots, p_{h+k}$ be the optional parameters declared by $f$. 3551 Let $f$ be a function with $h$ required parameters, let $p_1 \ldots p_n$ be the positional parameters of $f$ and let $p_{h+1}, \ldots, p_{h+k}$ be the optional parameters declared by $f$.
3192 3552
3553 \LMHash{}
3193 An evaluated actual argument list $o_1 \ldots o_{m+l}$ derived from an actual ar gument list of the form $(a_1, \ldots, a_m, q_1: a_{m+1}, \ldots, q_l: a_{m+l})$ is bound to the formal parameters of $f$ as follows: 3554 An evaluated actual argument list $o_1 \ldots o_{m+l}$ derived from an actual ar gument list of the form $(a_1, \ldots, a_m, q_1: a_{m+1}, \ldots, q_l: a_{m+l})$ is bound to the formal parameters of $f$ as follows:
3194 3555
3195 \commentary{ 3556 \commentary{
3196 We have an argument list consisting of $m$ positional arguments and $l$ named ar guments. We have a function with $h$ required parameters and $k$ optional parame ters. The number of positional arguments must be at least as large as the number of required parameters, and no larger than the number of positional parameters. All named arguments must have a corresponding named parameter. You may not prov ide a given named argument more than once. If an optional parameter has no corr esponding argument, it gets its default value. In checked mode, all arguments mu st belong to subtypes of the type of their corresponding formal. 3557 We have an argument list consisting of $m$ positional arguments and $l$ named ar guments. We have a function with $h$ required parameters and $k$ optional parame ters. The number of positional arguments must be at least as large as the number of required parameters, and no larger than the number of positional parameters. All named arguments must have a corresponding named parameter. You may not prov ide a given named argument more than once. If an optional parameter has no corr esponding argument, it gets its default value. In checked mode, all arguments mu st belong to subtypes of the type of their corresponding formal.
3197 } 3558 }
3198 3559
3199 \commentary{ 3560 \commentary{
3200 If $l > 0$, then it is necessarily the case that $n = h$, because a method canno t have both optional positional parameters and named parameters. 3561 If $l > 0$, then it is necessarily the case that $n = h$, because a method canno t have both optional positional parameters and named parameters.
3201 } 3562 }
3202 3563
3203 3564
3565 \LMHash{}
3204 If $m < h$, or $m > n$, a \cd{NoSuchMethodError} is thrown. Furthermore, each $ q_i, 1 \le i \le l$, must have a corresponding named parameter in the set $\{p_ {n+1}, \ldots, p_{n +k}\}$ or a \cd{NoSuchMethodError} is thrown. Then $p_i$ is bound to $o_i, i \in 1.. m$, and $q_j$ is bound to $o_{m+j}, j \in 1.. l$. All remaining formal parameters of $f$ are bound to their default values. 3566 If $m < h$, or $m > n$, a \cd{NoSuchMethodError} is thrown. Furthermore, each $ q_i, 1 \le i \le l$, must have a corresponding named parameter in the set $\{p_ {n+1}, \ldots, p_{n +k}\}$ or a \cd{NoSuchMethodError} is thrown. Then $p_i$ is bound to $o_i, i \in 1.. m$, and $q_j$ is bound to $o_{m+j}, j \in 1.. l$. All remaining formal parameters of $f$ are bound to their default values.
3205 3567
3206 \commentary{All of these remaining parameters are necessarily optional and thus have default values.} 3568 \commentary{All of these remaining parameters are necessarily optional and thus have default values.}
3207 3569
3570 \LMHash{}
3208 In checked mode, it is a dynamic type error if $o_i$ is not \NULL{} and the act ual type (\ref{actualTypeOfADeclaration}) of $p_i$ is not a supertype of the ty pe of $o_i, i \in 1.. m$. In checked mode, it is a dynamic type error if $o_{m+ j}$ is not \NULL{} and the actual type (\ref{actualTypeOfADeclaration}) of $q_j $ is not a supertype of the type of $o_{m+j}, j \in 1.. l$. 3571 In checked mode, it is a dynamic type error if $o_i$ is not \NULL{} and the act ual type (\ref{actualTypeOfADeclaration}) of $p_i$ is not a supertype of the ty pe of $o_i, i \in 1.. m$. In checked mode, it is a dynamic type error if $o_{m+ j}$ is not \NULL{} and the actual type (\ref{actualTypeOfADeclaration}) of $q_j $ is not a supertype of the type of $o_{m+j}, j \in 1.. l$.
3209 3572
3573 \LMHash{}
3210 It is a compile-time error if $q_i = q_j$ for any $i \ne j$. 3574 It is a compile-time error if $q_i = q_j$ for any $i \ne j$.
3211 3575
3576 \LMHash{}
3212 Let $T_i$ be the static type of $a_i$, let $S_i$ be the type of $p_i, i \in 1 .. h+k$ and let $S_q$ be the type of the named parameter $q$ of $f$. It is a stat ic warning if $T_j$ may not be assigned to $S_j, j \in 1..m$. It is a static wa rning if $m < h$ or if $m > n$. Furthermore, each $q_i, 1 \le i \le l$, must ha ve a corresponding named parameter in the set $\{p_{n+1}, \ldots, p_{n +k}\}$ or a static warning occurs. It is a static warning if $T_{m+j}$ may not be assign ed to $S_{q_j}, j \in 1 .. l$. 3577 Let $T_i$ be the static type of $a_i$, let $S_i$ be the type of $p_i, i \in 1 .. h+k$ and let $S_q$ be the type of the named parameter $q$ of $f$. It is a stat ic warning if $T_j$ may not be assigned to $S_j, j \in 1..m$. It is a static wa rning if $m < h$ or if $m > n$. Furthermore, each $q_i, 1 \le i \le l$, must ha ve a corresponding named parameter in the set $\{p_{n+1}, \ldots, p_{n +k}\}$ or a static warning occurs. It is a static warning if $T_{m+j}$ may not be assign ed to $S_{q_j}, j \in 1 .. l$.
3213 3578
3214 \subsubsection{ Unqualified Invocation} 3579 \subsubsection{ Unqualified Invocation}
3215 \label{unqualifiedInvocation} 3580 \LMLabel{unqualifiedInvocation}
3216 3581
3582 \LMHash{}
3217 An unqualified function invocation $i$ has the form 3583 An unqualified function invocation $i$ has the form
3218 3584
3219 $id(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$, 3585 $id(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$,
3220 3586
3221 where $id$ is an identifier. 3587 where $id$ is an identifier.
3222 3588
3589 \LMHash{}
3223 If there exists a lexically visible declaration named $id$, let $f_{id}$ be the innermost such declaration. Then: 3590 If there exists a lexically visible declaration named $id$, let $f_{id}$ be the innermost such declaration. Then:
3224 \begin{itemize} 3591 \begin{itemize}
3225 \item 3592 \item
3226 If $f_{id}$ is a local function, a library function, a library or static getter or a variable then $i$ is interpreted as a function expression invocation (\ref {functionExpressionInvocation}). 3593 If $f_{id}$ is a local function, a library function, a library or static getter or a variable then $i$ is interpreted as a function expression invocation (\ref {functionExpressionInvocation}).
3227 \item 3594 \item
3228 Otherwise, if $f_{id}$ is a static method of the enclosing class $C$, $i$ is equ ivalent to $C.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k}) $. 3595 Otherwise, if $f_{id}$ is a static method of the enclosing class $C$, $i$ is equ ivalent to $C.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k}) $.
3229 \item Otherwise, $f_{id}$ is considered equivalent to the ordinary method invoca tion $\THIS{}.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k}) $. 3596 \item Otherwise, $f_{id}$ is considered equivalent to the ordinary method invoca tion $\THIS{}.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k}) $.
3230 \end{itemize} 3597 \end{itemize}
3231 3598
3232 %Otherwise, if there is an accessible (\ref{privacy}) static method named $id$ d eclared in a superclass $S$ of the immediately enclosing class $C$ then i is equ ivalent to the static method invocation $S.id(a_1, \ldots, a_n, x_{n+1}: a_{n+1} , \ldots, x_{n+k}: a_{n+k})$. 3599 %Otherwise, if there is an accessible (\ref{privacy}) static method named $id$ d eclared in a superclass $S$ of the immediately enclosing class $C$ then i is equ ivalent to the static method invocation $S.id(a_1, \ldots, a_n, x_{n+1}: a_{n+1} , \ldots, x_{n+k}: a_{n+k})$.
3233 3600
3234 %\rationale{ 3601 %\rationale{
3235 %Unqualified access to static methods of superclasses is inconsistent with the i dea that static methods are not inherited. It is not particularly necessary and may be restricted in future versions. 3602 %Unqualified access to static methods of superclasses is inconsistent with the i dea that static methods are not inherited. It is not particularly necessary and may be restricted in future versions.
3236 %} 3603 %}
3237 3604
3605 \LMHash{}
3238 Otherwise, if $i$ occurs inside a top level or static function (be it function, method, getter, or setter) or variable initializer, evaluation of $i$ causes a \cd{NoSuchMethodError} to be thrown. 3606 Otherwise, if $i$ occurs inside a top level or static function (be it function, method, getter, or setter) or variable initializer, evaluation of $i$ causes a \cd{NoSuchMethodError} to be thrown.
3239 3607
3608 \LMHash{}
3240 If $i$ does not occur inside a top level or static function, $i$ is equivalent t o $\THIS{}.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. 3609 If $i$ does not occur inside a top level or static function, $i$ is equivalent t o $\THIS{}.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$.
3241 3610
3242 % Should also say: 3611 % Should also say:
3243 % It is a static warning if $i$ occurs inside a top level or static function (b e it function, method, getter, or setter) or variable initializer and there is no lexically visible declaration named $id$ in scope. 3612 % It is a static warning if $i$ occurs inside a top level or static function (b e it function, method, getter, or setter) or variable initializer and there is no lexically visible declaration named $id$ in scope.
3244 3613
3245 3614
3246 3615
3247 3616
3248 3617
3249 \subsubsection{ Function Expression Invocation} 3618 \subsubsection{ Function Expression Invocation}
3250 \label{functionExpressionInvocation} 3619 \LMLabel{functionExpressionInvocation}
3251 3620
3621 \LMHash{}
3252 A function expression invocation $i$ has the form 3622 A function expression invocation $i$ has the form
3253 3623
3254 $e_f(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 3624 $e_f(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
3255 3625
3256 where $e_f$ is an expression. If $e_f$ is an identifier $id$, then $id$ must nec essarily denote a local function, a library function, a library or static getter or a variable as described above, or $i$ is not considered a function expressio n invocation. If $e_f$ is a property extraction expression (\ref{propertyExtract ion}), then $i$ is is not a function expression invocation and is instead recogn ized as an ordinary method invocation (\ref{ordinaryInvocation}). 3626 where $e_f$ is an expression. If $e_f$ is an identifier $id$, then $id$ must nec essarily denote a local function, a library function, a library or static getter or a variable as described above, or $i$ is not considered a function expressio n invocation. If $e_f$ is a property extraction expression (\ref{propertyExtract ion}), then $i$ is is not a function expression invocation and is instead recogn ized as an ordinary method invocation (\ref{ordinaryInvocation}).
3257 3627
3258 \commentary{ 3628 \commentary{
3259 \code{$a.b(x)$} is parsed as a method invocation of method \code{$b()$} on objec t \code{$a$}, not as an invocation of getter \code{$b$} on \code{$a$} followed b y a function call \code{$(a.b)(x)$}. If a method or getter \code{$b$} exists, t he two will be equivalent. However, if \code{$b$} is not defined on \code{$a$}, the resulting invocation of \code{noSuchMethod()} would differ. The \code{Invoc ation} passed to \code{noSuchMethod()} would describe a call to a method \code{$ b$} with argument \code{$x$} in the former case, and a call to a getter \code{$b $} (with no arguments) in the latter. 3629 \code{$a.b(x)$} is parsed as a method invocation of method \code{$b()$} on objec t \code{$a$}, not as an invocation of getter \code{$b$} on \code{$a$} followed b y a function call \code{$(a.b)(x)$}. If a method or getter \code{$b$} exists, t he two will be equivalent. However, if \code{$b$} is not defined on \code{$a$}, the resulting invocation of \code{noSuchMethod()} would differ. The \code{Invoc ation} passed to \code{noSuchMethod()} would describe a call to a method \code{$ b$} with argument \code{$x$} in the former case, and a call to a getter \code{$b $} (with no arguments) in the latter.
3260 } 3630 }
3261 3631
3632 \LMHash{}
3262 Otherwise: 3633 Otherwise:
3263 3634
3264 A function expression invocation $e_f(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldot s , x_{n+k}: a_{n+k})$ is equivalent to $e_f.call(a_1, \ldots , a_n, x_{n+1}: a_ {n+1}, \ldots , x_{n+k}: a_{n+k})$. 3635 A function expression invocation $e_f(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldot s , x_{n+k}: a_{n+k})$ is equivalent to $e_f.call(a_1, \ldots , a_n, x_{n+1}: a_ {n+1}, \ldots , x_{n+k}: a_{n+k})$.
3265 3636
3266 \commentary{ 3637 \commentary{
3267 The implication of this definition, and the other definitions involving the meth od \code{call()}, is that user defined types can be used as function values prov ided they define a \CALL{} method. The method \CALL{} is special in this regard. The signature of the \CALL{} method determines the signature used when using th e object via the built-in invocation syntax. 3638 The implication of this definition, and the other definitions involving the meth od \code{call()}, is that user defined types can be used as function values prov ided they define a \CALL{} method. The method \CALL{} is special in this regard. The signature of the \CALL{} method determines the signature used when using th e object via the built-in invocation syntax.
3268 } 3639 }
3269 3640
3641 \LMHash{}
3270 It is a static warning if the static type $F$ of $e_f$ may not be assigned to a function type. If $F$ is not a function type, the static type of $i$ is \DYNAMI C{}. Otherwise 3642 It is a static warning if the static type $F$ of $e_f$ may not be assigned to a function type. If $F$ is not a function type, the static type of $i$ is \DYNAMI C{}. Otherwise
3271 the static type of $i$ is the declared return type of $F$. 3643 the static type of $i$ is the declared return type of $F$.
3272 %\item Let $T_i$ be the static type of $a_i, i \in 1 .. n+k$. It is a static war ning if $F$ is not a supertype of $(T_1, \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldot s, T_{n+k}$ $x_{n+k}]) \to \bot$. 3644 %\item Let $T_i$ be the static type of $a_i, i \in 1 .. n+k$. It is a static war ning if $F$ is not a supertype of $(T_1, \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldot s, T_{n+k}$ $x_{n+k}]) \to \bot$.
3273 %\end{itemize} 3645 %\end{itemize}
3274 3646
3275 \subsection{ Lookup} 3647 \subsection{ Lookup}
3276 3648
3277 \subsubsection{Method Lookup} 3649 \subsubsection{Method Lookup}
3278 \label{methodLookup} 3650 \LMLabel{methodLookup}
3279 3651
3652 \LMHash{}
3280 The result of a lookup of a method $m$ in object $o$ with respect to library $L$ is the result of a lookup of method $m$ in class $C$ with respect to library $ L$, where $C$ is the class of $o$. 3653 The result of a lookup of a method $m$ in object $o$ with respect to library $L$ is the result of a lookup of method $m$ in class $C$ with respect to library $ L$, where $C$ is the class of $o$.
3281 3654
3655 \LMHash{}
3282 The result of a lookup of method $m$ in class $C$ with respect to library $L$ i s: 3656 The result of a lookup of method $m$ in class $C$ with respect to library $L$ i s:
3283 If $C$ declares a concrete instance method named $m$ that is accessible to $L$, then that method is the result of the lookup. Otherwise, if $C$ has a superclas s $S$, then the result of the lookup is the result of looking up $m$ in $S$ wit h respect to $L$. Otherwise, we say that the method lookup has failed. 3657 If $C$ declares a concrete instance method named $m$ that is accessible to $L$, then that method is the result of the lookup. Otherwise, if $C$ has a superclas s $S$, then the result of the lookup is the result of looking up $m$ in $S$ wit h respect to $L$. Otherwise, we say that the method lookup has failed.
3284 3658
3285 \rationale { 3659 \rationale {
3286 The motivation for skipping abstract members during lookup is largely to allow s moother mixin composition. 3660 The motivation for skipping abstract members during lookup is largely to allow s moother mixin composition.
3287 } 3661 }
3288 3662
3289 3663
3290 \subsubsection{ Getter and Setter Lookup} 3664 \subsubsection{ Getter and Setter Lookup}
3291 \label{getterAndSetterLookup} 3665 \LMLabel{getterAndSetterLookup}
3292 3666
3667 \LMHash{}
3293 The result of a lookup of a getter (respectively setter) $m$ in object $o$ with respect to library $L$ is the result of looking up getter (respectively sette r) $m$ in class $C$ with respect to $L$, where $C$ is the class of $o$. 3668 The result of a lookup of a getter (respectively setter) $m$ in object $o$ with respect to library $L$ is the result of looking up getter (respectively sette r) $m$ in class $C$ with respect to $L$, where $C$ is the class of $o$.
3294 3669
3670 \LMHash{}
3295 The result of a lookup of a getter (respectively setter) $m$ in class $C$ with respect to library $L$ is: 3671 The result of a lookup of a getter (respectively setter) $m$ in class $C$ with respect to library $L$ is:
3296 If $C$ declares a concrete instance getter (respectively setter) named $m$ that is accessible to $L$, then that getter (respectively setter) is the result of the lookup. Otherwise, if $C$ has a superclass $S$, then the result of the looku p is the result of looking up getter (respectively setter) $m$ in $S$ with respe ct to $L$. Otherwise, we say that the lookup has failed. 3672 If $C$ declares a concrete instance getter (respectively setter) named $m$ that is accessible to $L$, then that getter (respectively setter) is the result of the lookup. Otherwise, if $C$ has a superclass $S$, then the result of the looku p is the result of looking up getter (respectively setter) $m$ in $S$ with respe ct to $L$. Otherwise, we say that the lookup has failed.
3297 3673
3298 \rationale { 3674 \rationale {
3299 The motivation for skipping abstract members during lookup is largely to allow s moother mixin composition. 3675 The motivation for skipping abstract members during lookup is largely to allow s moother mixin composition.
3300 } 3676 }
3301 3677
3302 3678
3303 \subsection{ Top level Getter Invocation} 3679 \subsection{ Top level Getter Invocation}
3304 \label{topLevelGetterInvocation} 3680 \LMLabel{topLevelGetterInvocation}
3305 3681
3682 \LMHash{}
3306 Evaluation of a top-level getter invocation $i$ of the form $m$, where $m$ is an identifier, proceeds as follows: 3683 Evaluation of a top-level getter invocation $i$ of the form $m$, where $m$ is an identifier, proceeds as follows:
3307 3684
3685 \LMHash{}
3308 The getter function $m$ is invoked. The value of $i$ is the result returned by t he call to the getter function. 3686 The getter function $m$ is invoked. The value of $i$ is the result returned by t he call to the getter function.
3309 \commentary{ 3687 \commentary{
3310 Note that the invocation is always defined. Per the rules for identifier referen ces, an identifier will not be treated as a top-level getter invocation unless t he getter $i$ is defined. 3688 Note that the invocation is always defined. Per the rules for identifier referen ces, an identifier will not be treated as a top-level getter invocation unless t he getter $i$ is defined.
3311 } 3689 }
3312 3690
3691 \LMHash{}
3313 The static type of $i$ is the declared return type of $m$. 3692 The static type of $i$ is the declared return type of $m$.
3314 3693
3315 \subsection{ Method Invocation} 3694 \subsection{ Method Invocation}
3316 \label{methodInvocation} 3695 \LMLabel{methodInvocation}
3317 3696
3697 \LMHash{}
3318 Method invocation can take several forms as specified below. 3698 Method invocation can take several forms as specified below.
3319 3699
3320 \subsubsection{Ordinary Invocation} 3700 \subsubsection{Ordinary Invocation}
3321 \label{ordinaryInvocation} 3701 \LMLabel{ordinaryInvocation}
3322 3702
3703 \LMHash{}
3323 An ordinary method invocation $i$ has the form 3704 An ordinary method invocation $i$ has the form
3324 3705
3325 $o.m(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. 3706 $o.m(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$.
3326 3707
3708 \LMHash{}
3327 Evaluation of an ordinary method invocation $i$ of the form 3709 Evaluation of an ordinary method invocation $i$ of the form
3328 3710
3329 $o.m(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3711 $o.m(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
3330 3712
3331 proceeds as follows: 3713 proceeds as follows:
3332 3714
3715 \LMHash{}
3333 First, the expression $o$ is evaluated to a value $v_o$. Next, the argument list $(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ is evaluated yielding actual argument objects $o_1, \ldots , o_{n+k}$. Let $f$ be the result of looking up (\ref{methodLookup}) method $m$ in $v_o$ with respect to the cur rent library $L$. 3716 First, the expression $o$ is evaluated to a value $v_o$. Next, the argument list $(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ is evaluated yielding actual argument objects $o_1, \ldots , o_{n+k}$. Let $f$ be the result of looking up (\ref{methodLookup}) method $m$ in $v_o$ with respect to the cur rent library $L$.
3334 3717
3718 \LMHash{}
3335 Let $p_1 \ldots p_h$ be the required parameters of $f$, let $p_1 \ldots p_m$ be the positional parameters of $f$ and let $p_{h+1}, \ldots, p_{h+l}$ be the opti onal parameters declared by $f$. 3719 Let $p_1 \ldots p_h$ be the required parameters of $f$, let $p_1 \ldots p_m$ be the positional parameters of $f$ and let $p_{h+1}, \ldots, p_{h+l}$ be the opti onal parameters declared by $f$.
3336 3720
3337 \commentary{ 3721 \commentary{
3338 We have an argument list consisting of $n$ positional arguments and $k$ named ar guments. We have a function with $h$ required parameters and $l$ optional parame ters. The number of positional arguments must be at least as large as the number of required parameters, and no larger than the number of positional parameters. All named arguments must have a corresponding named parameter. 3722 We have an argument list consisting of $n$ positional arguments and $k$ named ar guments. We have a function with $h$ required parameters and $l$ optional parame ters. The number of positional arguments must be at least as large as the number of required parameters, and no larger than the number of positional parameters. All named arguments must have a corresponding named parameter.
3339 } 3723 }
3340 3724
3725 \LMHash{}
3341 If $n < h$, or $n > m$, the method lookup has failed. Furthermore, each $x_i, n +1 \le i \le n+k$, must have a corresponding named parameter in the set $\{p_{m +1}, \ldots, p_{h+l}\}$ or the method lookup also fails. If $v_o$ is an instanc e of \code{Type} but $o$ is not a constant type literal, then if $m$ is a method that forwards (\ref{functionDeclarations}) to a static method, method lookup fa ils. Otherwise method lookup has succeeded. 3726 If $n < h$, or $n > m$, the method lookup has failed. Furthermore, each $x_i, n +1 \le i \le n+k$, must have a corresponding named parameter in the set $\{p_{m +1}, \ldots, p_{h+l}\}$ or the method lookup also fails. If $v_o$ is an instanc e of \code{Type} but $o$ is not a constant type literal, then if $m$ is a method that forwards (\ref{functionDeclarations}) to a static method, method lookup fa ils. Otherwise method lookup has succeeded.
3342 3727
3728 \LMHash{}
3343 If the method lookup succeeded, the body of $f$ is executed with respect to the bindings that resulted from the evaluation of the argument list, and with \THIS{ } bound to $v_o$. The value of $i$ is the value returned after $f$ is executed. 3729 If the method lookup succeeded, the body of $f$ is executed with respect to the bindings that resulted from the evaluation of the argument list, and with \THIS{ } bound to $v_o$. The value of $i$ is the value returned after $f$ is executed.
3344 3730
3731 \LMHash{}
3345 If the method lookup has failed, then let $g$ be the result of looking up getter (\ref{getterAndSetterLookup}) $m$ in $v_o$ with respect to $L$. 3732 If the method lookup has failed, then let $g$ be the result of looking up getter (\ref{getterAndSetterLookup}) $m$ in $v_o$ with respect to $L$.
3346 f $v_o$ is an instance of \code{Type} but $o$ is not a constant type literal, th en if $g$ is a getter that forwards to a static getter, getter lookup fails. 3733 f $v_o$ is an instance of \code{Type} but $o$ is not a constant type literal, th en if $g$ is a getter that forwards to a static getter, getter lookup fails.
3347 If the getter lookup succeeded, let $v_g$ be the value of the getter invocation $o.m$. Then the value of $i$ is the result of invoking 3734 If the getter lookup succeeded, let $v_g$ be the value of the getter invocation $o.m$. Then the value of $i$ is the result of invoking
3348 the static method \code{Function.apply()} with arguments $v.g, [o_1, \ldots , o_ n], \{x_{n+1}: o_{n+1}, \ldots , x_{n+k}: o_{n+k}\}$. 3735 the static method \code{Function.apply()} with arguments $v.g, [o_1, \ldots , o_ n], \{x_{n+1}: o_{n+1}, \ldots , x_{n+k}: o_{n+k}\}$.
3349 3736
3737 \LMHash{}
3350 If getter lookup has also failed, then a new instance $im$ of the predefined c lass \code{Invocation} is created, such that : 3738 If getter lookup has also failed, then a new instance $im$ of the predefined c lass \code{Invocation} is created, such that :
3351 \begin{itemize} 3739 \begin{itemize}
3352 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 3740 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
3353 \item \code{im.memberName} evaluates to \code{'m'}. 3741 \item \code{im.memberName} evaluates to \code{'m'}.
3354 \item \code{im.positionalArguments} evaluates to an immutable list with the same values as \code{[$o_1, \ldots, o_n$]}. 3742 \item \code{im.positionalArguments} evaluates to an immutable list with the same values as \code{[$o_1, \ldots, o_n$]}.
3355 \item \code{im.namedArguments} evaluates to an immutable map with the same keys and values as \code{\{$x_{n+1}: o_{n+1}, \ldots, x_{n+k} : o_{n+k}$\}}. 3743 \item \code{im.namedArguments} evaluates to an immutable map with the same keys and values as \code{\{$x_{n+1}: o_{n+1}, \ldots, x_{n+k} : o_{n+k}$\}}.
3356 \end{itemize} 3744 \end{itemize}
3357 3745
3746 \LMHash{}
3358 Then the method \code{noSuchMethod()} is looked up in $v_o$ and invoked with arg ument $im$, and the result of this invocation is the result of evaluating $i$. H owever, if the implementation found cannot be invoked with a single positional a rgument, the implementation of \code{noSuchMethod()} in class \code{Object} is invoked on $v_o$ with argument $im'$, where $im'$ is an instance of \code{Invoca tion} such that : 3747 Then the method \code{noSuchMethod()} is looked up in $v_o$ and invoked with arg ument $im$, and the result of this invocation is the result of evaluating $i$. H owever, if the implementation found cannot be invoked with a single positional a rgument, the implementation of \code{noSuchMethod()} in class \code{Object} is invoked on $v_o$ with argument $im'$, where $im'$ is an instance of \code{Invoca tion} such that :
3359 \begin{itemize} 3748 \begin{itemize}
3360 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 3749 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
3361 \item \code{im.memberName} evaluates to \code{noSuchMethod'}. 3750 \item \code{im.memberName} evaluates to \code{noSuchMethod'}.
3362 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$. 3751 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$.
3363 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 3752 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3364 \end{itemize} 3753 \end{itemize}
3365 3754
3366 and the result of the latter invocation is the result of evaluating $i$. 3755 and the result of the latter invocation is the result of evaluating $i$.
3367 3756
3368 \rationale { 3757 \rationale {
3369 It is possible to bring about such a situation by overriding \code{noSuchMethod( )} with the wrong number of arguments:} 3758 It is possible to bring about such a situation by overriding \code{noSuchMethod( )} with the wrong number of arguments:}
3370 3759
3371 \begin{code} 3760 \begin{code}
3372 \CLASS{} Perverse \{ 3761 \CLASS{} Perverse \{
3373 noSuchMethod(x,y) =$>$ x + y; 3762 noSuchMethod(x,y) =$>$ x + y;
3374 \} 3763 \}
3375 3764
3376 \NEW{} Perverse.unknownMethod(); 3765 \NEW{} Perverse.unknownMethod();
3377 \end{code} 3766 \end{code}
3378 3767
3379 \commentary{Notice that the wording carefully avoids re-evaluating the receiver $o$ and the arguments $a_i$. } 3768 \commentary{Notice that the wording carefully avoids re-evaluating the receiver $o$ and the arguments $a_i$. }
3380 3769
3770 \LMHash{}
3381 Let $T$ be the static type of $o$. It is a static type warning if $T$ does not have an accessible (\ref{privacy}) instance member named $m$ unless either: 3771 Let $T$ be the static type of $o$. It is a static type warning if $T$ does not have an accessible (\ref{privacy}) instance member named $m$ unless either:
3382 \begin{itemize} 3772 \begin{itemize}
3383 \item 3773 \item
3384 $T$ or a superinterface of $T$ is annotated with an annotation denoting a consta nt identical to the constant \code{@proxy} defined in \code{dart:core}. Or 3774 $T$ or a superinterface of $T$ is annotated with an annotation denoting a consta nt identical to the constant \code{@proxy} defined in \code{dart:core}. Or
3385 \item $T$ is \code{Type}, $e$ is a constant type literal and the class correspo nding to $e$ has a static getter named $m$. 3775 \item $T$ is \code{Type}, $e$ is a constant type literal and the class correspo nding to $e$ has a static getter named $m$.
3386 \end{itemize} 3776 \end{itemize}
3387 3777
3778 \LMHash{}
3388 If $T.m$ exists, it is a static type warning if the type $F$ of $T.m$ may not b e assigned to a function type. If $T.m$ does not exist, or if $F$ is not a funct ion type, the static type of $i$ is \DYNAMIC{}; otherwise the static type of $i$ is the declared return type of $F$. 3779 If $T.m$ exists, it is a static type warning if the type $F$ of $T.m$ may not b e assigned to a function type. If $T.m$ does not exist, or if $F$ is not a funct ion type, the static type of $i$ is \DYNAMIC{}; otherwise the static type of $i$ is the declared return type of $F$.
3389 3780
3781 \LMHash{}
3390 It is a compile-time error to invoke any of the methods of class \cd{Object} on a prefix object (\ref{imports}) or on a constant type literal that is immediate ly followed by the token `.'. 3782 It is a compile-time error to invoke any of the methods of class \cd{Object} on a prefix object (\ref{imports}) or on a constant type literal that is immediate ly followed by the token `.'.
3391 3783
3392 3784
3393 \subsubsection{Cascaded Invocations} 3785 \subsubsection{Cascaded Invocations}
3394 \label{cascadedInvocations} 3786 \LMLabel{cascadedInvocations}
3395 3787
3788 \LMHash{}
3396 A {\em cascaded method invocation} has the form {\em e..suffix} 3789 A {\em cascaded method invocation} has the form {\em e..suffix}
3397 where $e$ is an expression and {\em suffix} is a sequence of operator, method, g etter or setter invocations. 3790 where $e$ is an expression and {\em suffix} is a sequence of operator, method, g etter or setter invocations.
3398 3791
3399 \begin{grammar} 3792 \begin{grammar}
3400 {\bf cascadeSection:} 3793 {\bf cascadeSection:}
3401 `{\escapegrammar ..}' (cascadeSelector arguments*) (assignableSelector arg uments*)* (assignmentOperator expressionWithoutCascade)? 3794 `{\escapegrammar ..}' (cascadeSelector arguments*) (assignableSelector arg uments*)* (assignmentOperator expressionWithoutCascade)?
3402 . 3795 .
3403 3796
3404 {\bf cascadeSelector:}`[' expression `]'; 3797 {\bf cascadeSelector:}`[' expression `]';
3405 identifier 3798 identifier
3406 . 3799 .
3407 \end{grammar} 3800 \end{grammar}
3408 3801
3802 \LMHash{}
3409 A cascaded method invocation expression of the form {\em e..suffix} is equivalen t to the expression \code{(t)\{t.{\em suffix}; \RETURN{} t;\}($e$)}. 3803 A cascaded method invocation expression of the form {\em e..suffix} is equivalen t to the expression \code{(t)\{t.{\em suffix}; \RETURN{} t;\}($e$)}.
3410 3804
3411 \subsubsection{Super Invocation} 3805 \subsubsection{Super Invocation}
3412 \label{superInvocation} 3806 \LMLabel{superInvocation}
3413 3807
3808 \LMHash{}
3414 A super method invocation $i$ has the form 3809 A super method invocation $i$ has the form
3415 3810
3416 $\SUPER{}.m(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. 3811 $\SUPER{}.m(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$.
3417 3812
3813 \LMHash{}
3418 Evaluation of $i$ proceeds as follows: 3814 Evaluation of $i$ proceeds as follows:
3419 3815
3816 \LMHash{}
3420 First, the argument list $(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k} : a_{n+k})$ is evaluated yielding actual argument objects $o_1, \ldots , o_{n+k }$. Let $S$ be the superclass of the immediately enclosing class, and let $f$ be the result of looking up method (\ref{ordinaryInvocation}) $m$ in $S$ with re spect to the current library $L$. 3817 First, the argument list $(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k} : a_{n+k})$ is evaluated yielding actual argument objects $o_1, \ldots , o_{n+k }$. Let $S$ be the superclass of the immediately enclosing class, and let $f$ be the result of looking up method (\ref{ordinaryInvocation}) $m$ in $S$ with re spect to the current library $L$.
3421 Let $p_1 \ldots p_h$ be the required parameters of $f$, let $p_1 \ldots p_m$ be the positional parameters of $f$ and let $p_{h+1}, \ldots, p_{h+l}$ be the opti onal parameters declared by $f$. 3818 Let $p_1 \ldots p_h$ be the required parameters of $f$, let $p_1 \ldots p_m$ be the positional parameters of $f$ and let $p_{h+1}, \ldots, p_{h+l}$ be the opti onal parameters declared by $f$.
3422 3819
3820 \LMHash{}
3423 If $n < h$, or $n > m$, the method lookup has failed. Furthermore, each $x_i, n +1 \le i \le n+k$, must have a corresponding named parameter in the set $\{p_{m +1}, \ldots, p_{h+l}\}$ or the method lookup also fails. Otherwise method looku p has succeeded. 3821 If $n < h$, or $n > m$, the method lookup has failed. Furthermore, each $x_i, n +1 \le i \le n+k$, must have a corresponding named parameter in the set $\{p_{m +1}, \ldots, p_{h+l}\}$ or the method lookup also fails. Otherwise method looku p has succeeded.
3424 3822
3823 \LMHash{}
3425 If the method lookup succeeded, the body of $f$ is executed with respect to the bindings that resulted from the evaluation of the argument list, and with \THIS{ } bound to the current value of \THIS{}. The value of $i$ is the value returned after $f$ is executed. 3824 If the method lookup succeeded, the body of $f$ is executed with respect to the bindings that resulted from the evaluation of the argument list, and with \THIS{ } bound to the current value of \THIS{}. The value of $i$ is the value returned after $f$ is executed.
3426 3825
3826 \LMHash{}
3427 If the method lookup has failed, then let $g$ be the result of looking up getter (\ref{getterAndSetterLookup}) $m$ in $S$ with respect to $L$. If the getter loo kup succeeded, let $v_g$ be the value of the getter invocation $\SUPER{}.m$. The n the value of $i$ is the result of invoking 3827 If the method lookup has failed, then let $g$ be the result of looking up getter (\ref{getterAndSetterLookup}) $m$ in $S$ with respect to $L$. If the getter loo kup succeeded, let $v_g$ be the value of the getter invocation $\SUPER{}.m$. The n the value of $i$ is the result of invoking
3428 the static method \code{Function.apply()} with arguments $v.g, [o_1, \ldots , o_ n], \{x_{n+1}: o_{n+1}, \ldots , x_{n+k}: o_{n+k}\}$. 3828 the static method \code{Function.apply()} with arguments $v.g, [o_1, \ldots , o_ n], \{x_{n+1}: o_{n+1}, \ldots , x_{n+k}: o_{n+k}\}$.
3429 3829
3830 \LMHash{}
3430 If getter lookup has also failed, then a new instance $im$ of the predefined c lass \code{Invocation} is created, such that : 3831 If getter lookup has also failed, then a new instance $im$ of the predefined c lass \code{Invocation} is created, such that :
3431 \begin{itemize} 3832 \begin{itemize}
3432 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 3833 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
3433 \item \code{im.memberName} evaluates to \code{'m'}. 3834 \item \code{im.memberName} evaluates to \code{'m'}.
3434 \item \code{im.positionalArguments} evaluates to an immutable list with the same values as \code{[$o_1, \ldots, o_n$]}. 3835 \item \code{im.positionalArguments} evaluates to an immutable list with the same values as \code{[$o_1, \ldots, o_n$]}.
3435 \item \code{im.namedArguments} evaluates to an immutable map with the same keys and values as \code{\{$x_{n+1}: o_{n+1}, \ldots, x_{n+k} : o_{n+k}$\}}. 3836 \item \code{im.namedArguments} evaluates to an immutable map with the same keys and values as \code{\{$x_{n+1}: o_{n+1}, \ldots, x_{n+k} : o_{n+k}$\}}.
3436 \end{itemize} 3837 \end{itemize}
3437 Then the method \code{noSuchMethod()} is looked up in $S$ and invoked on \THIS{} with argument $im$, and the result of this invocation is the result of evaluati ng $i$. However, if the implementation found cannot be invoked with a single pos itional argument, the implementation of \code{noSuchMethod()} in class \code{Ob ject} is invoked on \THIS{} with argument $im'$, where $im'$ is an instance of \ code{Invocation} such that : 3838 Then the method \code{noSuchMethod()} is looked up in $S$ and invoked on \THIS{} with argument $im$, and the result of this invocation is the result of evaluati ng $i$. However, if the implementation found cannot be invoked with a single pos itional argument, the implementation of \code{noSuchMethod()} in class \code{Ob ject} is invoked on \THIS{} with argument $im'$, where $im'$ is an instance of \ code{Invocation} such that :
3438 \begin{itemize} 3839 \begin{itemize}
3439 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 3840 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
3440 \item \code{im.memberName} evaluates to \code{noSuchMethod}. 3841 \item \code{im.memberName} evaluates to \code{noSuchMethod}.
3441 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$. 3842 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$.
3442 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 3843 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3443 \end{itemize} 3844 \end{itemize}
3444 3845
3445 and the result of this latter invocation is the result of evaluating $i$. 3846 and the result of this latter invocation is the result of evaluating $i$.
3446 3847
3447 3848
3849 \LMHash{}
3448 It is a compile-time error if a super method invocation occurs in a top-level fu nction or variable initializer, in an instance variable initializer or initializ er list, in class \code{Object}, in a factory constructor or in a static method or variable initializer. 3850 It is a compile-time error if a super method invocation occurs in a top-level fu nction or variable initializer, in an instance variable initializer or initializ er list, in class \code{Object}, in a factory constructor or in a static method or variable initializer.
3449 3851
3852 \LMHash{}
3450 It is a static type warning if $S$ does not have an accessible (\ref{privacy}) i nstance member named $m$ unless $S$ or a superinterface of $S$ is annotated with an annotation denoting a constant identical to the constant \code{@proxy} defin ed in \code{dart:core}. If $S.m$ exists, it is a static type warning if the typ e $F$ of $S.m$ may not be assigned to a function type. If $S.m$ does not exist, or if $F$ is not a function type, the static type of $i$ is \DYNAMIC{}; otherwis e the static type of $i$ is the declared return type of $F$. 3853 It is a static type warning if $S$ does not have an accessible (\ref{privacy}) i nstance member named $m$ unless $S$ or a superinterface of $S$ is annotated with an annotation denoting a constant identical to the constant \code{@proxy} defin ed in \code{dart:core}. If $S.m$ exists, it is a static type warning if the typ e $F$ of $S.m$ may not be assigned to a function type. If $S.m$ does not exist, or if $F$ is not a function type, the static type of $i$ is \DYNAMIC{}; otherwis e the static type of $i$ is the declared return type of $F$.
3451 % The following is not needed because it is specified in 'Binding Actuals to For mals" 3854 % The following is not needed because it is specified in 'Binding Actuals to For mals"
3452 %Let $T_i$ be the static type of $a_i, i \in 1 .. n+k$. It is a static warning i f $F$ is not a supertype of $(T_1, \ldots, t_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_ {n+k}$ $x_{n+k}\}) \to \bot$. 3855 %Let $T_i$ be the static type of $a_i, i \in 1 .. n+k$. It is a static warning i f $F$ is not a supertype of $(T_1, \ldots, t_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_ {n+k}$ $x_{n+k}\}) \to \bot$.
3453 3856
3454 3857
3455 3858
3456 3859
3457 \subsubsection{Sending Messages} 3860 \subsubsection{Sending Messages}
3861 \LMLabel{sendingMessages}
3458 3862
3459 \label{sendingMessages} 3863 \LMHash{}
3460
3461 Messages are the sole means of communication among isolates. Messages are sent b y invoking specific methods in the Dart libraries; there is no specific syntax for sending a message. 3864 Messages are the sole means of communication among isolates. Messages are sent b y invoking specific methods in the Dart libraries; there is no specific syntax for sending a message.
3462 3865
3463 \commentary{In other words, the methods supporting sending messages embody primi tives of Dart that are not accessible to ordinary code, much like the methods th at spawn isolates. 3866 \commentary{In other words, the methods supporting sending messages embody primi tives of Dart that are not accessible to ordinary code, much like the methods th at spawn isolates.
3464 } 3867 }
3465 3868
3466 3869
3467 3870
3468 \subsection{ Property Extraction} 3871 \subsection{ Property Extraction}
3469 \label{propertyExtraction} 3872 \LMLabel{propertyExtraction}
3470 3873
3874 \LMHash{}
3471 {\em Property extraction} allows for a member of an object to be concisely extra cted from the object. 3875 {\em Property extraction} allows for a member of an object to be concisely extra cted from the object.
3472 A property extraction can be either: 3876 A property extraction can be either:
3473 \begin{enumerate} 3877 \begin{enumerate}
3474 \item A {\em closurization} (\ref{closurization}) which allows a method to be tr eated as if it were a getter for a function valued object. Or 3878 \item A {\em closurization} (\ref{closurization}) which allows a method to be tr eated as if it were a getter for a function valued object. Or
3475 \item A {\em getter invocation} which returns the result of invoking of a getter method. 3879 \item A {\em getter invocation} which returns the result of invoking of a getter method.
3476 \end{enumerate} 3880 \end{enumerate}
3477 3881
3882 \LMHash{}
3478 Evaluation of a property extraction $i$ of the form $e.m$ proceeds as follows: 3883 Evaluation of a property extraction $i$ of the form $e.m$ proceeds as follows:
3479 3884
3885 \LMHash{}
3480 First, the expression $e$ is evaluated to an object $o$. Let $f$ be the result o f looking up (\ref{methodLookup}) method (\ref{instanceMethods}) $m$ in $o$ wit h respect to the current library $L$. If $o$ is an instance of \code{Type} but $e$ is not a constant type literal, then if $m$ is a method that forwards (\ref{ functionDeclarations}) to a static method, method lookup fails. If method looku p succeeds and $f$ is a concrete method then $i$ evaluates to the closurization of $o.m$. 3886 First, the expression $e$ is evaluated to an object $o$. Let $f$ be the result o f looking up (\ref{methodLookup}) method (\ref{instanceMethods}) $m$ in $o$ wit h respect to the current library $L$. If $o$ is an instance of \code{Type} but $e$ is not a constant type literal, then if $m$ is a method that forwards (\ref{ functionDeclarations}) to a static method, method lookup fails. If method looku p succeeds and $f$ is a concrete method then $i$ evaluates to the closurization of $o.m$.
3481 3887
3888 \LMHash{}
3482 Otherwise, $i$ is a getter invocation, and the getter function (\ref{getters}) $ m$ is looked up (\ref{getterAndSetterLookup}) in $o$ with respect to $L$. If $o $ is an instance of \code{Type} but $e$ is not a constant type literal, then if $m$ is a getter that forwards to a static getter, getter lookup fails. Otherwi se, the body of $m$ is executed with \THIS{} bound to $o$. The value of $i$ is the result returned by the call to the getter function. 3889 Otherwise, $i$ is a getter invocation, and the getter function (\ref{getters}) $ m$ is looked up (\ref{getterAndSetterLookup}) in $o$ with respect to $L$. If $o $ is an instance of \code{Type} but $e$ is not a constant type literal, then if $m$ is a getter that forwards to a static getter, getter lookup fails. Otherwi se, the body of $m$ is executed with \THIS{} bound to $o$. The value of $i$ is the result returned by the call to the getter function.
3483 3890
3891 \LMHash{}
3484 If the getter lookup has failed, then a new instance $im$ of the predefined cla ss \code{Invocation} is created, such that : 3892 If the getter lookup has failed, then a new instance $im$ of the predefined cla ss \code{Invocation} is created, such that :
3485 \begin{itemize} 3893 \begin{itemize}
3486 \item \code{im.isGetter} evaluates to \code{\TRUE{}}. 3894 \item \code{im.isGetter} evaluates to \code{\TRUE{}}.
3487 \item \code{im.memberName} evaluates to \code{'m'}. 3895 \item \code{im.memberName} evaluates to \code{'m'}.
3488 \item \code{im.positionalArguments} evaluates to the value of \code{\CONST{} []} . 3896 \item \code{im.positionalArguments} evaluates to the value of \code{\CONST{} []} .
3489 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 3897 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3490 \end{itemize} 3898 \end{itemize}
3491 Then the method \code{noSuchMethod()} is looked up in $o$ and invoked with argu ment $im$, and the result of this invocation is the result of evaluating $i$. Ho wever, if the implementation found cannot be invoked with a single positional ar gument, the implementation of \code{noSuchMethod()} in class \code{Object} is i nvoked on $o$ with argument $im'$, where $im'$ is an instance of \code{Invocatio n} such that : 3899 Then the method \code{noSuchMethod()} is looked up in $o$ and invoked with argu ment $im$, and the result of this invocation is the result of evaluating $i$. Ho wever, if the implementation found cannot be invoked with a single positional ar gument, the implementation of \code{noSuchMethod()} in class \code{Object} is i nvoked on $o$ with argument $im'$, where $im'$ is an instance of \code{Invocatio n} such that :
3492 \begin{itemize} 3900 \begin{itemize}
3493 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 3901 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
3494 \item \code{im.memberName} evaluates to \code{noSuchMethod}. 3902 \item \code{im.memberName} evaluates to \code{noSuchMethod}.
3495 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$. 3903 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$.
3496 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 3904 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3497 \end{itemize} 3905 \end{itemize}
3498 3906
3499 and the result of this latter invocation is the result of evaluating $i$. 3907 and the result of this latter invocation is the result of evaluating $i$.
3500 3908
3909 \LMHash{}
3501 It is a compile-time error if $m$ is a member of class \cd{Object} and $e$ is ei ther a prefix object (\ref{imports}) or a constant type literal. 3910 It is a compile-time error if $m$ is a member of class \cd{Object} and $e$ is ei ther a prefix object (\ref{imports}) or a constant type literal.
3502 3911
3503 \commentary { 3912 \commentary {
3504 This precludes \code{int.toString} but not \code{(int).toString} because in the latter case, $e$ is a parenthesized expression. 3913 This precludes \code{int.toString} but not \code{(int).toString} because in the latter case, $e$ is a parenthesized expression.
3505 } 3914 }
3506 3915
3916 \LMHash{}
3507 Let $T$ be the static type of $e$. It is a static type warning if $T$ does not have a method or getter named $m$ unless either: 3917 Let $T$ be the static type of $e$. It is a static type warning if $T$ does not have a method or getter named $m$ unless either:
3508 \begin{itemize} 3918 \begin{itemize}
3509 \item 3919 \item
3510 $T$ or a superinterface of $T$ is annotated with an annotation denoting a consta nt identical to the constant \code{@proxy} defined in \code{dart:core}. Or 3920 $T$ or a superinterface of $T$ is annotated with an annotation denoting a consta nt identical to the constant \code{@proxy} defined in \code{dart:core}. Or
3511 \item $T$ is \code{Type}, $e$ is a constant type literal and the class correspo nding to $e$ has a static method or getter named $m$. 3921 \item $T$ is \code{Type}, $e$ is a constant type literal and the class correspo nding to $e$ has a static method or getter named $m$.
3512 \end{itemize} 3922 \end{itemize}
3513 3923
3924 \LMHash{}
3514 If $i$ is a getter invocation, the static type of $i$ is: 3925 If $i$ is a getter invocation, the static type of $i$ is:
3515 \begin{itemize} 3926 \begin{itemize}
3516 \item The declared return type of $T.m$, if $T.m$ exists. 3927 \item The declared return type of $T.m$, if $T.m$ exists.
3517 \item The declared return type of $m$, if $T$ is \code{Type}, $e$ is a constant type literal and the class corresponding to $e$ has a static method or getter n amed $m$. 3928 \item The declared return type of $m$, if $T$ is \code{Type}, $e$ is a constant type literal and the class corresponding to $e$ has a static method or getter n amed $m$.
3518 \item The type \DYNAMIC{} otherwise. 3929 \item The type \DYNAMIC{} otherwise.
3519 \end{itemize} 3930 \end{itemize}
3520 3931
3932 \LMHash{}
3521 If $i$ is a closurization, its static type is as described in section \ref{closu rization}. 3933 If $i$ is a closurization, its static type is as described in section \ref{closu rization}.
3522 3934
3935 \LMHash{}
3523 Evaluation of a property extraction $i$ of the form $\SUPER.m$ proceeds as follo ws: 3936 Evaluation of a property extraction $i$ of the form $\SUPER.m$ proceeds as follo ws:
3524 3937
3938 \LMHash{}
3525 Let $S$ be the superclass of the immediately enclosing class. Let $f$ be the re sult of looking up method $m$ in $S$ with respect to the current library $L$. I f $f$ is a concrete method then $i$ evaluates to the closurization of $\SUPER.m$ with respect to superclass $S$(\ref{closurization}). 3939 Let $S$ be the superclass of the immediately enclosing class. Let $f$ be the re sult of looking up method $m$ in $S$ with respect to the current library $L$. I f $f$ is a concrete method then $i$ evaluates to the closurization of $\SUPER.m$ with respect to superclass $S$(\ref{closurization}).
3526 3940
3941 \LMHash{}
3527 Otherwise, $i$ is a getter invocation and the getter function $m$ is looked up in $S$ with respect to $L$, and its body is executed with \THIS{} bound to the current value of \THIS{}. The value of $i$ is the result returned by the call to the getter function. 3942 Otherwise, $i$ is a getter invocation and the getter function $m$ is looked up in $S$ with respect to $L$, and its body is executed with \THIS{} bound to the current value of \THIS{}. The value of $i$ is the result returned by the call to the getter function.
3528 3943
3944 \LMHash{}
3529 If the getter lookup has failed, then a new instance $im$ of the predefined cla ss \code{Invocation} is created, such that : 3945 If the getter lookup has failed, then a new instance $im$ of the predefined cla ss \code{Invocation} is created, such that :
3530 \begin{itemize} 3946 \begin{itemize}
3531 \item \code{im.isGetter} evaluates to \code{\TRUE{}}. 3947 \item \code{im.isGetter} evaluates to \code{\TRUE{}}.
3532 \item \code{im.memberName} evaluates to \code{'m'}. 3948 \item \code{im.memberName} evaluates to \code{'m'}.
3533 \item \code{im.positionalArguments} evaluates to the value of \code{\CONST{} []} . 3949 \item \code{im.positionalArguments} evaluates to the value of \code{\CONST{} []} .
3534 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 3950 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3535 \end{itemize} 3951 \end{itemize}
3536 Then the method \code{noSuchMethod()} is looked up in $S$ and invoked with argu ment $im$, and the result of this invocation is the result of evaluating $i$. Ho wever, if the implementation found cannot be invoked with a single positional ar gument, the implementation of \code{noSuchMethod()} in class \code{Object} is i nvoked on \THIS{} with argument $im'$, where $im'$ is an instance of \code{Invoc ation} such that : 3952 Then the method \code{noSuchMethod()} is looked up in $S$ and invoked with argu ment $im$, and the result of this invocation is the result of evaluating $i$. Ho wever, if the implementation found cannot be invoked with a single positional ar gument, the implementation of \code{noSuchMethod()} in class \code{Object} is i nvoked on \THIS{} with argument $im'$, where $im'$ is an instance of \code{Invoc ation} such that :
3537 \begin{itemize} 3953 \begin{itemize}
3538 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 3954 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
3539 \item \code{im.memberName} evaluates to \code{noSuchMethod}. 3955 \item \code{im.memberName} evaluates to \code{noSuchMethod}.
3540 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$. 3956 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$.
3541 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 3957 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3542 \end{itemize} 3958 \end{itemize}
3543 3959
3544 and the result of this latter invocation is the result of evaluating $i$. 3960 and the result of this latter invocation is the result of evaluating $i$.
3545 3961
3962 \LMHash{}
3546 It is a static type warning if $S$ does not have a method or getter named $m$. If $i$ is a getter invocation, the static type of $i$ is the declared return typ e of $S.m$, if $S.m$ exists and \DYNAMIC{} otherwise. If $i$ is a closurization , its static type is as described in section \ref{closurization}. 3963 It is a static type warning if $S$ does not have a method or getter named $m$. If $i$ is a getter invocation, the static type of $i$ is the declared return typ e of $S.m$, if $S.m$ exists and \DYNAMIC{} otherwise. If $i$ is a closurization , its static type is as described in section \ref{closurization}.
3547 3964
3548 3965
3549 \subsubsection{Closurization} 3966 \subsubsection{Closurization}
3550 \label{closurization} 3967 \LMLabel{closurization}
3551 3968
3969 \LMHash{}
3552 The {\em closurization of $o.m$} is defined to be equivalent to: 3970 The {\em closurization of $o.m$} is defined to be equivalent to:
3553 3971
3554 \begin{itemize} 3972 \begin{itemize}
3555 3973
3556 \item 3974 \item
3557 \begin{dartCode} 3975 \begin{dartCode}
3558 $(r_1, \ldots, r_n, \{p_1 : d_1, \ldots , p_k : d_k\})$ \{ 3976 $(r_1, \ldots, r_n, \{p_1 : d_1, \ldots , p_k : d_k\})$ \{
3559 \RETURN{} $ u.m(r_1, \ldots, r_n, p_1: p_1, \ldots, p_k: p_k);$ 3977 \RETURN{} $ u.m(r_1, \ldots, r_n, p_1: p_1, \ldots, p_k: p_k);$
3560 \} 3978 \}
3561 \end{dartCode} 3979 \end{dartCode}
(...skipping 29 matching lines...) Expand all
3591 4009
3592 \commentary{Observations: 4010 \commentary{Observations:
3593 \begin{enumerate} 4011 \begin{enumerate}
3594 \item One cannot closurize a getter or a setter. 4012 \item One cannot closurize a getter or a setter.
3595 \item One can tell whether one implemented a property via a method or via field/ getter, which means that one has to plan ahead as to what construct to use, and that choice is reflected in the interface of the class. 4013 \item One can tell whether one implemented a property via a method or via field/ getter, which means that one has to plan ahead as to what construct to use, and that choice is reflected in the interface of the class.
3596 \end{enumerate} 4014 \end{enumerate}
3597 } 4015 }
3598 4016
3599 4017
3600 4018
4019 \LMHash{}
3601 The closurization of $\SUPER{}.m$ with respect to superclass $S$ is defined to b e equivalent to: 4020 The closurization of $\SUPER{}.m$ with respect to superclass $S$ is defined to b e equivalent to:
3602 4021
3603 \begin{itemize} 4022 \begin{itemize}
3604 %\item $(r_1, \ldots, r_n)\{\RETURN{}$ $o.m(r_1, \ldots, r_n);\}$ if $m$ has on ly required parameters $r_1, \ldots r_n$. 4023 %\item $(r_1, \ldots, r_n)\{\RETURN{}$ $o.m(r_1, \ldots, r_n);\}$ if $m$ has on ly required parameters $r_1, \ldots r_n$.
3605 %\item $(r_1, \ldots, r_n, rest)\{return$ $o.m(r_1, \ldots, r_n, rest);\}$ if $ m$ has required parameters $r_1, \ldots r_n$, and a rest parameter $rest$. 4024 %\item $(r_1, \ldots, r_n, rest)\{return$ $o.m(r_1, \ldots, r_n, rest);\}$ if $ m$ has required parameters $r_1, \ldots r_n$, and a rest parameter $rest$.
3606 %\item 4025 %\item
3607 \item 4026 \item
3608 \begin{dartCode} 4027 \begin{dartCode}
3609 $(r_1, \ldots, r_n, \{p_1 : d_1, \ldots , p_k : d_k\})$\{ 4028 $(r_1, \ldots, r_n, \{p_1 : d_1, \ldots , p_k : d_k\})$\{
3610 \RETURN{} \SUPER{}$.m(r_1, \ldots, r_n, p_1: p_1, \ldots, p_k: p_k)$; 4029 \RETURN{} \SUPER{}$.m(r_1, \ldots, r_n, p_1: p_1, \ldots, p_k: p_k)$;
3611 \} 4030 \}
3612 \end{dartCode} 4031 \end{dartCode}
3613 4032
3614 if $m$ has required parameters $r_1, \ldots, r_n$, and named parameters $p_1, \l dots, p_k$ with defaults $d_1, \ldots, d_k$. 4033 if $m$ has required parameters $r_1, \ldots, r_n$, and named parameters $p_1, \l dots, p_k$ with defaults $d_1, \ldots, d_k$.
3615 \item 4034 \item
3616 \begin{dartCode} 4035 \begin{dartCode}
3617 $(r_1, \ldots, r_n, [p_1 = d_1, \ldots , p_k = d_k])$\{ 4036 $(r_1, \ldots, r_n, [p_1 = d_1, \ldots , p_k = d_k])$\{
3618 \RETURN{} \SUPER{}$.m(r_1, \ldots, r_n, p_1, \ldots, p_k)$; 4037 \RETURN{} \SUPER{}$.m(r_1, \ldots, r_n, p_1, \ldots, p_k)$;
3619 \} 4038 \}
3620 \end{dartCode} 4039 \end{dartCode}
3621 4040
3622 if $m$ has required parameters $r_1, \ldots, r_n$, and optional positional param eters $p_1, \ldots, p_k$ with defaults $d_1, \ldots, d_k$. 4041 if $m$ has required parameters $r_1, \ldots, r_n$, and optional positional param eters $p_1, \ldots, p_k$ with defaults $d_1, \ldots, d_k$.
3623 \end{itemize} 4042 \end{itemize}
3624 4043
4044 \LMHash{}
3625 Except that: 4045 Except that:
3626 \begin{enumerate} 4046 \begin{enumerate}
3627 \item iff \code{identical($o_1, o_2$)} then \cd{$o_1.m$ == $o_2.m$}. 4047 \item iff \code{identical($o_1, o_2$)} then \cd{$o_1.m$ == $o_2.m$}.
3628 \item 4048 \item
3629 The static type of the property extraction is the static type of the method $S.m $, if $S.m$ is defined. Otherwise the static type of $\SUPER{}.m$ is \DYNAMIC{} . 4049 The static type of the property extraction is the static type of the method $S.m $, if $S.m$ is defined. Otherwise the static type of $\SUPER{}.m$ is \DYNAMIC{} .
3630 \end{enumerate} 4050 \end{enumerate}
3631 4051
3632 4052
3633 \subsection{ Assignment} 4053 \subsection{ Assignment}
3634 \label{assignment} 4054 \LMLabel{assignment}
3635 4055
4056 \LMHash{}
3636 An assignment changes the value associated with a mutable variable or property. 4057 An assignment changes the value associated with a mutable variable or property.
3637 4058
3638 \begin{grammar} 4059 \begin{grammar}
3639 {\bf assignmentOperator:}`=' ; 4060 {\bf assignmentOperator:}`=' ;
3640 compoundAssignmentOperator 4061 compoundAssignmentOperator
3641 . 4062 .
3642 \end{grammar} 4063 \end{grammar}
3643 4064
4065 \LMHash{}
3644 Evaluation of an assignment $a$ of the form $v$ \code{=} $e$ proceeds as follows : 4066 Evaluation of an assignment $a$ of the form $v$ \code{=} $e$ proceeds as follows :
3645 4067
3646 4068
3647 %If there is neither a local variable declaration with name $v$ nor a setter dec laration with name $v=$ in the lexical scope enclosing $a$, then: 4069 %If there is neither a local variable declaration with name $v$ nor a setter dec laration with name $v=$ in the lexical scope enclosing $a$, then:
3648 %\begin{itemize} 4070 %\begin{itemize}
3649 % \item If $a$ occurs inside a top level or static function (be it function, me thod, getter, or setter) or variable initializer, evaluation of $a$ causes $e$ to be evaluated, after which a \code{NoSuchMethodError} is thrown. 4071 % \item If $a$ occurs inside a top level or static function (be it function, me thod, getter, or setter) or variable initializer, evaluation of $a$ causes $e$ to be evaluated, after which a \code{NoSuchMethodError} is thrown.
3650 % \item Otherwise, the assignment is equivalent to the assignment \code{ \THIS{} .$v$ = $e$}. 4072 % \item Otherwise, the assignment is equivalent to the assignment \code{ \THIS{} .$v$ = $e$}.
3651 % \end{itemize} 4073 % \end{itemize}
3652 4074
3653 %Otherwise, 4075 %Otherwise,
3654 4076
4077 \LMHash{}
3655 Let $d$ be the innermost declaration whose name is $v$ or $v=$, if it exists. 4078 Let $d$ be the innermost declaration whose name is $v$ or $v=$, if it exists.
3656 4079
4080 \LMHash{}
3657 If $d$ is the declaration of a local variable, the expression $e$ is evaluated t o an object $o$. Then, the variable $v$ is bound to $o$ unless $v$ is \FINAL{} o r \CONST{}, in which case a dynamic error occurs. 4081 If $d$ is the declaration of a local variable, the expression $e$ is evaluated t o an object $o$. Then, the variable $v$ is bound to $o$ unless $v$ is \FINAL{} o r \CONST{}, in which case a dynamic error occurs.
3658 If no error occurs, the value of the assignment expression is $o$. 4082 If no error occurs, the value of the assignment expression is $o$.
3659 4083
4084 \LMHash{}
3660 If $d$ is the declaration of a library variable, top level getter or top level s etter, the expression $e$ is evaluated to an object $o$. Then the setter $v=$ is invoked with its formal parameter bound to $o$. The value of the assignment exp ression is $o$. 4085 If $d$ is the declaration of a library variable, top level getter or top level s etter, the expression $e$ is evaluated to an object $o$. Then the setter $v=$ is invoked with its formal parameter bound to $o$. The value of the assignment exp ression is $o$.
3661 4086
4087 \LMHash{}
3662 Otherwise, if $d$ is the declaration of a static variable, static getter or stat ic setter in class $C$, then the assignment is equivalent to the assignment \cod e{$C.v$ = $e$}. 4088 Otherwise, if $d$ is the declaration of a static variable, static getter or stat ic setter in class $C$, then the assignment is equivalent to the assignment \cod e{$C.v$ = $e$}.
3663 4089
4090 \LMHash{}
3664 Otherwise, If $a$ occurs inside a top level or static function (be it function, method, getter, or setter) or variable initializer, evaluation of $a$ causes $ e$ to be evaluated, after which a \code{NoSuchMethodError} is thrown. 4091 Otherwise, If $a$ occurs inside a top level or static function (be it function, method, getter, or setter) or variable initializer, evaluation of $a$ causes $ e$ to be evaluated, after which a \code{NoSuchMethodError} is thrown.
3665 4092
4093 \LMHash{}
3666 Otherwise, the assignment is equivalent to the assignment \code{ \THIS{}.$v$ = $ e$}. 4094 Otherwise, the assignment is equivalent to the assignment \code{ \THIS{}.$v$ = $ e$}.
3667 4095
4096 \LMHash{}
3668 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 (\ref{actualTypeOfAD eclaration}) of $v$. 4097 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 (\ref{actualTypeOfAD eclaration}) of $v$.
3669 4098
4099 \LMHash{}
3670 It is a static type warning if the static type of $e$ may not be assigned to the static type of $v$. The static type of the expression $v$ \code{=} $e$ is the s tatic type of $e$. 4100 It is a static type warning if the static type of $e$ may not be assigned to the static type of $v$. The static type of the expression $v$ \code{=} $e$ is the s tatic type of $e$.
3671 4101
4102 \LMHash{}
3672 Evaluation of an assignment of the form $e_1.v$ \code{=} $e_2$ proceeds as follo ws: 4103 Evaluation of an assignment of the form $e_1.v$ \code{=} $e_2$ proceeds as follo ws:
3673 4104
4105 \LMHash{}
3674 The expression $e_1$ is evaluated to an object $o_1$. Then, the expression $e_2$ is evaluated to an object $o_2$. Then, the setter $v=$ is looked up (\ref{gett erAndSetterLookup}) in $o_1$ with respect to the current library. If $o_1$ is a n instance of \code{Type} but $e_1$ is not a constant type literal, then if $v=$ is a setter that forwards (\ref{functionDeclarations}) to a static setter, sett er lookup fails. Otherwise, the body of $v=$ is executed with its formal parame ter bound to $o_2$ and \THIS{} bound to $o_1$. 4106 The expression $e_1$ is evaluated to an object $o_1$. Then, the expression $e_2$ is evaluated to an object $o_2$. Then, the setter $v=$ is looked up (\ref{gett erAndSetterLookup}) in $o_1$ with respect to the current library. If $o_1$ is a n instance of \code{Type} but $e_1$ is not a constant type literal, then if $v=$ is a setter that forwards (\ref{functionDeclarations}) to a static setter, sett er lookup fails. Otherwise, the body of $v=$ is executed with its formal parame ter bound to $o_2$ and \THIS{} bound to $o_1$.
3675 4107
4108 \LMHash{}
3676 If the setter lookup has failed, then a new instance $im$ of the predefined cla ss \code{Invocation} is created, such that : 4109 If the setter lookup has failed, then a new instance $im$ of the predefined cla ss \code{Invocation} is created, such that :
3677 \begin{itemize} 4110 \begin{itemize}
3678 \item \code{im.isSetter} evaluates to \code{\TRUE{}}. 4111 \item \code{im.isSetter} evaluates to \code{\TRUE{}}.
3679 \item \code{im.memberName} evaluates to \code{'v='}. 4112 \item \code{im.memberName} evaluates to \code{'v='}.
3680 \item \code{im.positionalArguments} evaluates to an immutable list with the same values as \code{[$o_2$]}. 4113 \item \code{im.positionalArguments} evaluates to an immutable list with the same values as \code{[$o_2$]}.
3681 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 4114 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3682 \end{itemize} 4115 \end{itemize}
3683 4116
4117 \LMHash{}
3684 Then the method \code{noSuchMethod()} is looked up in $o_1$ and invoked with ar gument $im$. 4118 Then the method \code{noSuchMethod()} is looked up in $o_1$ and invoked with ar gument $im$.
3685 However, if the implementation found cannot be invoked with a single positional argument, the implementation of \code{noSuchMethod()} in class \code{Object} is invoked on $o_1$ with argument $im'$, where $im'$ is an instance of \code{Invoc ation} such that : 4119 However, if the implementation found cannot be invoked with a single positional argument, the implementation of \code{noSuchMethod()} in class \code{Object} is invoked on $o_1$ with argument $im'$, where $im'$ is an instance of \code{Invoc ation} such that :
3686 \begin{itemize} 4120 \begin{itemize}
3687 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 4121 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
3688 \item \code{im.memberName} evaluates to \code{noSuchMethod}. 4122 \item \code{im.memberName} evaluates to \code{noSuchMethod}.
3689 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$. 4123 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$.
3690 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 4124 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3691 \end{itemize} 4125 \end{itemize}
3692 4126
4127 \LMHash{}
3693 The value of the assignment expression is $o_2$ irrespective of whether setter l ookup has failed or succeeded. 4128 The value of the assignment expression is $o_2$ irrespective of whether setter l ookup has failed or succeeded.
3694 4129
4130 \LMHash{}
3695 In checked mode, it is a dynamic type error if $o_2$ is not \NULL{} and the inte rface of the class of $o_2$ is not a subtype of the actual type of $e_1.v$. 4131 In checked mode, it is a dynamic type error if $o_2$ is not \NULL{} and the inte rface of the class of $o_2$ is not a subtype of the actual type of $e_1.v$.
3696 4132
4133 \LMHash{}
3697 Let $T$ be the static type of $e_1$. It is a static type warning if $T$ does not have an accessible instance setter named $v=$ unless either: 4134 Let $T$ be the static type of $e_1$. It is a static type warning if $T$ does not have an accessible instance setter named $v=$ unless either:
3698 \begin{itemize} 4135 \begin{itemize}
3699 \item $T$ or a superinterface of $T$ is annotated with an annotation denoting a constant identical to the constant \code{@proxy} defined in \code{dart:core}. Or 4136 \item $T$ or a superinterface of $T$ is annotated with an annotation denoting a constant identical to the constant \code{@proxy} defined in \code{dart:core}. Or
3700 \item $T$ is \code{Type}, $e_1$ is a constant type literal and the class corresp onding to $e_1$ has a static setter named $v=$. 4137 \item $T$ is \code{Type}, $e_1$ is a constant type literal and the class corresp onding to $e_1$ has a static setter named $v=$.
3701 \end{itemize} 4138 \end{itemize}
3702 4139
3703 4140
3704 4141
4142 \LMHash{}
3705 It is a static type warning if the static type of $e_2$ may not be assigned to t he static type of the formal parameter of the setter $v=$. The static type of the expression $e_1.v$ \code{=} $e_2$ is the static type of $e_2$. 4143 It is a static type warning if the static type of $e_2$ may not be assigned to t he static type of the formal parameter of the setter $v=$. The static type of the expression $e_1.v$ \code{=} $e_2$ is the static type of $e_2$.
3706 4144
4145 \LMHash{}
3707 Evaluation of an assignment of the form $e_1[e_2]$ \code{=} $e_3$ is equivalent to the evaluation of the expression \code{(a, i, e)\{a.[]=(i, e); \RETURN{} e; \ } ($e_1, e_2, e_3$)}. The static type of the expression $e_1[e_2]$ \code{=} $e_ 3$ is the static type of $e_3$. 4146 Evaluation of an assignment of the form $e_1[e_2]$ \code{=} $e_3$ is equivalent to the evaluation of the expression \code{(a, i, e)\{a.[]=(i, e); \RETURN{} e; \ } ($e_1, e_2, e_3$)}. The static type of the expression $e_1[e_2]$ \code{=} $e_ 3$ is the static type of $e_3$.
3708 4147
3709 % Should we add: It is a dynamic error if $e_1$ evaluates to an constant list o r map. 4148 % Should we add: It is a dynamic error if $e_1$ evaluates to an constant list o r map.
3710 4149
4150 \LMHash{}
3711 It is a static warning if an assignment of the form $v = e$ occurs inside a top level or static function (be it function, method, getter, or setter) or variable initializer and there is neither a local variable declaration with name $v$ no r setter declaration with name $v=$ in the lexical scope enclosing the assignmen t. 4151 It is a static warning if an assignment of the form $v = e$ occurs inside a top level or static function (be it function, method, getter, or setter) or variable initializer and there is neither a local variable declaration with name $v$ no r setter declaration with name $v=$ in the lexical scope enclosing the assignmen t.
3712 4152
4153 \LMHash{}
3713 It is a compile-time error to invoke any of the setters of class \cd{Object} on a prefix object (\ref{imports}) or on a constant type literal that is immediate ly followed by the token `.'. 4154 It is a compile-time error to invoke any of the setters of class \cd{Object} on a prefix object (\ref{imports}) or on a constant type literal that is immediate ly followed by the token `.'.
3714 4155
3715 4156
3716 4157
3717 \subsubsection{Compound Assignment} 4158 \subsubsection{Compound Assignment}
3718 \label{compoundAssignment} 4159 \LMLabel{compoundAssignment}
3719 4160
4161 \LMHash{}
3720 A compound assignment of the form $v$ $op\code{=} e$ is equivalent to $v \code{= } v$ $op$ $e$. A compound assignment of the form $C.v$ $op \code{=} e$ is equiva lent to $C.v \code{=} C.v$ $op$ $e$. A compound assignment of the form $e_1.v$ $ op = e_2$ is equivalent to \code{((x) $=>$ x.v = x.v $op$ $e_2$)($e_1$)} where $ x$ is a variable that is not used in $e_2$. A compound assignment of the form $ e_1[e_2]$ $op\code{=} e_3$ is equivalent to 4162 A compound assignment of the form $v$ $op\code{=} e$ is equivalent to $v \code{= } v$ $op$ $e$. A compound assignment of the form $C.v$ $op \code{=} e$ is equiva lent to $C.v \code{=} C.v$ $op$ $e$. A compound assignment of the form $e_1.v$ $ op = e_2$ is equivalent to \code{((x) $=>$ x.v = x.v $op$ $e_2$)($e_1$)} where $ x$ is a variable that is not used in $e_2$. A compound assignment of the form $ e_1[e_2]$ $op\code{=} e_3$ is equivalent to
3721 \code{((a, i) $=>$ a[i] = a[i] $op$ $e_3$)($e_1, e_2$)} where $a$ and $i$ are a variables that are not used in $e_3$. 4163 \code{((a, i) $=>$ a[i] = a[i] $op$ $e_3$)($e_1, e_2$)} where $a$ and $i$ are a variables that are not used in $e_3$.
3722 4164
3723 4165
3724 \begin{grammar} 4166 \begin{grammar}
3725 {\bf compoundAssignmentOperator:}`*='; 4167 {\bf compoundAssignmentOperator:}`*=';
3726 `/='; 4168 `/=';
3727 `\~{}/='; 4169 `\~{}/=';
3728 `\%='; 4170 `\%=';
3729 `+='; 4171 `+=';
3730 `-='; 4172 `-=';
3731 `{\escapegrammar \lt \lt}='; 4173 `{\escapegrammar \lt \lt}=';
3732 `{\escapegrammar \gt \gt}='; 4174 `{\escapegrammar \gt \gt}=';
3733 `\&='; 4175 `\&=';
3734 `\^{}='; 4176 `\^{}=';
3735 `$|$=' 4177 `$|$='
3736 . 4178 .
3737 \end{grammar} 4179 \end{grammar}
3738 4180
3739 4181
3740 \subsection{ Conditional} 4182 \subsection{ Conditional}
3741 \label{conditional} 4183 \LMLabel{conditional}
3742 4184
4185 \LMHash{}
3743 A {\em conditional expression} evaluates one of two expressions based on a boole an condition. 4186 A {\em conditional expression} evaluates one of two expressions based on a boole an condition.
3744 4187
3745 \begin{grammar} 4188 \begin{grammar}
3746 {\bf conditionalExpression:} 4189 {\bf conditionalExpression:}
3747 logicalOrExpression (`?' expressionWithoutCascade `{\escapegrammar :}' expr essionWithoutCascade)? 4190 logicalOrExpression (`?' expressionWithoutCascade `{\escapegrammar :}' expr essionWithoutCascade)?
3748 . % the first branches could top level expressions, it seems, but certainl y NOT the second 4191 . % the first branches could top level expressions, it seems, but certainl y NOT the second
3749 \end{grammar} 4192 \end{grammar}
3750 4193
4194 \LMHash{}
3751 Evaluation of a conditional expression $c$ of the form $e_1 ? e_2 : e_3$ proceed s as follows: 4195 Evaluation of a conditional expression $c$ of the form $e_1 ? e_2 : e_3$ proceed s as follows:
3752 4196
4197 \LMHash{}
3753 First, $e_1$ is evaluated to an object $o_1$. Then, $o_1$ is subjected to bool ean conversion (\ref{booleanConversion}) producing an object $r$. If $r$ is \TR UE, then the value of $c$ is the result of evaluating the expression $e_2$. Othe rwise the value of $c$ is the result of evaluating the expression $e_3$. 4198 First, $e_1$ is evaluated to an object $o_1$. Then, $o_1$ is subjected to bool ean conversion (\ref{booleanConversion}) producing an object $r$. If $r$ is \TR UE, then the value of $c$ is the result of evaluating the expression $e_2$. Othe rwise the value of $c$ is the result of evaluating the expression $e_3$.
3754 4199
4200 \LMHash{}
3755 If all of the following hold: 4201 If all of the following hold:
3756 \begin{itemize} 4202 \begin{itemize}
3757 \item $e_1$ shows that a variable $v$ has type $T$. 4203 \item $e_1$ shows that a variable $v$ has type $T$.
3758 \item $v$ is not potentially mutated in $e_2$ or within a closure. 4204 \item $v$ is not potentially mutated in $e_2$ or within a closure.
3759 \item If the variable $v$ is accessed by a closure in $e_2$ then the variable $v $ is not potentially mutated anywhere in the scope of $v$. 4205 \item If the variable $v$ is accessed by a closure in $e_2$ then the variable $v $ is not potentially mutated anywhere in the scope of $v$.
3760 \end{itemize} 4206 \end{itemize}
3761 4207
3762 then the type of $v$ is known to be $T$ in $e_2$. 4208 then the type of $v$ is known to be $T$ in $e_2$.
3763 4209
3764 4210
4211 \LMHash{}
3765 It is a static type warning if the static type of $e_1$ may not be assigned to \code{bool}. The static type of $c$ is the least upper bound (\ref{leastUpperBo unds}) of the static type of $e_2$ and the static type of $e_3$. 4212 It is a static type warning if the static type of $e_1$ may not be assigned to \code{bool}. The static type of $c$ is the least upper bound (\ref{leastUpperBo unds}) of the static type of $e_2$ and the static type of $e_3$.
3766 4213
3767 4214
3768 \subsection{ Logical Boolean Expressions} 4215 \subsection{ Logical Boolean Expressions}
3769 \label{logicalBooleanExpressions} 4216 \LMLabel{logicalBooleanExpressions}
3770 4217
4218 \LMHash{}
3771 The logical boolean expressions combine boolean objects using the boolean conjun ction and disjunction operators. 4219 The logical boolean expressions combine boolean objects using the boolean conjun ction and disjunction operators.
3772 4220
3773 \begin{grammar} 4221 \begin{grammar}
3774 {\bf logicalOrExpression:} 4222 {\bf logicalOrExpression:}
3775 logicalAndExpression (`$||$' logicalAndExpression)* 4223 logicalAndExpression (`$||$' logicalAndExpression)*
3776 . 4224 .
3777 4225
3778 4226
3779 {\bf logicalAndExpression:} 4227 {\bf logicalAndExpression:}
3780 equalityExpression (`\&\&' equalityExpression)* 4228 equalityExpression (`\&\&' equalityExpression)*
3781 % bitwiseOrExpression (`\&\&' bitwiseOrExpression)* 4229 % bitwiseOrExpression (`\&\&' bitwiseOrExpression)*
3782 . 4230 .
3783 \end{grammar} 4231 \end{grammar}
3784 4232
4233 \LMHash{}
3785 A {\em logical boolean expression} is either an equality expression (\ref{equali ty}), or an invocation of a logical boolean operator on an expression $e_1$ with argument $e_2$. 4234 A {\em logical boolean expression} is either an equality expression (\ref{equali ty}), or an invocation of a logical boolean operator on an expression $e_1$ with argument $e_2$.
3786 4235
4236 \LMHash{}
3787 Evaluation of a logical boolean expression $b$ of the form $e_1 || e_2$ causes t he evaluation of $e_1$ which is then subjected to boolean conversion, yielding an object $o_1$; if $o_1$ is \TRUE, the result of evaluating $b$ is \TRUE, other wise $e_2$ is evaluated to an object $o_2$, which is then subjected to boolean c onversion (\ref{booleanConversion}) producing an object $r$, which is the value of $b$. 4237 Evaluation of a logical boolean expression $b$ of the form $e_1 || e_2$ causes t he evaluation of $e_1$ which is then subjected to boolean conversion, yielding an object $o_1$; if $o_1$ is \TRUE, the result of evaluating $b$ is \TRUE, other wise $e_2$ is evaluated to an object $o_2$, which is then subjected to boolean c onversion (\ref{booleanConversion}) producing an object $r$, which is the value of $b$.
3788 4238
4239 \LMHash{}
3789 Evaluation of a logical boolean expression $b$ of the form $e_1 \&\& e_2$ causes the evaluation of $e_1$ which is then subjected to boolean conversion, yielding an object $o_1$; if $o_1$ is not \TRUE, the result of evaluating $b$ is \FALSE , otherwise $e_2$ is evaluated to an object $o_2$, which is then subjected to bo olean conversion producing an object $r$, which is the value of $b$. 4240 Evaluation of a logical boolean expression $b$ of the form $e_1 \&\& e_2$ causes the evaluation of $e_1$ which is then subjected to boolean conversion, yielding an object $o_1$; if $o_1$ is not \TRUE, the result of evaluating $b$ is \FALSE , otherwise $e_2$ is evaluated to an object $o_2$, which is then subjected to bo olean conversion producing an object $r$, which is the value of $b$.
3790 4241
4242 \LMHash{}
3791 A logical boolean expression $b$ of the form $e_1 \&\& e_2$ shows that a variabl e $v$ has type 4243 A logical boolean expression $b$ of the form $e_1 \&\& e_2$ shows that a variabl e $v$ has type
3792 $T$ if all of the following conditions hold: 4244 $T$ if all of the following conditions hold:
3793 \begin{itemize} 4245 \begin{itemize}
3794 \item Either $e_1$ shows that $v$ has type $T$ or $e_2$ shows that $v$ has type $T$. 4246 \item Either $e_1$ shows that $v$ has type $T$ or $e_2$ shows that $v$ has type $T$.
3795 \item $v$ is a local variable or formal parameter. 4247 \item $v$ is a local variable or formal parameter.
3796 \item The variable $v$ is not mutated in $e_2$ or within a closure. 4248 \item The variable $v$ is not mutated in $e_2$ or within a closure.
3797 \end{itemize} 4249 \end{itemize}
3798 4250
4251 \LMHash{}
3799 Furthermore, if all of the following hold: 4252 Furthermore, if all of the following hold:
3800 \begin{itemize} 4253 \begin{itemize}
3801 \item $e_1$ shows that $v$ has type $T$. 4254 \item $e_1$ shows that $v$ has type $T$.
3802 \item $v$ is not mutated in either $e_1$, $e_2$ or within a closure. 4255 \item $v$ is not mutated in either $e_1$, $e_2$ or within a closure.
3803 \item If the variable $v$ is accessed by a closure in $e_2$ then the variable $v $ is not potentially mutated anywhere in the scope of $v$. 4256 \item If the variable $v$ is accessed by a closure in $e_2$ then the variable $v $ is not potentially mutated anywhere in the scope of $v$.
3804 \end{itemize} 4257 \end{itemize}
3805 then the type of $v$ is known to be $T$ in $e_2$. 4258 then the type of $v$ is known to be $T$ in $e_2$.
3806 4259
4260 \LMHash{}
3807 It is a static warning if the static type of $e_1$ may not be assigned to \cd{bo ol} or if the static type of $e_2$ may not be assigned to \cd{bool}. The static type of a logical boolean expression is \code{bool}. 4261 It is a static warning if the static type of $e_1$ may not be assigned to \cd{bo ol} or if the static type of $e_2$ may not be assigned to \cd{bool}. The static type of a logical boolean expression is \code{bool}.
3808 4262
3809 4263
3810 \subsection{ Equality} 4264 \subsection{ Equality}
3811 \label{equality} 4265 \LMLabel{equality}
3812 4266
4267 \LMHash{}
3813 Equality expressions test objects for equality. 4268 Equality expressions test objects for equality.
3814 4269
3815 \begin{grammar} 4270 \begin{grammar}
3816 {\bf equalityExpression:}relationalExpression (equalityOperator relationalExpres sion)?; 4271 {\bf equalityExpression:}relationalExpression (equalityOperator relationalExpres sion)?;
3817 \SUPER{} equalityOperator relationalExpression 4272 \SUPER{} equalityOperator relationalExpression
3818 . 4273 .
3819 4274
3820 {\bf equalityOperator:}`=='; 4275 {\bf equalityOperator:}`==';
3821 `!=' 4276 `!='
3822 . 4277 .
3823 \end{grammar} 4278 \end{grammar}
3824 4279
4280 \LMHash{}
3825 An {\em equality expression} is either a relational expression (\ref{relationalE xpressions}), or an invocation of an equality operator on either \SUPER{} or an expression $e_1$, with argument $e_2$. 4281 An {\em equality expression} is either a relational expression (\ref{relationalE xpressions}), or an invocation of an equality operator on either \SUPER{} or an expression $e_1$, with argument $e_2$.
3826 4282
3827 4283
4284 \LMHash{}
3828 Evaluation of an equality expression $ee$ of the form \code{$e_1$ == $e_2$} proc eeds as follows: 4285 Evaluation of an equality expression $ee$ of the form \code{$e_1$ == $e_2$} proc eeds as follows:
3829 \begin{itemize} 4286 \begin{itemize}
3830 \item The expression $e_1$ is evaluated to an object $o_1$. 4287 \item The expression $e_1$ is evaluated to an object $o_1$.
3831 \item The expression $e_2$ is evaluated to an object $o_2$. 4288 \item The expression $e_2$ is evaluated to an object $o_2$.
3832 \item If either $o_1$ or $o_2$ is \NULL{}, then $ee$ evaluates to \code{identica l($o_1$, $o_2$)}. Otherwise, 4289 \item If either $o_1$ or $o_2$ is \NULL{}, then $ee$ evaluates to \code{identica l($o_1$, $o_2$)}. Otherwise,
3833 \item $ee$ is equivalent to the method invocation \code{$o_1$.==($o_2$)}. 4290 \item $ee$ is equivalent to the method invocation \code{$o_1$.==($o_2$)}.
3834 \end{itemize} 4291 \end{itemize}
3835 4292
3836 4293
4294 \LMHash{}
3837 Evaluation of an equality expression $ee$ of the form \code{\SUPER{} == $e$} pro ceeds as follows: 4295 Evaluation of an equality expression $ee$ of the form \code{\SUPER{} == $e$} pro ceeds as follows:
3838 \begin{itemize} 4296 \begin{itemize}
3839 \item The expression $e$ is evaluated to an object $o$. 4297 \item The expression $e$ is evaluated to an object $o$.
3840 \item If either \THIS{} or $o$ is \NULL{}, then $ee$ evaluates to \code{identica l(\THIS{}, $o$)}. Otherwise, 4298 \item If either \THIS{} or $o$ is \NULL{}, then $ee$ evaluates to \code{identica l(\THIS{}, $o$)}. Otherwise,
3841 \item $ee$ is equivalent to the method invocation \code{\SUPER{}.==($o$)}. 4299 \item $ee$ is equivalent to the method invocation \code{\SUPER{}.==($o$)}.
3842 \end{itemize} 4300 \end{itemize}
3843 4301
3844 \commentary{As a result of the above definition, user defined \code{==} methods can assume that their argument is non-null, and avoid the standard boiler-plate prelude: 4302 \commentary{As a result of the above definition, user defined \code{==} methods can assume that their argument is non-null, and avoid the standard boiler-plate prelude:
3845 4303
3846 \code{if (identical(\NULL{}, arg)) return \FALSE{};} 4304 \code{if (identical(\NULL{}, arg)) return \FALSE{};}
3847 4305
3848 Another implication is that there is never a need to use \code{identical()} to t est against \NULL{}, nor should anyone ever worry about whether to write \NULL{} == $e$ or $e$ == \NULL{}. 4306 Another implication is that there is never a need to use \code{identical()} to t est against \NULL{}, nor should anyone ever worry about whether to write \NULL{} == $e$ or $e$ == \NULL{}.
3849 } 4307 }
3850 4308
4309 \LMHash{}
3851 An equality expression of the form \code{$e_1$ != $e_2$} is equivalent to the e xpression \code{!($e_1$ == $e_2$)}. An equality expression of the form \code{\SU PER{} != $e$} is equivalent to the expression \code{!(\SUPER{} == $e$)}. 4310 An equality expression of the form \code{$e_1$ != $e_2$} is equivalent to the e xpression \code{!($e_1$ == $e_2$)}. An equality expression of the form \code{\SU PER{} != $e$} is equivalent to the expression \code{!(\SUPER{} == $e$)}.
3852 4311
3853 4312
3854 4313
3855 %The expression $e_1$ is evaluated to an object $o_1$; then the expression $e_2 $ is evaluated to an object $o_2$. Next, if $o_1$ and $o_2$ are the same object , then $ee$ evaluates to \TRUE{}, otherwise $ee$ evaluates to \FALSE{}. 4314 %The expression $e_1$ is evaluated to an object $o_1$; then the expression $e_2 $ is evaluated to an object $o_2$. Next, if $o_1$ and $o_2$ are the same object , then $ee$ evaluates to \TRUE{}, otherwise $ee$ evaluates to \FALSE{}.
3856 4315
3857 4316
4317 \LMHash{}
3858 The static type of an equality expression is \code{bool}. 4318 The static type of an equality expression is \code{bool}.
3859 4319
3860 4320
3861 \subsection{ Relational Expressions} 4321 \subsection{ Relational Expressions}
3862 \label{relationalExpressions} 4322 \LMLabel{relationalExpressions}
3863 4323
4324 \LMHash{}
3864 Relational expressions invoke the relational operators on objects. 4325 Relational expressions invoke the relational operators on objects.
3865 4326
3866 \begin{grammar} 4327 \begin{grammar}
3867 {\bf relationalExpression:}bitwiseOrExpression (typeTest $|$ typeCast $|$ relat ionalOperator bitwiseOrExpression)?; 4328 {\bf relationalExpression:}bitwiseOrExpression (typeTest $|$ typeCast $|$ relat ionalOperator bitwiseOrExpression)?;
3868 \SUPER{} relationalOperator bitwiseOrExpression 4329 \SUPER{} relationalOperator bitwiseOrExpression
3869 . 4330 .
3870 4331
3871 4332
3872 {\bf relationalOperator:}`{\escapegrammar \gt=}'; 4333 {\bf relationalOperator:}`{\escapegrammar \gt=}';
3873 `{\escapegrammar \gt}'; 4334 `{\escapegrammar \gt}';
3874 `{\escapegrammar \lt}='; 4335 `{\escapegrammar \lt}=';
3875 `{\escapegrammar \lt}' 4336 `{\escapegrammar \lt}'
3876 . 4337 .
3877 \end{grammar} 4338 \end{grammar}
3878 4339
4340 \LMHash{}
3879 A {\em relational expression} is either a bitwise expression (\ref{bitwiseExpres sions}), or an invocation of a relational operator on either \SUPER{} or an expr ession $e_1$, with argument $e_2$. 4341 A {\em relational expression} is either a bitwise expression (\ref{bitwiseExpres sions}), or an invocation of a relational operator on either \SUPER{} or an expr ession $e_1$, with argument $e_2$.
3880 4342
4343 \LMHash{}
3881 A relational expression of the form $e_1$ $op$ $e_2$ is equivalent to the metho d invocation \code{$e_1$.$op$($e_2$)}. A relational expression of the form \SUP ER{} $op$ $e_2$ is equivalent to the method invocation \code{\SUPER{}.$op$($e_2$ )}. 4344 A relational expression of the form $e_1$ $op$ $e_2$ is equivalent to the metho d invocation \code{$e_1$.$op$($e_2$)}. A relational expression of the form \SUP ER{} $op$ $e_2$ is equivalent to the method invocation \code{\SUPER{}.$op$($e_2$ )}.
3882 4345
3883 \subsection{ Bitwise Expressions} 4346 \subsection{ Bitwise Expressions}
3884 \label{bitwiseExpressions} 4347 \LMLabel{bitwiseExpressions}
3885 4348
4349 \LMHash{}
3886 Bitwise expressions invoke the bitwise operators on objects. 4350 Bitwise expressions invoke the bitwise operators on objects.
3887 4351
3888 \begin{grammar} 4352 \begin{grammar}
3889 {\bf bitwiseOrExpression:}bitwiseXorExpression (`$|$' bitwiseXorExpression)*; 4353 {\bf bitwiseOrExpression:}bitwiseXorExpression (`$|$' bitwiseXorExpression)*;
3890 \SUPER{} (`$|$' bitwiseXorExpression)+ 4354 \SUPER{} (`$|$' bitwiseXorExpression)+
3891 . 4355 .
3892 4356
3893 {\bf bitwiseXorExpression:}bitwiseAndExpression (`\^{}' bitwiseAndExpression)*; 4357 {\bf bitwiseXorExpression:}bitwiseAndExpression (`\^{}' bitwiseAndExpression)*;
3894 \SUPER{} (`\^{}' bitwiseAndExpression)+ 4358 \SUPER{} (`\^{}' bitwiseAndExpression)+
3895 . 4359 .
3896 4360
3897 {\bf bitwiseAndExpression:}shiftExpression (`\&' shiftExpression)*; 4361 {\bf bitwiseAndExpression:}shiftExpression (`\&' shiftExpression)*;
3898 \SUPER{} (`\&' shiftExpression)+ 4362 \SUPER{} (`\&' shiftExpression)+
3899 . 4363 .
3900 4364
3901 {\bf bitwiseOperator:}`\&'; 4365 {\bf bitwiseOperator:}`\&';
3902 `\^{}'; 4366 `\^{}';
3903 `$|$' 4367 `$|$'
3904 . 4368 .
3905 \end{grammar} 4369 \end{grammar}
3906 4370
4371 \LMHash{}
3907 A {\em bitwise expression} is either a shift expression (\ref{shift}), or an inv ocation of a bitwise operator on either \SUPER{} or an expression $e_1$, with ar gument $e_2$. 4372 A {\em bitwise expression} is either a shift expression (\ref{shift}), or an inv ocation of a bitwise operator on either \SUPER{} or an expression $e_1$, with ar gument $e_2$.
3908 4373
4374 \LMHash{}
3909 A bitwise expression of the form $e_1$ $op$ $e_2$ is equivalent to the method invocation $e_1.op(e_2)$. 4375 A bitwise expression of the form $e_1$ $op$ $e_2$ is equivalent to the method invocation $e_1.op(e_2)$.
3910 A bitwise expression of the form \code{\SUPER{} $op$ $e_2$} is equivalent to th e method invocation \code{\SUPER{}.op($e_2$)}. 4376 A bitwise expression of the form \code{\SUPER{} $op$ $e_2$} is equivalent to th e method invocation \code{\SUPER{}.op($e_2$)}.
3911 4377
3912 \commentary{ 4378 \commentary{
3913 It should be obvious that the static type rules for these expressions are define d by the equivalence above - ergo, by the type rules for method invocation and t he signatures of the operators on the type $e_1$. The same holds in similar situ ations throughout this specification. 4379 It should be obvious that the static type rules for these expressions are define d by the equivalence above - ergo, by the type rules for method invocation and t he signatures of the operators on the type $e_1$. The same holds in similar situ ations throughout this specification.
3914 } 4380 }
3915 4381
3916 4382
3917 \subsection{ Shift} 4383 \subsection{ Shift}
3918 \label{shift} 4384 \LMLabel{shift}
3919 4385
4386 \LMHash{}
3920 Shift expressions invoke the shift operators on objects. 4387 Shift expressions invoke the shift operators on objects.
3921 4388
3922 \begin{grammar} 4389 \begin{grammar}
3923 {\bf shiftExpression:}additiveExpression (shiftOperator additiveExpression)*; 4390 {\bf shiftExpression:}additiveExpression (shiftOperator additiveExpression)*;
3924 \SUPER{} (shiftOperator additiveExpression)+ 4391 \SUPER{} (shiftOperator additiveExpression)+
3925 . 4392 .
3926 4393
3927 {\bf shiftOperator:}`{\escapegrammar \lt\lt'}; 4394 {\bf shiftOperator:}`{\escapegrammar \lt\lt'};
3928 `{\escapegrammar \gt \gt}' 4395 `{\escapegrammar \gt \gt}'
3929 . 4396 .
3930 \end{grammar} 4397 \end{grammar}
3931 4398
4399 \LMHash{}
3932 A {\em shift expression} is either an additive expression (\ref{additiveExpressi ons}), or an invocation of a shift operator on either \SUPER{} or an expression $e_1$, with argument $e_2$. 4400 A {\em shift expression} is either an additive expression (\ref{additiveExpressi ons}), or an invocation of a shift operator on either \SUPER{} or an expression $e_1$, with argument $e_2$.
3933 4401
4402 \LMHash{}
3934 A shift expression of the form $e_1$ $op$ $e_2$ is equivalent to the method in vocation \code{$e_1$.$op$($e_2$)}. A shift expression of the form \SUPER{} $op$ $e_2$ is equivalent to the method invocation \code{\SUPER{}.$op$($e_2$)}. 4403 A shift expression of the form $e_1$ $op$ $e_2$ is equivalent to the method in vocation \code{$e_1$.$op$($e_2$)}. A shift expression of the form \SUPER{} $op$ $e_2$ is equivalent to the method invocation \code{\SUPER{}.$op$($e_2$)}.
3935 4404
3936 \commentary{ 4405 \commentary{
3937 Note that this definition implies left-to-right evaluation order among shift exp ressions: 4406 Note that this definition implies left-to-right evaluation order among shift exp ressions:
3938 4407
3939 $e_1 << e_2 << e_3$ 4408 $e_1 << e_2 << e_3$
3940 4409
3941 is evaluated as $(e_1 << e_2 ).<< (e_3)$ which is equivalent to $(e_1 << e_2) << e_3$. 4410 is evaluated as $(e_1 << e_2 ).<< (e_3)$ which is equivalent to $(e_1 << e_2) << e_3$.
3942 The same holds for additive and multiplicative expressions. 4411 The same holds for additive and multiplicative expressions.
3943 } 4412 }
3944 4413
3945 \subsection{ Additive Expressions} 4414 \subsection{ Additive Expressions}
3946 \label{additiveExpressions} 4415 \LMLabel{additiveExpressions}
3947 4416
4417 \LMHash{}
3948 Additive expressions invoke the addition operators on objects. 4418 Additive expressions invoke the addition operators on objects.
3949 4419
3950 \begin{grammar} 4420 \begin{grammar}
3951 {\bf additiveExpression:}multiplicativeExpression (additiveOperator multiplicati veExpression)*; 4421 {\bf additiveExpression:}multiplicativeExpression (additiveOperator multiplicati veExpression)*;
3952 \SUPER{} (additiveOperator multiplicativeExpression)+ 4422 \SUPER{} (additiveOperator multiplicativeExpression)+
3953 . 4423 .
3954 4424
3955 {\bf additiveOperator:}`+'; 4425 {\bf additiveOperator:}`+';
3956 `-' 4426 `-'
3957 . 4427 .
3958 \end{grammar} 4428 \end{grammar}
3959 4429
4430 \LMHash{}
3960 An {\em additive expression} is either a multiplicative expression (\ref{multipl icativeExpressions}), or an invocation of an additive operator on either \SUPER{ } or an expression $e_1$, with argument $e_2$. 4431 An {\em additive expression} is either a multiplicative expression (\ref{multipl icativeExpressions}), or an invocation of an additive operator on either \SUPER{ } or an expression $e_1$, with argument $e_2$.
3961 4432
4433 \LMHash{}
3962 An additive expression of the form $e_1$ $op$ $e_2$ is equivalent to the method invocation \code{$e_1$.$op$($e_2$)}. An additive expression of the form \SUPER {} $op$ $e_2$ is equivalent to the method invocation \code{\SUPER{}.$op$($e_2$)} . 4434 An additive expression of the form $e_1$ $op$ $e_2$ is equivalent to the method invocation \code{$e_1$.$op$($e_2$)}. An additive expression of the form \SUPER {} $op$ $e_2$ is equivalent to the method invocation \code{\SUPER{}.$op$($e_2$)} .
3963 4435
4436 \LMHash{}
3964 The static type of an additive expression is usually determined by the signature given in the declaration of the operator used. However, invocations of the oper ators \cd{+} and \cd{-} of class \cd{int} are treated specially by the typechec ker. The static type of an expression $e_1 + e_2$ where $e_1$ has static type \c d{int} is \cd{int} if the static type of $e_2$ is \cd{int}, and \cd{double} if t he static type of $e_2$ is \cd{double}. The static type of an expression $e_1 - e_2$ where $e_1$ has static type \cd{int} is \cd{int} if the static type of $e_2 $ is \cd{int}, and \cd{double} if the static type of $e_2$ is \cd{double}. 4437 The static type of an additive expression is usually determined by the signature given in the declaration of the operator used. However, invocations of the oper ators \cd{+} and \cd{-} of class \cd{int} are treated specially by the typechec ker. The static type of an expression $e_1 + e_2$ where $e_1$ has static type \c d{int} is \cd{int} if the static type of $e_2$ is \cd{int}, and \cd{double} if t he static type of $e_2$ is \cd{double}. The static type of an expression $e_1 - e_2$ where $e_1$ has static type \cd{int} is \cd{int} if the static type of $e_2 $ is \cd{int}, and \cd{double} if the static type of $e_2$ is \cd{double}.
3965 4438
3966 4439
3967 \subsection{ Multiplicative Expressions} 4440 \subsection{ Multiplicative Expressions}
3968 \label{multiplicativeExpressions} 4441 \LMLabel{multiplicativeExpressions}
3969 4442
4443 \LMHash{}
3970 Multiplicative expressions invoke the multiplication operators on objects. 4444 Multiplicative expressions invoke the multiplication operators on objects.
3971 4445
3972 \begin{grammar} 4446 \begin{grammar}
3973 {\bf multiplicativeExpression:}unaryExpression (multiplicativeOperator unaryExpr ession)*; 4447 {\bf multiplicativeExpression:}unaryExpression (multiplicativeOperator unaryExpr ession)*;
3974 \SUPER{} (multiplicativeOperator unaryExpression)+ 4448 \SUPER{} (multiplicativeOperator unaryExpression)+
3975 . 4449 .
3976 4450
3977 {\bf multiplicativeOperator:}`*'; 4451 {\bf multiplicativeOperator:}`*';
3978 `/'; 4452 `/';
3979 `\%'; 4453 `\%';
3980 `\~{}/' 4454 `\~{}/'
3981 . 4455 .
3982 4456
3983 \end{grammar} 4457 \end{grammar}
3984 4458
4459 \LMHash{}
3985 A {\em multiplicative expression} is either a unary expression (\ref{unaryExpre ssions}), or an invocation of a multiplicative operator on either \SUPER{} or an expression $e_1$, with argument $e_2$. 4460 A {\em multiplicative expression} is either a unary expression (\ref{unaryExpre ssions}), or an invocation of a multiplicative operator on either \SUPER{} or an expression $e_1$, with argument $e_2$.
3986 4461
4462 \LMHash{}
3987 A multiplicative expression of the form $e_1$ $op$ $e_2$ is equivalent to the method invocation \code{$e_1$.$op$($e_2$)}. A multiplicative expression of the f orm \SUPER{} $op$ $e_2$ is equivalent to the method invocation \code{\SUPER{}.$ op$($e_2$)}. 4463 A multiplicative expression of the form $e_1$ $op$ $e_2$ is equivalent to the method invocation \code{$e_1$.$op$($e_2$)}. A multiplicative expression of the f orm \SUPER{} $op$ $e_2$ is equivalent to the method invocation \code{\SUPER{}.$ op$($e_2$)}.
3988 4464
4465 \LMHash{}
3989 The static type of an multiplicative expression is usually determined by the sig nature given in the declaration of the operator used. However, invocations of th e operators \cd{*}, \cd{\%} and \cd{\~{}/} of class \cd{int} are treated specia lly by the typechecker. The static type of an expression $e_1 * e_2$ where $e_1$ has static type \cd{int} is \cd{int} if the static type of $e_2$ is \cd{int}, a nd \cd{double} if the static type of $e_2$ is \cd{double}. The static type of an expression $e_1 \% e_2$ where $e_1$ has static type \cd{int} is \cd{int} if the static type of $e_2$ is \cd{int}, and \cd{double} if the static type of $e_2$ i s \cd{double}. The static type of an expression \cd{$e_1$ \~{}/ $e_2$} where $e _1$ has static type \cd{int} is \cd{int} if the static type of $e_2$ is \cd{int} . 4466 The static type of an multiplicative expression is usually determined by the sig nature given in the declaration of the operator used. However, invocations of th e operators \cd{*}, \cd{\%} and \cd{\~{}/} of class \cd{int} are treated specia lly by the typechecker. The static type of an expression $e_1 * e_2$ where $e_1$ has static type \cd{int} is \cd{int} if the static type of $e_2$ is \cd{int}, a nd \cd{double} if the static type of $e_2$ is \cd{double}. The static type of an expression $e_1 \% e_2$ where $e_1$ has static type \cd{int} is \cd{int} if the static type of $e_2$ is \cd{int}, and \cd{double} if the static type of $e_2$ i s \cd{double}. The static type of an expression \cd{$e_1$ \~{}/ $e_2$} where $e _1$ has static type \cd{int} is \cd{int} if the static type of $e_2$ is \cd{int} .
3990 4467
3991 \subsection{ Unary Expressions} 4468 \subsection{ Unary Expressions}
3992 \label{unaryExpressions} 4469 \LMLabel{unaryExpressions}
3993 4470
4471 \LMHash{}
3994 Unary expressions invoke unary operators on objects. 4472 Unary expressions invoke unary operators on objects.
3995 4473
3996 \begin{grammar} 4474 \begin{grammar}
3997 {\bf unaryExpression:}prefixOperator unaryExpression; 4475 {\bf unaryExpression:}prefixOperator unaryExpression;
3998 awaitExpression; 4476 awaitExpression;
3999 postfixExpression; 4477 postfixExpression;
4000 (minusOperator $|$ tildeOperator) \SUPER{}; 4478 (minusOperator $|$ tildeOperator) \SUPER{};
4001 incrementOperator assignableExpression 4479 incrementOperator assignableExpression
4002 . 4480 .
4003 4481
4004 {\bf prefixOperator:}minusOperator; 4482 {\bf prefixOperator:}minusOperator;
4005 negationOperator; 4483 negationOperator;
4006 tildeOperator 4484 tildeOperator
4007 . 4485 .
4008 4486
4009 4487
4010 {\bf minusOperator:}`-'; . 4488 {\bf minusOperator:}`-'; .
4011 4489
4012 4490
4013 {\bf negationOperator:}`!' ; 4491 {\bf negationOperator:}`!' ;
4014 . 4492 .
4015 4493
4016 {\bf tildeOperator:} `\~{}' 4494 {\bf tildeOperator:} `\~{}'
4017 . 4495 .
4018 4496
4019 4497
4020 \end{grammar} 4498 \end{grammar}
4021 4499
4500 \LMHash{}
4022 A {\em unary expression} is either a postfix expression (\ref{postfixExpression s}), an await expression (\ref{awaitExpressions}) or an invocation of a prefix o perator on an expression or an invocation of a unary operator on either \SUPER{} or an expression $e$. 4501 A {\em unary expression} is either a postfix expression (\ref{postfixExpression s}), an await expression (\ref{awaitExpressions}) or an invocation of a prefix o perator on an expression or an invocation of a unary operator on either \SUPER{} or an expression $e$.
4023 4502
4503 \LMHash{}
4024 The expression $!e$ is equivalent to the expression $e?$ $ \FALSE{} :\TRUE{}$. 4504 The expression $!e$ is equivalent to the expression $e?$ $ \FALSE{} :\TRUE{}$.
4025 4505
4506 \LMHash{}
4026 Evaluation of an expression of the form \code{++$e$} is equivalent to \code{$e$ += 1}. Evaluation of an expression of the form \code{-{}-$e$} is equivalent to \code{$e$ -= 1}. 4507 Evaluation of an expression of the form \code{++$e$} is equivalent to \code{$e$ += 1}. Evaluation of an expression of the form \code{-{}-$e$} is equivalent to \code{$e$ -= 1}.
4027 4508
4028 %The expression $-e$ is equivalent to the method invocation \code{$e$.-()}. The expression \code{-\SUPER{}} is equivalent to the method invocation \code{\SUPE R{}.-()}. 4509 %The expression $-e$ is equivalent to the method invocation \code{$e$.-()}. The expression \code{-\SUPER{}} is equivalent to the method invocation \code{\SUPE R{}.-()}.
4029 4510
4511 \LMHash{}
4030 An expression of the form \code{$op$ $e$} is equivalent to the method invocation \code{$e.op()$}. An expression of the form \code{$op$ \SUPER{}} is equivalent t o the method invocation (\ref{superInvocation}) \code{\SUPER{}.$op()$}. 4512 An expression of the form \code{$op$ $e$} is equivalent to the method invocation \code{$e.op()$}. An expression of the form \code{$op$ \SUPER{}} is equivalent t o the method invocation (\ref{superInvocation}) \code{\SUPER{}.$op()$}.
4031 4513
4032 \subsection{ Await Expressions} 4514 \subsection{ Await Expressions}
4033 \label{awaitExpressions} 4515 \LMLabel{awaitExpressions}
4034 4516
4517 \LMHash{}
4035 An {\em await expression} allows code to yield control until an asynchronous ope ration (\ref{functions}) completes. 4518 An {\em await expression} allows code to yield control until an asynchronous ope ration (\ref{functions}) completes.
4036 4519
4037 \begin{grammar} 4520 \begin{grammar}
4038 {\bf awaitExpression:} 4521 {\bf awaitExpression:}
4039 \AWAIT{} unaryExpression 4522 \AWAIT{} unaryExpression
4040 \end{grammar} 4523 \end{grammar}
4041 4524
4525 \LMHash{}
4042 Evaluation of an await expression $a$ of the form \AWAIT{} $e$ proceeds as follo ws: 4526 Evaluation of an await expression $a$ of the form \AWAIT{} $e$ proceeds as follo ws:
4043 First, the expression $e$ is evaluated. Next: 4527 First, the expression $e$ is evaluated. Next:
4044 4528
4529 \LMHash{}
4045 If $e$ raises an exception $x$, then an instance $f$ of class \code{Future} is a llocated and later completed with $x$. Otherwise, if $e$ evaluates to an object $o$ that is not an instance of \code{Future}, then let $f$ be the result of call ing \code{Future.value()} with $o$ as its argument; otherwise let $f$ be the res ult of evaluating $e$. 4530 If $e$ raises an exception $x$, then an instance $f$ of class \code{Future} is a llocated and later completed with $x$. Otherwise, if $e$ evaluates to an object $o$ that is not an instance of \code{Future}, then let $f$ be the result of call ing \code{Future.value()} with $o$ as its argument; otherwise let $f$ be the res ult of evaluating $e$.
4046 4531
4532 \LMHash{}
4047 Next, execution of the function $m$ immediately enclosing $a$ is suspended unti l after $f$ completes. The stream associated with the innermost enclosing asynch ronous for loop (\ref{asynchronousFor-in}), if any, is paused. At some time afte r $f$ is completed, control returns to the current invocation. The stream associ ated with the innermost enclosing asynchronous for loop (\ref{asynchronousFor-i n}), if any, is resumed. If $f$ has completed with an exception $x$, $a$ raises $x$. If $f$ completes with a value $v$, $a$ evaluates to $v$. 4533 Next, execution of the function $m$ immediately enclosing $a$ is suspended unti l after $f$ completes. The stream associated with the innermost enclosing asynch ronous for loop (\ref{asynchronousFor-in}), if any, is paused. At some time afte r $f$ is completed, control returns to the current invocation. The stream associ ated with the innermost enclosing asynchronous for loop (\ref{asynchronousFor-i n}), if any, is resumed. If $f$ has completed with an exception $x$, $a$ raises $x$. If $f$ completes with a value $v$, $a$ evaluates to $v$.
4048 4534
4049 %Otherwise, the value of $a$ is the value of $e$. If evaluation of $e$ raises an exception $x$, $a$ raises $x$. 4535 %Otherwise, the value of $a$ is the value of $e$. If evaluation of $e$ raises an exception $x$, $a$ raises $x$.
4050 4536
4051 \commentary{ 4537 \commentary{
4052 It is a compile-time error if the function immediately enclosing $a$ is not declared asynchronous. However, this error is simply a syntax error, because in the context of a normal function, \AWAIT{} has no special meaning. 4538 It is a compile-time error if the function immediately enclosing $a$ is not declared asynchronous. However, this error is simply a syntax error, because in the context of a normal function, \AWAIT{} has no special meaning.
4053 } 4539 }
4054 4540
4055 \rationale{ 4541 \rationale{
4056 An await expression has no meaning in a synchronous function. If such a function were to suspend waiting for a future, it would no longer be synchronous. 4542 An await expression has no meaning in a synchronous function. If such a function were to suspend waiting for a future, it would no longer be synchronous.
4057 } 4543 }
4058 4544
4059 \commentary{ 4545 \commentary{
4060 It is not a static warning if the type of $e$ is not a subtype of \code{Future}. Tools may choose to give a hint in such cases. 4546 It is not a static warning if the type of $e$ is not a subtype of \code{Future}. Tools may choose to give a hint in such cases.
4061 } 4547 }
4062 4548
4549 \LMHash{}
4063 Let $flatten(T) = flatten(S)$ if $T = Future<S>$, and $T$ otherwise. The static type of $a$ is $flatten(T)$ where $T$ is the static type of $e$. 4550 Let $flatten(T) = flatten(S)$ if $T = Future<S>$, and $T$ otherwise. The static type of $a$ is $flatten(T)$ where $T$ is the static type of $e$.
4064 4551
4065 \rationale{ 4552 \rationale{
4066 We collapse multiple layers of futures into one. If $e$ evaluates to a future $f $, the future will not invoke its \code{then()} callback until f completes to a non-future value, and so the result of an await is never a future, and the resul t of an async function will never have type \code{Future$<X>$} where $X$ itself is an invocation of \code{Future}. 4553 We collapse multiple layers of futures into one. If $e$ evaluates to a future $f $, the future will not invoke its \code{then()} callback until f completes to a non-future value, and so the result of an await is never a future, and the resul t of an async function will never have type \code{Future$<X>$} where $X$ itself is an invocation of \code{Future}.
4067 } 4554 }
4068 4555
4069 4556
4070 4557
4071 4558
4072 \subsection{ Postfix Expressions} 4559 \subsection{ Postfix Expressions}
4073 \label{postfixExpressions} 4560 \LMLabel{postfixExpressions}
4074 4561
4562 \LMHash{}
4075 Postfix expressions invoke the postfix operators on objects. 4563 Postfix expressions invoke the postfix operators on objects.
4076 4564
4077 \begin{grammar} 4565 \begin{grammar}
4078 {\bf postfixExpression:}assignableExpression postfixOperator; 4566 {\bf postfixExpression:}assignableExpression postfixOperator;
4079 primary selector* 4567 primary selector*
4080 . 4568 .
4081 4569
4082 {\bf postfixOperator:} 4570 {\bf postfixOperator:}
4083 incrementOperator 4571 incrementOperator
4084 . 4572 .
4085 4573
4086 {\bf selector:}assignableSelector; 4574 {\bf selector:}assignableSelector;
4087 arguments 4575 arguments
4088 . 4576 .
4089 4577
4090 {\bf incrementOperator:}`++'; 4578 {\bf incrementOperator:}`++';
4091 `-{}-' 4579 `-{}-'
4092 . 4580 .
4093 4581
4094 \end{grammar} 4582 \end{grammar}
4095 4583
4584 \LMHash{}
4096 A {\em postfix expression} is either a primary expression, a function, method o r getter invocation, or an invocation of a postfix operator on an expression $e$ . 4585 A {\em postfix expression} is either a primary expression, a function, method o r getter invocation, or an invocation of a postfix operator on an expression $e$ .
4097 4586
4587 \LMHash{}
4098 A postfix expression of the form \code{$v$++}, where $v$ is an identifier, is eq uivalent to \code{()\{var r = $v$; $v$ = r + 1; return r\}()}. 4588 A postfix expression of the form \code{$v$++}, where $v$ is an identifier, is eq uivalent to \code{()\{var r = $v$; $v$ = r + 1; return r\}()}.
4099 4589
4100 \rationale{The above ensures that if $v$ is a field, the getter gets called exac tly once. Likewise in the cases below. 4590 \rationale{The above ensures that if $v$ is a field, the getter gets called exac tly once. Likewise in the cases below.
4101 } 4591 }
4102 4592
4593 \LMHash{}
4103 A postfix expression of the form \code{$C.v$ ++} is equivalent to 4594 A postfix expression of the form \code{$C.v$ ++} is equivalent to
4104 4595
4105 \code{()\{var r = $C.v$; $C.v$ = r + 1; return r\}()}. 4596 \code{()\{var r = $C.v$; $C.v$ = r + 1; return r\}()}.
4106 4597
4598 \LMHash{}
4107 A postfix expression of the form \code{$e_1.v$++} is equivalent to 4599 A postfix expression of the form \code{$e_1.v$++} is equivalent to
4108 4600
4109 \code{(x)\{var r = x.v; x.v = r + 1; \RETURN{} r\}($e_1$)}. 4601 \code{(x)\{var r = x.v; x.v = r + 1; \RETURN{} r\}($e_1$)}.
4110 4602
4603 \LMHash{}
4111 A postfix expression of the form \code{$e_1[e_2]$++}, is equivalent to 4604 A postfix expression of the form \code{$e_1[e_2]$++}, is equivalent to
4112 4605
4113 \code{(a, i)\{var r = a[i]; a[i] = r + 1; return r\}($e_1$, $e_2$)}. 4606 \code{(a, i)\{var r = a[i]; a[i] = r + 1; return r\}($e_1$, $e_2$)}.
4114 4607
4608 \LMHash{}
4115 A postfix expression of the form \code{$v$-{}-}, where $v$ is an identifier, is equivalent to 4609 A postfix expression of the form \code{$v$-{}-}, where $v$ is an identifier, is equivalent to
4116 4610
4117 \code{()\{var r = $v$; $v$ = r - 1; return r\}()}. 4611 \code{()\{var r = $v$; $v$ = r - 1; return r\}()}.
4118 4612
4613 \LMHash{}
4119 A postfix expression of the form \code{$C.v$-{}-} is equivalent to 4614 A postfix expression of the form \code{$C.v$-{}-} is equivalent to
4120 4615
4121 \code{()\{var r = $C.v$; $C.v$ = r - 1; return r\}()}. 4616 \code{()\{var r = $C.v$; $C.v$ = r - 1; return r\}()}.
4122 4617
4618 \LMHash{}
4123 A postfix expression of the form \code{$e_1.v$-{}-} is equivalent to 4619 A postfix expression of the form \code{$e_1.v$-{}-} is equivalent to
4124 4620
4125 \code{(x)\{var r = x.v; x.v = r - 1; \RETURN{} r\}($e_1$)}. 4621 \code{(x)\{var r = x.v; x.v = r - 1; \RETURN{} r\}($e_1$)}.
4126 4622
4623 \LMHash{}
4127 A postfix expression of the form \code{$e_1[e_2]$-{}-}, is equivalent to 4624 A postfix expression of the form \code{$e_1[e_2]$-{}-}, is equivalent to
4128 4625
4129 \code{(a, i)\{var r = a[i]; a[i] = r - 1; return r\}($e_1$, $e_2$)}. 4626 \code{(a, i)\{var r = a[i]; a[i] = r - 1; return r\}($e_1$, $e_2$)}.
4130 4627
4131 4628
4132 \subsection{ Assignable Expressions} 4629 \subsection{ Assignable Expressions}
4133 \label{assignableExpressions} 4630 \LMLabel{assignableExpressions}
4134 4631
4632 \LMHash{}
4135 Assignable expressions are expressions that can appear on the left hand side of an assignment. 4633 Assignable expressions are expressions that can appear on the left hand side of an assignment.
4136 This section describes how to evaluate these expressions when they do not consti tute the complete left hand side of an assignment. 4634 This section describes how to evaluate these expressions when they do not consti tute the complete left hand side of an assignment.
4137 4635
4138 \rationale{ 4636 \rationale{
4139 Of course, if assignable expressions always appeared {\em as} the left hand side , one would have no need for their value, and the rules for evaluating them woul d be unnecessary. However, assignable expressions can be subexpressions of othe r expressions and therefore must be evaluated. 4637 Of course, if assignable expressions always appeared {\em as} the left hand side , one would have no need for their value, and the rules for evaluating them woul d be unnecessary. However, assignable expressions can be subexpressions of othe r expressions and therefore must be evaluated.
4140 } 4638 }
4141 4639
4142 4640
4143 4641
4144 \begin{grammar} 4642 \begin{grammar}
4145 4643
4146 {\bf assignableExpression:}primary (argument* assignableSelector)+; 4644 {\bf assignableExpression:}primary (argument* assignableSelector)+;
4147 \SUPER{} assignableSelector; 4645 \SUPER{} assignableSelector;
4148 identifier 4646 identifier
4149 . 4647 .
4150 4648
4151 {\bf assignableSelector:}`[' expression `]'; % again, could be top level 4649 {\bf assignableSelector:}`[' expression `]'; % again, could be top level
4152 `{\escapegrammar .}' identifier 4650 `{\escapegrammar .}' identifier
4153 . 4651 .
4154 4652
4155 \end{grammar} 4653 \end{grammar}
4156 4654
4655 \LMHash{}
4157 An {\em assignable expression} is either: 4656 An {\em assignable expression} is either:
4158 \begin{itemize} 4657 \begin{itemize}
4159 \item An identifier. 4658 \item An identifier.
4160 \item An invocation of a getter (\ref{getters}) or list access operator on an ex pression $e$. 4659 \item An invocation of a getter (\ref{getters}) or list access operator on an ex pression $e$.
4161 \item An invocation of a getter or list access operator on \SUPER{}. 4660 \item An invocation of a getter or list access operator on \SUPER{}.
4162 \end{itemize} 4661 \end{itemize}
4163 4662
4164 4663
4664 \LMHash{}
4165 An assignable expression of the form $id$ is evaluated as an identifier expressi on (\ref{identifierReference}). 4665 An assignable expression of the form $id$ is evaluated as an identifier expressi on (\ref{identifierReference}).
4166 4666
4167 %An assignable expression of the form $e.id(a_1, \ldots, a_n)$ is evaluated as a method invocation (\ref{methodInvocation}). 4667 %An assignable expression of the form $e.id(a_1, \ldots, a_n)$ is evaluated as a method invocation (\ref{methodInvocation}).
4168 4668
4669 \LMHash{}
4169 An assignable expression of the form $e.id$ is evaluated as a property extractio n (\ref{propertyExtraction}). 4670 An assignable expression of the form $e.id$ is evaluated as a property extractio n (\ref{propertyExtraction}).
4170 4671
4672 \LMHash{}
4171 An assignable expression of the form \code{$e_1$[$e_2$]} is evaluated as a metho d invocation of the operator method \code{[]} on $e_1$ with argument $e_2$. 4673 An assignable expression of the form \code{$e_1$[$e_2$]} is evaluated as a metho d invocation of the operator method \code{[]} on $e_1$ with argument $e_2$.
4172 4674
4675 \LMHash{}
4173 An assignable expression of the form \code{\SUPER{}.id} is evaluated as a prope rty extraction. 4676 An assignable expression of the form \code{\SUPER{}.id} is evaluated as a prope rty extraction.
4174 4677
4678 \LMHash{}
4175 An assignable expression of the form \code{\SUPER{}[$e_2$]} is equivalent to the method invocation \code{\SUPER{}.[]($e_2$)}. 4679 An assignable expression of the form \code{\SUPER{}[$e_2$]} is equivalent to the method invocation \code{\SUPER{}.[]($e_2$)}.
4176 4680
4177 \subsection{ Identifier Reference} 4681 \subsection{ Identifier Reference}
4178 \label{identifierReference} 4682 \LMLabel{identifierReference}
4179 4683
4684 \LMHash{}
4180 An {\em identifier expression} consists of a single identifier; it provides acce ss to an object via an unqualified name. 4685 An {\em identifier expression} consists of a single identifier; it provides acce ss to an object via an unqualified name.
4181 4686
4182 \begin{grammar} 4687 \begin{grammar}
4183 {\bf identifier:} 4688 {\bf identifier:}
4184 IDENTIFIER 4689 IDENTIFIER
4185 . 4690 .
4186 4691
4187 4692
4188 {\bf IDENTIFIER\_NO\_DOLLAR:} 4693 {\bf IDENTIFIER\_NO\_DOLLAR:}
4189 IDENTIFIER\_START\_NO\_DOLLAR IDENTIFIER\_PART\_NO\_DOLLAR* 4694 IDENTIFIER\_START\_NO\_DOLLAR IDENTIFIER\_PART\_NO\_DOLLAR*
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
4228 DIGIT 4733 DIGIT
4229 . 4734 .
4230 4735
4231 4736
4232 4737
4233 {\bf qualified:} 4738 {\bf qualified:}
4234 identifier (`{\escapegrammar .}' identifier)? 4739 identifier (`{\escapegrammar .}' identifier)?
4235 . 4740 .
4236 \end{grammar} 4741 \end{grammar}
4237 4742
4743 \LMHash{}
4238 A built-in identifier is one of the identifiers produced by the production {\em BUILT\_IN\_IDENTIFIER}. It is a compile-time error if a built-in identifier is u sed as the declared name of a prefix, class, type parameter or type alias. It is a compile-time error to use a built-in identifier other than \DYNAMIC{} as a ty pe annotation or type parameter. 4744 A built-in identifier is one of the identifiers produced by the production {\em BUILT\_IN\_IDENTIFIER}. It is a compile-time error if a built-in identifier is u sed as the declared name of a prefix, class, type parameter or type alias. It is a compile-time error to use a built-in identifier other than \DYNAMIC{} as a ty pe annotation or type parameter.
4239 4745
4240 \rationale{ 4746 \rationale{
4241 Built-in identifiers are identifiers that are used as keywords in Dart, but are not reserved words in Javascript. To minimize incompatibilities when porting Jav ascript code to Dart, we do not make these into reserved words. A built-in ident ifier may not be used to name a class or type. In other words, they are treated as reserved words when used as types. This eliminates many confusing situations without causing compatibility problems. After all, a Javascript program has no type declarations or annotations so no clash can occur. Furthermore, types shou ld begin with an uppercase letter (see the appendix) and so no clash should occu r in any Dart user program anyway. 4747 Built-in identifiers are identifiers that are used as keywords in Dart, but are not reserved words in Javascript. To minimize incompatibilities when porting Jav ascript code to Dart, we do not make these into reserved words. A built-in ident ifier may not be used to name a class or type. In other words, they are treated as reserved words when used as types. This eliminates many confusing situations without causing compatibility problems. After all, a Javascript program has no type declarations or annotations so no clash can occur. Furthermore, types shou ld begin with an uppercase letter (see the appendix) and so no clash should occu r in any Dart user program anyway.
4242 } 4748 }
4243 4749
4750 \LMHash{}
4244 It is a compile-time error if any of the identifiers \ASYNC, \AWAIT{} or \YIELD{ } is used as an identifier in a function body marked with either \ASYNC{}, \ASYN C* or \SYNC*. 4751 It is a compile-time error if any of the identifiers \ASYNC, \AWAIT{} or \YIELD{ } is used as an identifier in a function body marked with either \ASYNC{}, \ASYN C* or \SYNC*.
4245 4752
4246 \rationale{ 4753 \rationale{
4247 For compatibility reasons, new constructs cannot rely upon new reserved words o r even built-in identifiers. However, the constructs above are only usable in co ntexts that require special markers introduced concurrently with these construct s, so no old code could use them. Hence the restriction, which treats these name s as reserved words in a limited context. 4754 For compatibility reasons, new constructs cannot rely upon new reserved words o r even built-in identifiers. However, the constructs above are only usable in co ntexts that require special markers introduced concurrently with these construct s, so no old code could use them. Hence the restriction, which treats these name s as reserved words in a limited context.
4248 } 4755 }
4249 4756
4757 \LMHash{}
4250 Evaluation of an identifier expression $e$ of the form $id$ proceeds as follows: 4758 Evaluation of an identifier expression $e$ of the form $id$ proceeds as follows:
4251 4759
4252 4760
4761 \LMHash{}
4253 Let $d$ be the innermost declaration in the enclosing lexical scope whose name i s $id$ or $id=$. If no such declaration exists in the lexical scope, let $d$ be the declaration of the inherited member named $id$ if it exists. 4762 Let $d$ be the innermost declaration in the enclosing lexical scope whose name i s $id$ or $id=$. If no such declaration exists in the lexical scope, let $d$ be the declaration of the inherited member named $id$ if it exists.
4254 %If no such member exists, let $d$ be the declaration of the static member name $id$ declared in a superclass of the current class, if it exists. 4763 %If no such member exists, let $d$ be the declaration of the static member name $id$ declared in a superclass of the current class, if it exists.
4255 4764
4256 \begin{itemize} 4765 \begin{itemize}
4257 \item if $d$ is a prefix $p$, a compile-time error occurs unless the token immed iately following $d$ is \code{'.'}. 4766 \item if $d$ is a prefix $p$, a compile-time error occurs unless the token immed iately following $d$ is \code{'.'}.
4258 \item If $d$ is a class or type alias $T$, the value of $e$ is an instance of c lass \code{Type} (or a subclass thereof) reifying $T$. 4767 \item If $d$ is a class or type alias $T$, the value of $e$ is an instance of c lass \code{Type} (or a subclass thereof) reifying $T$.
4259 \item If $d$ is a type parameter $T$, then the value of $e$ is the value of the actual type argument corresponding to $T$ that was passed to the generative con structor that created the current binding of \THIS{}. If, however, $e$ occurs in side a static member, a compile-time error occurs. 4768 \item If $d$ is a type parameter $T$, then the value of $e$ is the value of the actual type argument corresponding to $T$ that was passed to the generative con structor that created the current binding of \THIS{}. If, however, $e$ occurs in side a static member, a compile-time error occurs.
4260 4769
4261 %\commentary{ We are assured that \THIS{} is well defined, because if we were in a static member the reference to $T$ is a compile-time error (\ref{generics}.)} 4770 %\commentary{ We are assured that \THIS{} is well defined, because if we were in a static member the reference to $T$ is a compile-time error (\ref{generics}.)}
4262 %\item If $d$ is a library variable then: 4771 %\item If $d$ is a library variable then:
4263 % \begin{itemize} 4772 % \begin{itemize}
4264 % \item If $d$ is of one of the forms \code{\VAR{} $v$ = $e_i$;} , \code{$T$ $v $ = $e_i$;} , \code{\FINAL{} $v$ = $e_i$;} or \code{\FINAL{} $T$ $v$ = $e_i$;} and no value has yet been stored into $v$ then the initializer expression $e_i$ is evaluated. If, during the evaluation of $e_i$, the getter for $v$ is referenc ed, a \code{CyclicInitializationError} is thrown. If the evaluation succeeded yi elding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$ is stored into $v$. The value of $e$ is $r$. 4773 % \item If $d$ is of one of the forms \code{\VAR{} $v$ = $e_i$;} , \code{$T$ $v $ = $e_i$;} , \code{\FINAL{} $v$ = $e_i$;} or \code{\FINAL{} $T$ $v$ = $e_i$;} and no value has yet been stored into $v$ then the initializer expression $e_i$ is evaluated. If, during the evaluation of $e_i$, the getter for $v$ is referenc ed, a \code{CyclicInitializationError} is thrown. If the evaluation succeeded yi elding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$ is stored into $v$. The value of $e$ is $r$.
4265 \item If $d$ is a constant variable of one of the forms \code{\CONST{} $v$ = $e$;} or \code{\CONST{} $T$ $v$ = $e$;} then the value $id$ is the value of the compile-time constant $e$. 4774 \item If $d$ is a constant variable of one of the forms \code{\CONST{} $v$ = $e$;} or \code{\CONST{} $T$ $v$ = $e$;} then the value $id$ is the value of the compile-time constant $e$.
4266 % Otherwise 4775 % Otherwise
4267 % \item $e$ evaluates to the current binding of $id$. 4776 % \item $e$ evaluates to the current binding of $id$.
4268 % \end{itemize} 4777 % \end{itemize}
4269 \item If $d$ is a local variable or formal parameter then $e$ evaluates to the c urrent binding of $id$. 4778 \item If $d$ is a local variable or formal parameter then $e$ evaluates to the c urrent binding of $id$.
4270 %\item If $d$ is a library variable, local variable, or formal parameter, then $ e$ evaluates to the current binding of $id$. \commentary{This case also applies if d is a library or local function declaration, as these are equivalent to func tion-valued variable declarations.} 4779 %\item If $d$ is a library variable, local variable, or formal parameter, then $ e$ evaluates to the current binding of $id$. \commentary{This case also applies if d is a library or local function declaration, as these are equivalent to func tion-valued variable declarations.}
4271 \item If $d$ is a static method, top-level function or local function then $e$ e valuates to the function defined by $d$. 4780 \item If $d$ is a static method, top-level function or local function then $e$ e valuates to the function defined by $d$.
4272 \item If $d$ is the declaration of a static variable, static getter or static se tter declared in class $C$, then $e$ is equivalent to the property extraction (\ ref{propertyExtraction}) $C.id$. 4781 \item If $d$ is the declaration of a static variable, static getter or static se tter declared in class $C$, then $e$ is equivalent to the property extraction (\ ref{propertyExtraction}) $C.id$.
4273 \item If $d$ is the declaration of a library variable, top-level getter or top-l evel setter, then $e$ is equivalent to the top level getter invocation (\ref{top LevelGetterInvocation}) $id$. 4782 \item If $d$ is the declaration of a library variable, top-level getter or top-l evel setter, then $e$ is equivalent to the top level getter invocation (\ref{top LevelGetterInvocation}) $id$.
4274 \item Otherwise, if $e$ occurs inside a top level or static function (be it func tion, method, getter, or setter) or variable initializer, evaluation of $e$ cau ses a \code{NoSuchMethod} to be thrown. 4783 \item Otherwise, if $e$ occurs inside a top level or static function (be it func tion, method, getter, or setter) or variable initializer, evaluation of $e$ cau ses a \code{NoSuchMethod} to be thrown.
4275 \item Otherwise, $e$ is equivalent to the property extraction (\ref{propertyExtr action}) \THIS{}.$id$. 4784 \item Otherwise, $e$ is equivalent to the property extraction (\ref{propertyExtr action}) \THIS{}.$id$.
4276 % This implies that referring to an undefined static getter by simple name is an error, whereas doing so by qualified name is only a warning. Same with assignme nts. Revise? 4785 % This implies that referring to an undefined static getter by simple name is an error, whereas doing so by qualified name is only a warning. Same with assignme nts. Revise?
4277 \end{itemize} 4786 \end{itemize}
4278 4787
4788 \LMHash{}
4279 The static type of $e$ is determined as follows: 4789 The static type of $e$ is determined as follows:
4280 4790
4281 \begin{itemize} 4791 \begin{itemize}
4282 \item If $d$ is a class, type alias or type parameter the static type of $e$ is \code{Type}. 4792 \item If $d$ is a class, type alias or type parameter the static type of $e$ is \code{Type}.
4283 \item If $d$ is a local variable or formal parameter the static type of $e$ is t he type of the variable $id$, unless $id$ is known to have some type $T$, in whi ch case the static type of $e$ is $T$, provided that $T$ is more specific than a ny other type $S$ such that $v$ is known to have type $S$. 4793 \item If $d$ is a local variable or formal parameter the static type of $e$ is t he type of the variable $id$, unless $id$ is known to have some type $T$, in whi ch case the static type of $e$ is $T$, provided that $T$ is more specific than a ny other type $S$ such that $v$ is known to have type $S$.
4284 \item If $d$ is a static method, top-level function or local function the static type of $e$ is the function type defined by $d$. 4794 \item If $d$ is a static method, top-level function or local function the static type of $e$ is the function type defined by $d$.
4285 \item If $d$ is the declaration of a static variable, static getter or static se tter declared in class $C$, the static type of $e$ is the static type of the get ter invocation (\ref{propertyExtraction}) $C.id$. 4795 \item If $d$ is the declaration of a static variable, static getter or static se tter declared in class $C$, the static type of $e$ is the static type of the get ter invocation (\ref{propertyExtraction}) $C.id$.
4286 \item If $d$ is the declaration of a library variable, top-level getter or top-l evel setter, the static type of $e$ is the static type of the top level getter invocation $id$. 4796 \item If $d$ is the declaration of a library variable, top-level getter or top-l evel setter, the static type of $e$ is the static type of the top level getter invocation $id$.
4287 \item Otherwise, if $e$ occurs inside a top level or static function (be it func tion, method, getter, or setter) or variable initializer, the static type of $e $ is \DYNAMIC{}. 4797 \item Otherwise, if $e$ occurs inside a top level or static function (be it func tion, method, getter, or setter) or variable initializer, the static type of $e $ is \DYNAMIC{}.
4288 \item Otherwise, the static type of $e$ is the type of the property extraction ( \ref{propertyExtraction}) \THIS{}.$id$. 4798 \item Otherwise, the static type of $e$ is the type of the property extraction ( \ref{propertyExtraction}) \THIS{}.$id$.
4289 \end{itemize} 4799 \end{itemize}
4290 4800
4291 \commentary{Note that if one declares a setter, we bind to the corresponding ge tter even if it does not exist.} 4801 \commentary{Note that if one declares a setter, we bind to the corresponding ge tter even if it does not exist.}
4292 4802
4293 \rationale{ 4803 \rationale{
4294 This prevents situations where one uses uncorrelated setters and getters. The i ntent is to prevent errors when a getter in a surrounding scope is used acciden tally. 4804 This prevents situations where one uses uncorrelated setters and getters. The i ntent is to prevent errors when a getter in a surrounding scope is used acciden tally.
4295 } 4805 }
4296 4806
4807 \LMHash{}
4297 It is a static warning if an identifier expression $id$ occurs inside a top leve l or static function (be it function, method, getter, or setter) or variable ini tializer and there is no declaration $d$ with name $id$ in the lexical scope enc losing the expression. 4808 It is a static warning if an identifier expression $id$ occurs inside a top leve l or static function (be it function, method, getter, or setter) or variable ini tializer and there is no declaration $d$ with name $id$ in the lexical scope enc losing the expression.
4298 4809
4299 \subsection{ Type Test} 4810 \subsection{ Type Test}
4300 \label{typeTest} 4811 \LMLabel{typeTest}
4301 4812
4813 \LMHash{}
4302 The {\em is-expression} tests if an object is a member of a type. 4814 The {\em is-expression} tests if an object is a member of a type.
4303 4815
4304 \begin{grammar} 4816 \begin{grammar}
4305 {\bf typeTest:} 4817 {\bf typeTest:}
4306 isOperator type 4818 isOperator type
4307 . 4819 .
4308 4820
4309 4821
4310 {\bf isOperator:} 4822 {\bf isOperator:}
4311 \IS{} `!'? 4823 \IS{} `!'?
4312 . 4824 .
4313 \end{grammar} 4825 \end{grammar}
4314 4826
4827 \LMHash{}
4315 Evaluation of the is-expression \code{$e$ \IS{} $T$} proceeds as follows: 4828 Evaluation of the is-expression \code{$e$ \IS{} $T$} proceeds as follows:
4316 4829
4830 \LMHash{}
4317 The expression $e$ is evaluated to a value $v$. Then, if $T$ is a malformed or d eferred type (\ref{staticTypes}), a dynamic error occurs. Otherwise, if the inte rface of the class of $v$ is a subtype of $T$, the is-expression evaluates to \T RUE. Otherwise it evaluates to \FALSE. 4831 The expression $e$ is evaluated to a value $v$. Then, if $T$ is a malformed or d eferred type (\ref{staticTypes}), a dynamic error occurs. Otherwise, if the inte rface of the class of $v$ is a subtype of $T$, the is-expression evaluates to \T RUE. Otherwise it evaluates to \FALSE.
4318 4832
4319 \commentary{It follows that \code{$e$ \IS{} Object} is always true. This makes s ense in a language where everything is an object. 4833 \commentary{It follows that \code{$e$ \IS{} Object} is always true. This makes s ense in a language where everything is an object.
4320 4834
4321 Also note that \code{\NULL{} \IS{} $T$} is false unless $T = \code{Object}$, $T = \code{\DYNAMIC{}}$ or $T = \code{Null}$. The former two are useless, as is an ything of the form \code{$e$ \IS{} Object} or \code{$e$ \IS{} \DYNAMIC{}}. User s should test for a null value directly rather than via type tests. 4835 Also note that \code{\NULL{} \IS{} $T$} is false unless $T = \code{Object}$, $T = \code{\DYNAMIC{}}$ or $T = \code{Null}$. The former two are useless, as is an ything of the form \code{$e$ \IS{} Object} or \code{$e$ \IS{} \DYNAMIC{}}. User s should test for a null value directly rather than via type tests.
4322 } 4836 }
4323 4837
4838 \LMHash{}
4324 The is-expression \code{$e$ \IS{}! $T$} is equivalent to \code{!($e$ \IS{} $T$)} . 4839 The is-expression \code{$e$ \IS{}! $T$} is equivalent to \code{!($e$ \IS{} $T$)} .
4325 4840
4326 % Add flow dependent types 4841 % Add flow dependent types
4327 4842
4328 4843
4844 \LMHash{}
4329 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{}$. 4845 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{}$.
4330 4846
4331 \rationale{ 4847 \rationale{
4332 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. 4848 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.
4333 4849
4334 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. 4850 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.
4335 4851
4336 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). 4852 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).
4337 4853
4338 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$. 4854 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$.
4339 } 4855 }
4340 4856
4857 \LMHash{}
4341 The static type of an is-expression is \code{bool}. 4858 The static type of an is-expression is \code{bool}.
4342 4859
4343 4860
4344 \subsection{ Type Cast} 4861 \subsection{ Type Cast}
4345 \label{typeCast} 4862 \LMLabel{typeCast}
4346 4863
4864 \LMHash{}
4347 The {\em cast expression} ensures that an object is a member of a type. 4865 The {\em cast expression} ensures that an object is a member of a type.
4348 4866
4349 \begin{grammar} 4867 \begin{grammar}
4350 {\bf typeCast:} 4868 {\bf typeCast:}
4351 asOperator type 4869 asOperator type
4352 . 4870 .
4353 4871
4354 4872
4355 {\bf asOperator:} 4873 {\bf asOperator:}
4356 \AS{} 4874 \AS{}
4357 . 4875 .
4358 \end{grammar} 4876 \end{grammar}
4359 4877
4878 \LMHash{}
4360 Evaluation of the cast expression \code{$e$ \AS{} $T$} proceeds as follows: 4879 Evaluation of the cast expression \code{$e$ \AS{} $T$} proceeds as follows:
4361 4880
4881 \LMHash{}
4362 The expression $e$ is evaluated to a value $v$. Then, if $T$ is a malformed or d eferred type (\ref{staticTypes}), a dynamic error occurs. Otherwise, if the inte rface of the class of $v$ is a subtype of $T$, the cast expression evaluates to $v$. Otherwise, if $v$ is \NULL{}, the cast expression evaluates to $v$. 4882 The expression $e$ is evaluated to a value $v$. Then, if $T$ is a malformed or d eferred type (\ref{staticTypes}), a dynamic error occurs. Otherwise, if the inte rface of the class of $v$ is a subtype of $T$, the cast expression evaluates to $v$. Otherwise, if $v$ is \NULL{}, the cast expression evaluates to $v$.
4363 In all other cases, a \code{CastError} is thrown. 4883 In all other cases, a \code{CastError} is thrown.
4364 4884
4885 \LMHash{}
4365 The static type of a cast expression \code{$e$ \AS{} $T$} is $T$. 4886 The static type of a cast expression \code{$e$ \AS{} $T$} is $T$.
4366 4887
4367 4888
4368 \section{Statements} 4889 \section{Statements}
4369 \label{statements} 4890 \LMLabel{statements}
4370 4891
4371 \begin{grammar} 4892 \begin{grammar}
4372 {\bf statements:} 4893 {\bf statements:}
4373 statement* 4894 statement*
4374 . 4895 .
4375 4896
4376 4897
4377 {\bf statement:} 4898 {\bf statement:}
4378 label* nonLabelledStatement 4899 label* nonLabelledStatement
4379 . 4900 .
(...skipping 12 matching lines...) Expand all
4392 returnStatement; 4913 returnStatement;
4393 yieldStatement; 4914 yieldStatement;
4394 yieldEachStatement; 4915 yieldEachStatement;
4395 expressionStatement; 4916 expressionStatement;
4396 assertStatement; 4917 assertStatement;
4397 localFunctionDeclaration 4918 localFunctionDeclaration
4398 . 4919 .
4399 \end{grammar} 4920 \end{grammar}
4400 4921
4401 \subsection{Blocks} 4922 \subsection{Blocks}
4402 \label{blocks} 4923 \LMLabel{blocks}
4403 4924
4925 \LMHash{}
4404 A {\em block statement} supports sequencing of code. 4926 A {\em block statement} supports sequencing of code.
4405 4927
4928 \LMHash{}
4406 Execution of a block statement $\{s_1, \ldots, s_n\}$ proceeds as follows: 4929 Execution of a block statement $\{s_1, \ldots, s_n\}$ proceeds as follows:
4407 4930
4931 \LMHash{}
4408 For $i \in 1 .. n, s_i$ is executed. 4932 For $i \in 1 .. n, s_i$ is executed.
4409 4933
4934 \LMHash{}
4410 A block statement introduces a new scope, which is nested in the lexically enclo sing scope in which the block statement appears. 4935 A block statement introduces a new scope, which is nested in the lexically enclo sing scope in which the block statement appears.
4411 4936
4412 4937
4413 4938
4414 \subsection{Expression Statements} 4939 \subsection{Expression Statements}
4415 \label{expressionStatements} 4940 \LMLabel{expressionStatements}
4416 4941
4942 \LMHash{}
4417 An {\em expression statement} consists of an expression other than a non-constan t map literal (\ref{maps}) that has no explicit type arguments. 4943 An {\em expression statement} consists of an expression other than a non-constan t map literal (\ref{maps}) that has no explicit type arguments.
4418 4944
4419 \rationale{ 4945 \rationale{
4420 The restriction on maps is designed to resolve an ambiguity in the grammar, whe n a statement begins with \{. 4946 The restriction on maps is designed to resolve an ambiguity in the grammar, whe n a statement begins with \{.
4421 } 4947 }
4422 4948
4423 \begin{grammar} 4949 \begin{grammar}
4424 {\bf expressionStatement:} 4950 {\bf expressionStatement:}
4425 expression? `{\escapegrammar ;}' 4951 expression? `{\escapegrammar ;}'
4426 . 4952 .
4427 \end{grammar} 4953 \end{grammar}
4428 4954
4955 \LMHash{}
4429 Execution of an expression statement \code{$e$;} proceeds by evaluating $e$. 4956 Execution of an expression statement \code{$e$;} proceeds by evaluating $e$.
4430 4957
4958 \LMHash{}
4431 It is a compile-time error if a non-constant map literal that has no explicit ty pe arguments appears in a place where a statement is expected. 4959 It is a compile-time error if a non-constant map literal that has no explicit ty pe arguments appears in a place where a statement is expected.
4432 4960
4433 \subsection{Local Variable Declaration} 4961 \subsection{Local Variable Declaration}
4434 \label{localVariableDeclaration} 4962 \LMLabel{localVariableDeclaration}
4435 4963
4436 4964
4965 \LMHash{}
4437 A {\em variable declaration statement }declares a new local variable. 4966 A {\em variable declaration statement }declares a new local variable.
4438 4967
4439 \begin{grammar} 4968 \begin{grammar}
4440 {\bf localVariableDeclaration:} 4969 {\bf localVariableDeclaration:}
4441 initializedVariableDeclaration {\escapegrammar';'} 4970 initializedVariableDeclaration {\escapegrammar';'}
4442 . 4971 .
4443 \end{grammar} 4972 \end{grammar}
4444 4973
4974 \LMHash{}
4445 Executing a variable declaration statement of one of the forms \VAR{} $v = e;$ , $T$ $v = e; $, \CONST{} $v = e;$, \CONST{} $T$ $v = e;$, \FINAL{} $v = e;$ o r \FINAL{} $T$ $v = e;$ proceeds as follows: 4975 Executing a variable declaration statement of one of the forms \VAR{} $v = e;$ , $T$ $v = e; $, \CONST{} $v = e;$, \CONST{} $T$ $v = e;$, \FINAL{} $v = e;$ o r \FINAL{} $T$ $v = e;$ proceeds as follows:
4446 4976
4977 \LMHash{}
4447 The expression $e$ is evaluated to an object $o$. Then, the variable $v$ is set to $o$. 4978 The expression $e$ is evaluated to an object $o$. Then, the variable $v$ is set to $o$.
4448 4979
4980 \LMHash{}
4449 A variable declaration statement of the form \VAR{} $v;$ is equivalent to \VAR{ } $v = \NULL{};$. A variable declaration statement of the form $T$ $v;$ is equiv alent to $T$ $v = \NULL{};$. 4981 A variable declaration statement of the form \VAR{} $v;$ is equivalent to \VAR{ } $v = \NULL{};$. A variable declaration statement of the form $T$ $v;$ is equiv alent to $T$ $v = \NULL{};$.
4450 4982
4451 \commentary{ 4983 \commentary{
4452 This holds regardless of the type $T$. For example, \code{int i;} does not cause \code{i} to be initialized to zero. Instead, \code{i} is initialized to \NULL{} , just as if we had written \VAR{} \code{i;} or \code{Object i;} or \code{Collec tion$<$String$>$ i;}. 4984 This holds regardless of the type $T$. For example, \code{int i;} does not cause \code{i} to be initialized to zero. Instead, \code{i} is initialized to \NULL{} , just as if we had written \VAR{} \code{i;} or \code{Object i;} or \code{Collec tion$<$String$>$ i;}.
4453 } 4985 }
4454 4986
4455 \rationale{ 4987 \rationale{
4456 To do otherwise would undermine the optionally typed nature of Dart, causing typ e annotations to modify program behavior. 4988 To do otherwise would undermine the optionally typed nature of Dart, causing typ e annotations to modify program behavior.
4457 } 4989 }
4458 4990
4459 %A variable declaration statement of one of the forms $T$ $v;$, $T$ $v = e;$, \C ONST{} $T$ $v = e;$, or \FINAL{} $T$ $v = e;$ causes a new getter named $v$ wit h static return type $T$ to be added to the innermost enclosing scope at the poi nt following the variable declaration statement. The result of executing this ge tter is the value stored in $v$. 4991 %A variable declaration statement of one of the forms $T$ $v;$, $T$ $v = e;$, \C ONST{} $T$ $v = e;$, or \FINAL{} $T$ $v = e;$ causes a new getter named $v$ wit h static return type $T$ to be added to the innermost enclosing scope at the poi nt following the variable declaration statement. The result of executing this ge tter is the value stored in $v$.
4460 4992
4461 %A variable declaration statement \VAR{} $v;$, \VAR{} $v = e;$, \CONST{} $v = e ;$ or \FINAL{} $v = e;$ causes a new getter named $v$ with static return type \DYNAMIC{} to be added to the innermost enclosing scope at the point following the variable declaration statement. The result of executing this getter is the value stored in $v$. 4993 %A variable declaration statement \VAR{} $v;$, \VAR{} $v = e;$, \CONST{} $v = e ;$ or \FINAL{} $v = e;$ causes a new getter named $v$ with static return type \DYNAMIC{} to be added to the innermost enclosing scope at the point following the variable declaration statement. The result of executing this getter is the value stored in $v$.
4462 4994
4463 %A variable declaration statement of one of the forms $T$ $v;$, or $T$ $v = e;$ causes a new setter named $v=$ with argument type $T$ to be added to the innermo st enclosing scope at the point following the variable declaration statement. Th e effect of executing this setter is to store its argument in $v$. 4995 %A variable declaration statement of one of the forms $T$ $v;$, or $T$ $v = e;$ causes a new setter named $v=$ with argument type $T$ to be added to the innermo st enclosing scope at the point following the variable declaration statement. Th e effect of executing this setter is to store its argument in $v$.
4464 4996
4465 %A variable declaration statement \VAR{} $v;$, \VAR{} $v = e;$, \CONST{} $v = e ;$ or \FINAL{} $v = e;$ causes a new setter named $v=$ with argument type \D YNAMIC{} to be added to the innermost enclosing scope at the point following the variable declaration statement. The effect of executing this setter is to stor e its argument in $v$. 4997 %A variable declaration statement \VAR{} $v;$, \VAR{} $v = e;$, \CONST{} $v = e ;$ or \FINAL{} $v = e;$ causes a new setter named $v=$ with argument type \D YNAMIC{} to be added to the innermost enclosing scope at the point following the variable declaration statement. The effect of executing this setter is to stor e its argument in $v$.
4466 4998
4467 %\rationale{ 4999 %\rationale{
4468 %The use of getters and setters here is a device to help make the specification more uniform. Introducing getters and setters for local variables has no perfor mance consequences, since they can never be overridden, and so can always be opt imized away. It is not possible to declare a local getter or setter explicitly, since there is little reason to ever do so. 5000 %The use of getters and setters here is a device to help make the specification more uniform. Introducing getters and setters for local variables has no perfor mance consequences, since they can never be overridden, and so can always be opt imized away. It is not possible to declare a local getter or setter explicitly, since there is little reason to ever do so.
4469 %} 5001 %}
4470 5002
4471 5003
4472 \subsection{Local Function Declaration} 5004 \subsection{Local Function Declaration}
5005 \LMLabel{localFunctionDeclaration}
4473 5006
4474 \label{localFunctionDeclaration} 5007 \LMHash{}
4475
4476 A function declaration statement declares a new local function (\ref{functionDec larations}). 5008 A function declaration statement declares a new local function (\ref{functionDec larations}).
4477 5009
4478 \begin{grammar} 5010 \begin{grammar}
4479 {\bf localFunctionDeclaration:} 5011 {\bf localFunctionDeclaration:}
4480 functionSignature functionBody 5012 functionSignature functionBody
4481 . 5013 .
4482 \end{grammar} 5014 \end{grammar}
4483 5015
5016 \LMHash{}
4484 A function declaration statement of one of the forms $id$ $signature$ $\{ statem ents \}$ or $T$ $id$ $signature$ $\{ statements \}$ causes a new function named $id$ to be added to the innermost enclosing scope. It is a compile-time error to reference a local function before its declaration. 5017 A function declaration statement of one of the forms $id$ $signature$ $\{ statem ents \}$ or $T$ $id$ $signature$ $\{ statements \}$ causes a new function named $id$ to be added to the innermost enclosing scope. It is a compile-time error to reference a local function before its declaration.
4485 5018
4486 5019
4487 \commentary{ This implies that local functions can be directly recursive, but no t mutually recursive. Consider these examples: 5020 \commentary{ This implies that local functions can be directly recursive, but no t mutually recursive. Consider these examples:
4488 } 5021 }
4489 5022
4490 \begin{dartCode} 5023 \begin{dartCode}
4491 f(x) =$>$ x++; // a top level function 5024 f(x) =$>$ x++; // a top level function
4492 top() \{ // another top level function 5025 top() \{ // another top level function
4493 f(3); // illegal 5026 f(3); // illegal
(...skipping 23 matching lines...) Expand all
4517 \} 5050 \}
4518 \end{dartCode} 5051 \end{dartCode}
4519 5052
4520 \rationale{ 5053 \rationale{
4521 The rules for local functions differ slightly from those for local variables in that a function can be accessed within its declaration but a variable can only be accessed after its declaration. This is because recursive functions are usefu l whereas recursively defined variables are almost always errors. It therefore makes sense to harmonize the rules for local functions with those for functions in general rather than with the rules for local variables. 5054 The rules for local functions differ slightly from those for local variables in that a function can be accessed within its declaration but a variable can only be accessed after its declaration. This is because recursive functions are usefu l whereas recursively defined variables are almost always errors. It therefore makes sense to harmonize the rules for local functions with those for functions in general rather than with the rules for local variables.
4522 } 5055 }
4523 5056
4524 % elaborate on function identity and equality, runtime type. Likewsie in functio n expressions (closures) and declarations 5057 % elaborate on function identity and equality, runtime type. Likewsie in functio n expressions (closures) and declarations
4525 5058
4526 \subsection{If} 5059 \subsection{If}
4527 \label{if} 5060 \LMLabel{if}
4528 5061
5062 \LMHash{}
4529 The {\em if statement} allows for conditional execution of statements. 5063 The {\em if statement} allows for conditional execution of statements.
4530 5064
4531 \begin{grammar} 5065 \begin{grammar}
4532 {\bf ifStatement:} 5066 {\bf ifStatement:}
4533 \IF{} `(' expression `)' statement ( \ELSE{} statement)? % we could allow top level expression 5067 \IF{} `(' expression `)' statement ( \ELSE{} statement)? % we could allow top level expression
4534 . 5068 .
4535 \end{grammar} 5069 \end{grammar}
4536 5070
4537 Execution of an if statement of the form \code {\IF{} (}$b$\code{)}$s_1$ \code{ \ELSE{} } $s_2$ proceeds as follows: 5071 Execution of an if statement of the form \code {\IF{} (}$b$\code{)}$s_1$ \code{ \ELSE{} } $s_2$ proceeds as follows:
4538 5072
5073 \LMHash{}
4539 First, the expression $b$ is evaluated to an object $o$. Then, $o$ is subjecte d to boolean conversion (\ref{booleanConversion}), producing an object $r$. If $ r$ is \TRUE{}, then the statement $\{s_1\}$ is executed, otherwise statement $\{ s_2\}$ is executed. 5074 First, the expression $b$ is evaluated to an object $o$. Then, $o$ is subjecte d to boolean conversion (\ref{booleanConversion}), producing an object $r$. If $ r$ is \TRUE{}, then the statement $\{s_1\}$ is executed, otherwise statement $\{ s_2\}$ is executed.
4540 5075
4541 5076
4542 \commentary { 5077 \commentary {
4543 Put another way, \code {\IF{} (}$b$\code{)}$s_1$ \code{\ELSE{} } $s_2$ is equiv alent to 5078 Put another way, \code {\IF{} (}$b$\code{)}$s_1$ \code{\ELSE{} } $s_2$ is equiv alent to
4544 \code {\IF{} (}$b$\code{)}$\{s_1\}$ \code{\ELSE{} } $\{s_2\}$ 5079 \code {\IF{} (}$b$\code{)}$\{s_1\}$ \code{\ELSE{} } $\{s_2\}$
4545 } 5080 }
4546 5081
4547 \rationale { 5082 \rationale {
4548 The reason for this equivalence is to catch errors such as 5083 The reason for this equivalence is to catch errors such as
4549 } 5084 }
4550 \begin{dartCode} 5085 \begin{dartCode}
4551 \VOID{} main() \{ 5086 \VOID{} main() \{
4552 \IF{} (somePredicate) 5087 \IF{} (somePredicate)
4553 \VAR{} v = 2; 5088 \VAR{} v = 2;
4554 print(v); 5089 print(v);
4555 \} 5090 \}
4556 \end{dartCode} 5091 \end{dartCode}
4557 5092
4558 \rationale { 5093 \rationale {
4559 Under reasonable scope rules such code is problematic. If we assume that \code{ v} is declared in the scope of the method \code{main()}, then when \code{somePre dicate} is false, \code{v} will be uninitialized when accessed. The cleanest ap proach would be to require a block following the test, rather than an arbitrary statement. However, this goes against long standing custom, undermining Dart's g oal of familiarity. Instead, we choose to insert a block, introducing a scope, around the statement following the predicate (and similarly for \ELSE{} and loo ps). This will cause both a warning and a runtime error in the case above. Of c ourse, if there is a declaration of \code{v} in the surrounding scope, programme rs might still be surprised. We expect tools to highlight cases of shadowing to help avoid such situations. 5094 Under reasonable scope rules such code is problematic. If we assume that \code{ v} is declared in the scope of the method \code{main()}, then when \code{somePre dicate} is false, \code{v} will be uninitialized when accessed. The cleanest ap proach would be to require a block following the test, rather than an arbitrary statement. However, this goes against long standing custom, undermining Dart's g oal of familiarity. Instead, we choose to insert a block, introducing a scope, around the statement following the predicate (and similarly for \ELSE{} and loo ps). This will cause both a warning and a runtime error in the case above. Of c ourse, if there is a declaration of \code{v} in the surrounding scope, programme rs might still be surprised. We expect tools to highlight cases of shadowing to help avoid such situations.
4560 } 5095 }
4561 5096
5097 \LMHash{}
4562 It is a static type warning if the type of the expression $b$ may not be assig ned to \code{bool}. 5098 It is a static type warning if the type of the expression $b$ may not be assig ned to \code{bool}.
4563 5099
5100 \LMHash{}
4564 If: 5101 If:
4565 \begin{itemize} 5102 \begin{itemize}
4566 \item $b$ shows that a variable $v$ has type $T$. 5103 \item $b$ shows that a variable $v$ has type $T$.
4567 \item $v$ is not potentially mutated in $s_1$ or within a closure. 5104 \item $v$ is not potentially mutated in $s_1$ or within a closure.
4568 \item If the variable $v$ is accessed by a closure in $s_1$ then the variable $v $ is not potentially mutated anywhere in the scope of $v$. 5105 \item If the variable $v$ is accessed by a closure in $s_1$ then the variable $v $ is not potentially mutated anywhere in the scope of $v$.
4569 \end{itemize} 5106 \end{itemize}
4570 then the type of $v$ is known to be $T$ in $s_1$. 5107 then the type of $v$ is known to be $T$ in $s_1$.
4571 5108
5109 \LMHash{}
4572 An if statement of the form \code {\IF{} (}$b$\code{)}$s_1$ is equivalent to t he if statement 5110 An if statement of the form \code {\IF{} (}$b$\code{)}$s_1$ is equivalent to t he if statement
4573 5111
4574 \code {\IF{} (}$b$\code{)}$s_1$ \code{\ELSE{} \{\}}. 5112 \code {\IF{} (}$b$\code{)}$s_1$ \code{\ELSE{} \{\}}.
4575 5113
4576 5114
4577 5115
4578 \subsection{For} 5116 \subsection{For}
4579 \label{for} 5117 \LMLabel{for}
4580 5118
5119 \LMHash{}
4581 The {\em for statement} supports iteration. 5120 The {\em for statement} supports iteration.
4582 5121
4583 \begin{grammar} 5122 \begin{grammar}
4584 {\bf forStatement:} 5123 {\bf forStatement:}
4585 \AWAIT? \FOR{} `(' forLoopParts `)' statement 5124 \AWAIT? \FOR{} `(' forLoopParts `)' statement
4586 . 5125 .
4587 5126
4588 {\bf forLoopParts:}forInitializerStatement expression? `{\escapegrammar ;}' expr essionList?; 5127 {\bf forLoopParts:}forInitializerStatement expression? `{\escapegrammar ;}' expr essionList?;
4589 declaredIdentifier \IN{} expression; 5128 declaredIdentifier \IN{} expression;
4590 identifier \IN{} expression 5129 identifier \IN{} expression
4591 . 5130 .
4592 5131
4593 {\bf forInitializerStatement:}localVariableDeclaration `{\escapegrammar ;}'; 5132 {\bf forInitializerStatement:}localVariableDeclaration `{\escapegrammar ;}';
4594 expression? `{\escapegrammar ;}' 5133 expression? `{\escapegrammar ;}'
4595 . 5134 .
4596 \end{grammar} 5135 \end{grammar}
4597 5136
5137 \LMHash{}
4598 The for statement has three forms - the traditional for loop and two forms of t he for-in statement - synchronous and asynchronous. 5138 The for statement has three forms - the traditional for loop and two forms of t he for-in statement - synchronous and asynchronous.
4599 5139
4600 \subsubsection{For Loop} 5140 \subsubsection{For Loop}
4601 \label{forLoop} 5141 \LMLabel{forLoop}
4602 5142
4603 5143
5144 \LMHash{}
4604 Execution of a for statement of the form \code{ \FOR{} (\VAR{} $v = e_0$ ; $c$ ; $e$) $s$} proceeds as follows: 5145 Execution of a for statement of the form \code{ \FOR{} (\VAR{} $v = e_0$ ; $c$ ; $e$) $s$} proceeds as follows:
4605 5146
5147 \LMHash{}
4606 If $c$ is empty then let $c^\prime$ be \TRUE{} otherwise let $c^\prime$ be $c$. 5148 If $c$ is empty then let $c^\prime$ be \TRUE{} otherwise let $c^\prime$ be $c$.
4607 5149
5150 \LMHash{}
4608 First the variable declaration statement \VAR{} $v = e_0$ is executed. Then: 5151 First the variable declaration statement \VAR{} $v = e_0$ is executed. Then:
4609 \begin{enumerate} 5152 \begin{enumerate}
4610 \item 5153 \item
4611 \label{beginFor} 5154 \label{beginFor}
4612 If this is the first iteration of the for loop, let $v^\prime$ be $v$. Otherwise , let $v^\prime$ be the variable $v^{\prime\prime}$ created in the previous exe cution of step \ref{allocateFreshVar}. 5155 If this is the first iteration of the for loop, let $v^\prime$ be $v$. Otherwise , let $v^\prime$ be the variable $v^{\prime\prime}$ created in the previous exe cution of step \ref{allocateFreshVar}.
4613 \item 5156 \item
4614 The expression $[v^\prime/v]c$ is evaluated and subjected to boolean conversion (\ref{booleans}). If the result is \FALSE{}, the for loop completes. Otherwise, execution continues at step 5157 The expression $[v^\prime/v]c$ is evaluated and subjected to boolean conversion (\ref{booleans}). If the result is \FALSE{}, the for loop completes. Otherwise, execution continues at step
4615 \ref{beginIteration}. 5158 \ref{beginIteration}.
4616 \item 5159 \item
4617 \label{beginIteration} 5160 \label{beginIteration}
4618 The statement $[v^\prime/v]\{s\}$ is executed. 5161 The statement $[v^\prime/v]\{s\}$ is executed.
4619 \item 5162 \item
4620 \label{allocateFreshVar} 5163 \label{allocateFreshVar}
4621 Let $v^{\prime\prime}$ be a fresh variable. $v^{\prime\prime}$ is bound to the value of $v^\prime$. 5164 Let $v^{\prime\prime}$ be a fresh variable. $v^{\prime\prime}$ is bound to the value of $v^\prime$.
4622 \item 5165 \item
4623 The expression $[v^{\prime\prime}/v]e$ is evaluated, and the process recurses at step 5166 The expression $[v^{\prime\prime}/v]e$ is evaluated, and the process recurses at step
4624 \ref{beginFor}. 5167 \ref{beginFor}.
4625 \end{enumerate} 5168 \end{enumerate}
4626 5169
4627 \rationale{ 5170 \rationale{
4628 The definition above is intended to prevent the common error where users create a closure inside a for loop, intending to close over the current binding of the loop variable, and find (usually after a painful process of debugging and learni ng) that all the created closures have captured the same value - the one current in the last iteration executed. 5171 The definition above is intended to prevent the common error where users create a closure inside a for loop, intending to close over the current binding of the loop variable, and find (usually after a painful process of debugging and learni ng) that all the created closures have captured the same value - the one current in the last iteration executed.
4629 5172
4630 Instead, each iteration has its own distinct variable. The first iteration uses the variable created by the initial declaration. The expression executed at the end of each iteration uses a fresh variable $v^{\prime\prime}$, bound to the va lue of the current iteration variable, and then modifies $v^{\prime\prime}$ as r equired for the next iteration. 5173 Instead, each iteration has its own distinct variable. The first iteration uses the variable created by the initial declaration. The expression executed at the end of each iteration uses a fresh variable $v^{\prime\prime}$, bound to the va lue of the current iteration variable, and then modifies $v^{\prime\prime}$ as r equired for the next iteration.
4631 } 5174 }
4632 5175
5176 \LMHash{}
4633 It is a static warning if the static type of $c$ may not be assigned to \cd{bool }. 5177 It is a static warning if the static type of $c$ may not be assigned to \cd{bool }.
4634 5178
4635 %A for statement of the form \code{ \FOR{} ($d$ ; $c$; $e$) $s$} is equivalent t o the the following code: 5179 %A for statement of the form \code{ \FOR{} ($d$ ; $c$; $e$) $s$} is equivalent t o the the following code:
4636 5180
4637 %\code{ 5181 %\code{
4638 %\{$d$; 5182 %\{$d$;
4639 %\WHILE{} ($c$) \{ 5183 %\WHILE{} ($c$) \{
4640 % \{$s$\} 5184 % \{$s$\}
4641 % $e$; 5185 % $e$;
4642 %\}\} 5186 %\}\}
4643 %} 5187 %}
4644 5188
4645 %If $c$ is empty, it is interpreted as \TRUE{}. 5189 %If $c$ is empty, it is interpreted as \TRUE{}.
4646 5190
4647 \subsubsection{For-in} 5191 \subsubsection{For-in}
4648 \label{for-in} 5192 \LMLabel{for-in}
4649 5193
5194 \LMHash{}
4650 A for statement of the form \code{ \FOR{} ($finalConstVarOrType?$ id \IN{} $e$) $s$} is equivalent to the following code: 5195 A for statement of the form \code{ \FOR{} ($finalConstVarOrType?$ id \IN{} $e$) $s$} is equivalent to the following code:
4651 5196
4652 \begin{dartCode} 5197 \begin{dartCode}
4653 var n0 = $e$.iterator; 5198 var n0 = $e$.iterator;
4654 \WHILE{} (n0.moveNext()) \{ 5199 \WHILE{} (n0.moveNext()) \{
4655 $finalConstVarOrType?$ id = n0.current; 5200 $finalConstVarOrType?$ id = n0.current;
4656 $s$ 5201 $s$
4657 \} 5202 \}
4658 \end{dartCode} 5203 \end{dartCode}
4659 where \code{n0} is an identifier that does not occur anywhere in the program. 5204 where \code{n0} is an identifier that does not occur anywhere in the program.
4660 5205
4661 \commentary{ 5206 \commentary{
4662 Note that in fact, using a \CONST{} variable would give rise to a compile time error since \cd{n0.current} is not a constant expression. 5207 Note that in fact, using a \CONST{} variable would give rise to a compile time error since \cd{n0.current} is not a constant expression.
4663 } 5208 }
4664 5209
4665 \subsubsection{Asynchronous For-in} 5210 \subsubsection{Asynchronous For-in}
4666 \label{asynchronousFor-in} 5211 \LMLabel{asynchronousFor-in}
4667 5212
5213 \LMHash{}
4668 A for-in statement may be asynchronous. The asynchronous form is designed to ite rate over streams. An asynchronous for loop is distinguished by the keyword \AWA IT{} immediately preceding the keyword \FOR. 5214 A for-in statement may be asynchronous. The asynchronous form is designed to ite rate over streams. An asynchronous for loop is distinguished by the keyword \AWA IT{} immediately preceding the keyword \FOR.
4669 5215
5216 \LMHash{}
4670 Execution of a for-in statement of the form \code{\AWAIT{} \FOR{} (finalConstVa rOrType? id \IN{} $e$) $s$} proceeds as follows: 5217 Execution of a for-in statement of the form \code{\AWAIT{} \FOR{} (finalConstVa rOrType? id \IN{} $e$) $s$} proceeds as follows:
4671 5218
5219 \LMHash{}
4672 The expression $e$ is evaluated to an object $o$. It is a dynamic error if $o$ i s not an instance of a class that implements \code{Stream}. Otherwise, the expre ssion \code{\AWAIT{} $v_f$} (\ref{awaitExpressions}) is evaluated, where $v_f$ is a fresh variable whose value is a fresh instance (\ref{generativeConstructors }) $f$ implementing the built-in class \code{Future}. 5220 The expression $e$ is evaluated to an object $o$. It is a dynamic error if $o$ i s not an instance of a class that implements \code{Stream}. Otherwise, the expre ssion \code{\AWAIT{} $v_f$} (\ref{awaitExpressions}) is evaluated, where $v_f$ is a fresh variable whose value is a fresh instance (\ref{generativeConstructors }) $f$ implementing the built-in class \code{Future}.
4673 5221
5222 \LMHash{}
4674 The stream $o$ is listened to, and on each data event in $o$ the statement $s$ is executed with \code{id} bound to the value of the current element of the stre am. If $s$ raises an exception, or if $o$ raises an exception, then $f$ is compl eted with that exception. Otherwise, when all events in the stream $o$ have been processed, $f$ is completed with \NULL{} (\ref{null}). 5223 The stream $o$ is listened to, and on each data event in $o$ the statement $s$ is executed with \code{id} bound to the value of the current element of the stre am. If $s$ raises an exception, or if $o$ raises an exception, then $f$ is compl eted with that exception. Otherwise, when all events in the stream $o$ have been processed, $f$ is completed with \NULL{} (\ref{null}).
4675 5224
5225 \LMHash{}
4676 Let $u$ be the stream associated with the immediately enclosing asynchronous for loop or generator function (\ref{functions}), if any. If another event $e_u$ of $u$ occurs before execution of $s$ is complete, handling of $e_u$ must wait unt il $s$ is complete. 5226 Let $u$ be the stream associated with the immediately enclosing asynchronous for loop or generator function (\ref{functions}), if any. If another event $e_u$ of $u$ occurs before execution of $s$ is complete, handling of $e_u$ must wait unt il $s$ is complete.
4677 5227
4678 \rationale{ 5228 \rationale{
4679 The future $f$ and the corresponding \AWAIT{} expression ensure that execution s uspends as an asynchronous for loop begins and resumes after the \FOR{} statemen t when it ends. They also ensure that the stream of any enclosing asynchronous \ FOR{} loop is paused for the duration of this loop. 5229 The future $f$ and the corresponding \AWAIT{} expression ensure that execution s uspends as an asynchronous for loop begins and resumes after the \FOR{} statemen t when it ends. They also ensure that the stream of any enclosing asynchronous \ FOR{} loop is paused for the duration of this loop.
4680 } 5230 }
4681 5231
5232 \LMHash{}
4682 It is a compile-time error if an asynchronous for-in statement appears inside a synchronous function (\ref{functions}). It is a compile-time error if a traditio nal for loop (\ref{forLoop}) is prefixed by the \AWAIT{} keyword. 5233 It is a compile-time error if an asynchronous for-in statement appears inside a synchronous function (\ref{functions}). It is a compile-time error if a traditio nal for loop (\ref{forLoop}) is prefixed by the \AWAIT{} keyword.
4683 5234
4684 \rationale{An asynchronous loop would make no sense within a synchronous functio n, for the same reasons that an await expression makes no sense in a synchronous function.} 5235 \rationale{An asynchronous loop would make no sense within a synchronous functio n, for the same reasons that an await expression makes no sense in a synchronous function.}
4685 5236
4686 5237
4687 \subsection{While} 5238 \subsection{While}
4688 \label{while} 5239 \LMLabel{while}
4689 5240
5241 \LMHash{}
4690 The while statement supports conditional iteration, where the condition is evalu ated prior to the loop. 5242 The while statement supports conditional iteration, where the condition is evalu ated prior to the loop.
4691 5243
4692 \begin{grammar} 5244 \begin{grammar}
4693 {\bf whileStatement:} 5245 {\bf whileStatement:}
4694 \WHILE{} `(' expression `)' statement % could do top level here, and in f or 5246 \WHILE{} `(' expression `)' statement % could do top level here, and in f or
4695 . 5247 .
4696 \end{grammar} 5248 \end{grammar}
4697 5249
5250 \LMHash{}
4698 Execution of a while statement of the form \code{\WHILE{} ($e$) $s$;} proceeds as follows: 5251 Execution of a while statement of the form \code{\WHILE{} ($e$) $s$;} proceeds as follows:
4699 5252
5253 \LMHash{}
4700 The expression $e$ is evaluated to an object $o$. Then, $o$ is subjected to boo lean conversion (\ref{booleanConversion}), producing an object $r$. If $r$ is \ TRUE{}, then the statement $\{s\}$ is executed and then the while statement is r e-executed recursively. If $r$ is \FALSE{}, execution of the while statement is complete. 5254 The expression $e$ is evaluated to an object $o$. Then, $o$ is subjected to boo lean conversion (\ref{booleanConversion}), producing an object $r$. If $r$ is \ TRUE{}, then the statement $\{s\}$ is executed and then the while statement is r e-executed recursively. If $r$ is \FALSE{}, execution of the while statement is complete.
4701 5255
5256 \LMHash{}
4702 It is a static type warning if the static type of $e$ may not be assigned to \co de{bool}. 5257 It is a static type warning if the static type of $e$ may not be assigned to \co de{bool}.
4703 5258
4704 5259
4705 \subsection{Do} 5260 \subsection{Do}
4706 \label{do} 5261 \LMLabel{do}
4707 5262
5263 \LMHash{}
4708 The do statement supports conditional iteration, where the condition is evaluate d after the loop. 5264 The do statement supports conditional iteration, where the condition is evaluate d after the loop.
4709 5265
4710 \begin{grammar} 5266 \begin{grammar}
4711 {\bf doStatement:} 5267 {\bf doStatement:}
4712 \DO{} statement \WHILE{} `(' expression `)' `{\escapegrammar ;}'% could do t op level here 5268 \DO{} statement \WHILE{} `(' expression `)' `{\escapegrammar ;}'% could do t op level here
4713 . 5269 .
4714 \end{grammar} 5270 \end{grammar}
4715 5271
4716 5272
5273 \LMHash{}
4717 Execution of a do statement of the form \code{\DO{} $s$ \WHILE{} ($e$);} proceed s as follows: 5274 Execution of a do statement of the form \code{\DO{} $s$ \WHILE{} ($e$);} proceed s as follows:
4718 5275
5276 \LMHash{}
4719 The statement $\{s\}$ is executed. Then, the expression $e$ is evaluated to an o bject $o$. Then, $o$ is subjected to boolean conversion (\ref{booleanConversion }), producing an object $r$. If $r$ is \FALSE{}, execution of the do statement i s complete. If $r$ is \TRUE{}, then the do statement is re-executed recursively. 5277 The statement $\{s\}$ is executed. Then, the expression $e$ is evaluated to an o bject $o$. Then, $o$ is subjected to boolean conversion (\ref{booleanConversion }), producing an object $r$. If $r$ is \FALSE{}, execution of the do statement i s complete. If $r$ is \TRUE{}, then the do statement is re-executed recursively.
4720 5278
5279 \LMHash{}
4721 It is a static type warning if the static type of $e$ may not be assigned to \co de{bool}. 5280 It is a static type warning if the static type of $e$ may not be assigned to \co de{bool}.
4722 5281
4723 \subsection{Switch} 5282 \subsection{Switch}
4724 \label{switch} 5283 \LMLabel{switch}
4725 5284
5285 \LMHash{}
4726 The {\em switch statement} supports dispatching control among a large number of cases. 5286 The {\em switch statement} supports dispatching control among a large number of cases.
4727 5287
4728 \begin{grammar} 5288 \begin{grammar}
4729 {\bf switchStatement:} 5289 {\bf switchStatement:}
4730 \SWITCH{} `(' expression `)' `\{' switchCase* defaultCase? `\}'% could do top level here and in cases 5290 \SWITCH{} `(' expression `)' `\{' switchCase* defaultCase? `\}'% could do top level here and in cases
4731 . 5291 .
4732 5292
4733 5293
4734 {\bf switchCase:} 5294 {\bf switchCase:}
4735 label* (\CASE{} expression `{\escapegrammar :}') statements 5295 label* (\CASE{} expression `{\escapegrammar :}') statements
4736 . 5296 .
4737 5297
4738 {\bf defaultCase:} 5298 {\bf defaultCase:}
4739 label* \DEFAULT{} `{\escapegrammar :}' statements 5299 label* \DEFAULT{} `{\escapegrammar :}' statements
4740 . 5300 .
4741 \end{grammar} 5301 \end{grammar}
4742 5302
5303 \LMHash{}
4743 Given a switch statement of the form 5304 Given a switch statement of the form
4744 5305
4745 \begin{dartCode} 5306 \begin{dartCode}
4746 \SWITCH{} ($e$) \{ 5307 \SWITCH{} ($e$) \{
4747 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ 5308 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$
4748 $\ldots$ 5309 $\ldots$
4749 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ 5310 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$
4750 \DEFAULT{}: $s_{n+1}$ 5311 \DEFAULT{}: $s_{n+1}$
4751 \} 5312 \}
4752 \end{dartCode} 5313 \end{dartCode}
(...skipping 11 matching lines...) Expand all
4764 it is a compile-time error if the expressions $e_k$ are not compile-time consta nts for all $k \in 1..n$. It is a compile-time error if the values of the expr essions $e_k$ are not either: 5325 it is a compile-time error if the expressions $e_k$ are not compile-time consta nts for all $k \in 1..n$. It is a compile-time error if the values of the expr essions $e_k$ are not either:
4765 \begin{itemize} 5326 \begin{itemize}
4766 \item instances of the same class $C$, for all $k \in 1..n$, or 5327 \item instances of the same class $C$, for all $k \in 1..n$, or
4767 \item instances of a class that implements \cd{int}, for all $k \in 1..n$, or 5328 \item instances of a class that implements \cd{int}, for all $k \in 1..n$, or
4768 \item instances of a class that implements \cd{String}, for all $k \in 1..n$. 5329 \item instances of a class that implements \cd{String}, for all $k \in 1..n$.
4769 \end{itemize} 5330 \end{itemize}
4770 5331
4771 \commentary{In other words, all the expressions in the cases evaluate to consta nts of the exact same user defined class or are of certain known types. Note th at the values of the expressions are known at compile-time, and are independent of any static type annotations. 5332 \commentary{In other words, all the expressions in the cases evaluate to consta nts of the exact same user defined class or are of certain known types. Note th at the values of the expressions are known at compile-time, and are independent of any static type annotations.
4772 } 5333 }
4773 5334
5335 \LMHash{}
4774 It is a compile-time error if the class $C$ has an implementation of the operato r $==$ other than the one inherited from \code{Object} unless the value of the e xpression is a string, an integer, literal symbol or the result of invoking a co nstant constructor of class \cd{Symbol}. 5336 It is a compile-time error if the class $C$ has an implementation of the operato r $==$ other than the one inherited from \code{Object} unless the value of the e xpression is a string, an integer, literal symbol or the result of invoking a co nstant constructor of class \cd{Symbol}.
4775 5337
4776 \rationale{ 5338 \rationale{
4777 The prohibition on user defined equality allows us to implement the switch effi ciently for user defined types. We could formulate matching in terms of identity instead with the same efficiency. However, if a type defines an equality operat or, programmers would find it quite surprising that equal objects did not match. 5339 The prohibition on user defined equality allows us to implement the switch effi ciently for user defined types. We could formulate matching in terms of identity instead with the same efficiency. However, if a type defines an equality operat or, programmers would find it quite surprising that equal objects did not match.
4778 5340
4779 } 5341 }
4780 5342
4781 \commentary{ 5343 \commentary{
4782 The \SWITCH{} statement should only be used in very limited situations (e.g., i nterpreters or scanners). 5344 The \SWITCH{} statement should only be used in very limited situations (e.g., i nterpreters or scanners).
4783 } 5345 }
4784 5346
5347 \LMHash{}
4785 Execution of a switch statement of the form 5348 Execution of a switch statement of the form
4786 5349
4787 \begin{dartCode} 5350 \begin{dartCode}
4788 \SWITCH{} ($e$) \{ 5351 \SWITCH{} ($e$) \{
4789 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ 5352 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$
4790 $\ldots$ 5353 $\ldots$
4791 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ 5354 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$
4792 \DEFAULT{}: $s_{n+1}$ 5355 \DEFAULT{}: $s_{n+1}$
4793 \} 5356 \}
4794 \end{dartCode} 5357 \end{dartCode}
4795 5358
4796 or the form 5359 or the form
4797 5360
4798 \begin{dartCode} 5361 \begin{dartCode}
4799 \SWITCH{} ($e$) \{ 5362 \SWITCH{} ($e$) \{
4800 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ 5363 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$
4801 $\ldots$ 5364 $\ldots$
4802 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ 5365 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$
4803 \} 5366 \}
4804 \end{dartCode} 5367 \end{dartCode}
4805 5368
4806 proceeds as follows: 5369 proceeds as follows:
4807 5370
5371 \LMHash{}
4808 The statement \code{\VAR{} id = $e$;} is evaluated, where \code{id} is a variabl e whose name is distinct from any other variable in the program. In checked mode , it is a run time error if the value of $e$ is not an instance of the same clas s as the constants $e_1 \ldots e_n$. 5372 The statement \code{\VAR{} id = $e$;} is evaluated, where \code{id} is a variabl e whose name is distinct from any other variable in the program. In checked mode , it is a run time error if the value of $e$ is not an instance of the same clas s as the constants $e_1 \ldots e_n$.
4809 5373
4810 \commentary{Note that if there are no case clauses ($n = 0$), the type of $e$ do es not matter.} 5374 \commentary{Note that if there are no case clauses ($n = 0$), the type of $e$ do es not matter.}
4811 5375
5376 \LMHash{}
4812 Next, the case clause \CASE{} $e_{1}: s_{1}$ is executed if it exists. If \CASE{ } $e_{1}: s_{1}$ does not exist, then if there is a \DEFAULT{} clause it is exe cuted by executing $s_{n+1}$. 5377 Next, the case clause \CASE{} $e_{1}: s_{1}$ is executed if it exists. If \CASE{ } $e_{1}: s_{1}$ does not exist, then if there is a \DEFAULT{} clause it is exe cuted by executing $s_{n+1}$.
4813 5378
5379 \LMHash{}
4814 A case clause introduces a new scope, nested in the lexically surrounding scope. The scope of a case clause ends immediately after the case clause's statement l ist. 5380 A case clause introduces a new scope, nested in the lexically surrounding scope. The scope of a case clause ends immediately after the case clause's statement l ist.
4815 5381
5382 \LMHash{}
4816 Execution of a \CASE{} clause \CASE{} $e_{k}: s_{k}$ of a switch statement 5383 Execution of a \CASE{} clause \CASE{} $e_{k}: s_{k}$ of a switch statement
4817 5384
4818 \begin{dartCode} 5385 \begin{dartCode}
4819 \SWITCH{} ($e$) \{ 5386 \SWITCH{} ($e$) \{
4820 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ 5387 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$
4821 $\ldots$ 5388 $\ldots$
4822 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ 5389 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$
4823 \DEFAULT{}: $s_{n+1}$ 5390 \DEFAULT{}: $s_{n+1}$
4824 \} 5391 \}
4825 \end{dartCode} 5392 \end{dartCode}
4826 5393
4827 proceeds as follows: 5394 proceeds as follows:
4828 5395
5396 \LMHash{}
4829 The expression \code{$e_k$ == id} is evaluated to an object $o$ which is then su bjected to boolean conversion yielding a value $v$. 5397 The expression \code{$e_k$ == id} is evaluated to an object $o$ which is then su bjected to boolean conversion yielding a value $v$.
4830 If $v$ is not \TRUE{} the following case, \CASE{} $e_{k+1}: s_{k+1}$ is execut ed if it exists. If \CASE{} $e_{k+1}: s_{k+1}$ does not exist, then the \DEFAUL T{} clause is executed by executing $s_{n+1}$. 5398 If $v$ is not \TRUE{} the following case, \CASE{} $e_{k+1}: s_{k+1}$ is execut ed if it exists. If \CASE{} $e_{k+1}: s_{k+1}$ does not exist, then the \DEFAUL T{} clause is executed by executing $s_{n+1}$.
4831 If $v$ is \TRUE{}, let $h$ be the smallest number such that $h \ge k$ and $s_h $ is non-empty. If no such $h$ exists, let $h = n + 1$. The sequence of stateme nts $s_h$ is then executed. 5399 If $v$ is \TRUE{}, let $h$ be the smallest number such that $h \ge k$ and $s_h $ is non-empty. If no such $h$ exists, let $h = n + 1$. The sequence of stateme nts $s_h$ is then executed.
4832 If execution reaches the point after $s_h$ then a runtime error occurs, unless $h = n+1$. 5400 If execution reaches the point after $s_h$ then a runtime error occurs, unless $h = n+1$.
4833 5401
5402 \LMHash{}
4834 Execution of a \CASE{} clause \CASE{} $e_{k}: s_{k}$ of a switch statement 5403 Execution of a \CASE{} clause \CASE{} $e_{k}: s_{k}$ of a switch statement
4835 5404
4836 \begin{dartCode} 5405 \begin{dartCode}
4837 \SWITCH{} ($e$) \{ 5406 \SWITCH{} ($e$) \{
4838 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ 5407 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$
4839 $\ldots$ 5408 $\ldots$
4840 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ 5409 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$
4841 \} 5410 \}
4842 \end{dartCode} 5411 \end{dartCode}
4843 5412
4844 proceeds as follows: 5413 proceeds as follows:
4845 5414
5415 \LMHash{}
4846 The expression \code{$e_k$ == id} is evaluated to an object $o$ which is then su bjected to boolean conversion yielding a value $v$. 5416 The expression \code{$e_k$ == id} is evaluated to an object $o$ which is then su bjected to boolean conversion yielding a value $v$.
4847 If $v$ is not \TRUE{} the following case, \CASE{} $e_{k+1}: s_{k+1}$ is execut ed if it exists. 5417 If $v$ is not \TRUE{} the following case, \CASE{} $e_{k+1}: s_{k+1}$ is execut ed if it exists.
4848 If $v$ is \TRUE{}, let $h$ be the smallest integer such that $h \ge k$ and $s_ h$ is non-empty. The sequence of statements $s_h$ is executed if it exists. 5418 If $v$ is \TRUE{}, let $h$ be the smallest integer such that $h \ge k$ and $s_ h$ is non-empty. The sequence of statements $s_h$ is executed if it exists.
4849 If execution reaches the point after $s_h$ then a runtime error occurs, unless $h = n$. 5419 If execution reaches the point after $s_h$ then a runtime error occurs, unless $h = n$.
4850 5420
4851 5421
4852 \commentary{ 5422 \commentary{
4853 In other words, there is no implicit fall-through between cases. The last case i n a switch (default or otherwise) can `fall-through' to the end of the statement . 5423 In other words, there is no implicit fall-through between cases. The last case i n a switch (default or otherwise) can `fall-through' to the end of the statement .
4854 } 5424 }
4855 5425
5426 \LMHash{}
4856 It is a static warning if the type of $e$ may not be assigned to the type of $e_ k$. It is a static warning if the last statement of the statement sequence $s_k$ is not a \BREAK{}, \CONTINUE{}, \RETURN{} or \THROW{} statement. 5427 It is a static warning if the type of $e$ may not be assigned to the type of $e_ k$. It is a static warning if the last statement of the statement sequence $s_k$ is not a \BREAK{}, \CONTINUE{}, \RETURN{} or \THROW{} statement.
4857 5428
4858 \rationale{ 5429 \rationale{
4859 The behavior of switch cases intentionally differs from the C tradition. Implic it fall through is a known cause of programming errors and therefore disallowed. Why not simply break the flow implicitly at the end of every case, rather than requiring explicit code to do so? This would indeed be cleaner. It would also be cleaner to insist that each case have a single (possibly compound) statement . We have chosen not to do so in order to facilitate porting of switch statemen ts from other languages. Implicitly breaking the control flow at the end of a c ase would silently alter the meaning of ported code that relied on fall-through, potentially forcing the programmer to deal with subtle bugs. Our design ensures that the difference is immediately brought to the coder's attention. The progr ammer will be notified at compile-time if they forget to end a case with a state ment that terminates the straight-line control flow. We could make this warning a compile-time error, but refrain from doing so because do not wish to force the programmer to deal with this issue immediately while porting code. If develope rs ignore the warning and run their code, a run time error will prevent the prog ram from misbehaving in hard-to-debug ways (at least with respect to this issue) . 5430 The behavior of switch cases intentionally differs from the C tradition. Implic it fall through is a known cause of programming errors and therefore disallowed. Why not simply break the flow implicitly at the end of every case, rather than requiring explicit code to do so? This would indeed be cleaner. It would also be cleaner to insist that each case have a single (possibly compound) statement . We have chosen not to do so in order to facilitate porting of switch statemen ts from other languages. Implicitly breaking the control flow at the end of a c ase would silently alter the meaning of ported code that relied on fall-through, potentially forcing the programmer to deal with subtle bugs. Our design ensures that the difference is immediately brought to the coder's attention. The progr ammer will be notified at compile-time if they forget to end a case with a state ment that terminates the straight-line control flow. We could make this warning a compile-time error, but refrain from doing so because do not wish to force the programmer to deal with this issue immediately while porting code. If develope rs ignore the warning and run their code, a run time error will prevent the prog ram from misbehaving in hard-to-debug ways (at least with respect to this issue) .
4860 5431
4861 The sophistication of the analysis of fall-through is another issue. For now, we have opted for a very straightforward syntactic requirement. There are obviousl y situations where code does not fall through, and yet does not conform to these simple rules, e.g.: 5432 The sophistication of the analysis of fall-through is another issue. For now, we have opted for a very straightforward syntactic requirement. There are obviousl y situations where code does not fall through, and yet does not conform to these simple rules, e.g.:
4862 } 5433 }
4863 5434
4864 \begin{dartCode} 5435 \begin{dartCode}
4865 \SWITCH{} (x) \{ 5436 \SWITCH{} (x) \{
4866 \CASE{} 1: \TRY{} \{ $\ldots$ \RETURN{};\} \FINALLY{} \{ $\ldots$ \RETURN{};\} 5437 \CASE{} 1: \TRY{} \{ $\ldots$ \RETURN{};\} \FINALLY{} \{ $\ldots$ \RETURN{};\}
4867 \} 5438 \}
4868 \end{dartCode} 5439 \end{dartCode}
4869 5440
4870 \rationale{ 5441 \rationale{
4871 Very elaborate code in a case clause is probably bad style in any case, and su ch code can always be refactored. 5442 Very elaborate code in a case clause is probably bad style in any case, and su ch code can always be refactored.
4872 } 5443 }
4873 5444
5445 \LMHash{}
4874 It is a static warning if all of the following conditions hold: 5446 It is a static warning if all of the following conditions hold:
4875 \begin{itemize} 5447 \begin{itemize}
4876 \item The switch statement does not have a default clause. 5448 \item The switch statement does not have a default clause.
4877 \item The static type of $e$ is an enumerated typed with elements $id_1, \ldots , id_n$. 5449 \item The static type of $e$ is an enumerated typed with elements $id_1, \ldots , id_n$.
4878 \item The sets $\{e_1, \ldots, e_k\} $ and $\{id_1, \ldots, id_n\}$ are not the same. 5450 \item The sets $\{e_1, \ldots, e_k\} $ and $\{id_1, \ldots, id_n\}$ are not the same.
4879 \end{itemize} 5451 \end{itemize}
4880 5452
4881 \commentary{ 5453 \commentary{
4882 In other words, a warning will be issued if a switch statement over an enum is n ot exhaustive. 5454 In other words, a warning will be issued if a switch statement over an enum is n ot exhaustive.
4883 } 5455 }
4884 5456
4885 5457
4886 \subsection{ Rethrow} 5458 \subsection{ Rethrow}
4887 \label{rethrow} 5459 \LMLabel{rethrow}
4888 5460
4889 5461
5462 \LMHash{}
4890 The {\em rethrow statement} is used to re-raise an exception. 5463 The {\em rethrow statement} is used to re-raise an exception.
4891 5464
4892 \begin{grammar} 5465 \begin{grammar}
4893 {\bf rethrowStatement:} 5466 {\bf rethrowStatement:}
4894 \RETHROW{} `{\escapegrammar ;}' 5467 \RETHROW{} `{\escapegrammar ;}'
4895 . 5468 .
4896 \end{grammar} 5469 \end{grammar}
4897 5470
5471 \LMHash{}
4898 Execution of a \code{\RETHROW{}} statement proceeds as follows: 5472 Execution of a \code{\RETHROW{}} statement proceeds as follows:
4899 5473
5474 \LMHash{}
4900 Let $f$ be the immediately enclosing function, and let \code{\ON{} $T$ \CATCH{} ($p_1$, $p_2$)} be the immediately enclosing catch clause (\ref{try}). 5475 Let $f$ be the immediately enclosing function, and let \code{\ON{} $T$ \CATCH{} ($p_1$, $p_2$)} be the immediately enclosing catch clause (\ref{try}).
4901 5476
4902 \rationale{ 5477 \rationale{
4903 A \RETHROW{} statement always appears inside a \CATCH{} clause, and any \CATCH{} clause is semantically equivalent to some \CATCH{} clause of the form \code{\ON {} $T$ \CATCH{} (p1, p2)}. So we can assume that the \RETHROW{} is enclosed in a \CATCH{} clause of that form. 5478 A \RETHROW{} statement always appears inside a \CATCH{} clause, and any \CATCH{} clause is semantically equivalent to some \CATCH{} clause of the form \code{\ON {} $T$ \CATCH{} (p1, p2)}. So we can assume that the \RETHROW{} is enclosed in a \CATCH{} clause of that form.
4904 } 5479 }
4905 5480
5481 \LMHash{}
4906 The current exception (\ref{throw}) is set to $p_1$, the current return value (\ ref{return}) becomes undefined, and the active stack trace (\ref{try}) is set to $p_2$. 5482 The current exception (\ref{throw}) is set to $p_1$, the current return value (\ ref{return}) becomes undefined, and the active stack trace (\ref{try}) is set to $p_2$.
4907 5483
5484 \LMHash{}
4908 If $f$ is marked \ASYNC{} or \ASYNC* (\ref{functions}) and there is a dynamicall y enclosing exception handler (\ref{try}) $h$ introduced by the current activati on, control is transferred to $h$, otherwise $f$ terminates. 5485 If $f$ is marked \ASYNC{} or \ASYNC* (\ref{functions}) and there is a dynamicall y enclosing exception handler (\ref{try}) $h$ introduced by the current activati on, control is transferred to $h$, otherwise $f$ terminates.
4909 5486
4910 \rationale{ 5487 \rationale{
4911 In the case of an asynchronous function, the dynamically enclosing exception han dler is only relevant within the function. If an exception is not caught within the function, the exception value is channelled through a future or stream rathe r than propagating via exception handlers. 5488 In the case of an asynchronous function, the dynamically enclosing exception han dler is only relevant within the function. If an exception is not caught within the function, the exception value is channelled through a future or stream rathe r than propagating via exception handlers.
4912 } 5489 }
4913 5490
5491 \LMHash{}
4914 Otherwise, control is transferred to the innermost enclosing exception handler. 5492 Otherwise, control is transferred to the innermost enclosing exception handler.
4915 5493
4916 \commentary{The change in control may result in multiple functions terminating i f these functions do not catch the exception via a \CATCH{} or \FINALLY{} clause , both of which introduce a dynamically enclosing exception handler.} 5494 \commentary{The change in control may result in multiple functions terminating i f these functions do not catch the exception via a \CATCH{} or \FINALLY{} clause , both of which introduce a dynamically enclosing exception handler.}
4917 5495
5496 \LMHash{}
4918 It is a compile-time error if a \code{\RETHROW{}} statement is not enclosed wit hin an \ON-\CATCH{} clause. 5497 It is a compile-time error if a \code{\RETHROW{}} statement is not enclosed wit hin an \ON-\CATCH{} clause.
4919 5498
4920 5499
4921 5500
4922 \subsection{ Try} 5501 \subsection{ Try}
4923 \label{try} 5502 \LMLabel{try}
4924 5503
5504 \LMHash{}
4925 The try statement supports the definition of exception handling code in a struct ured way. 5505 The try statement supports the definition of exception handling code in a struct ured way.
4926 5506
4927 \begin{grammar} 5507 \begin{grammar}
4928 {\bf tryStatement:} 5508 {\bf tryStatement:}
4929 \TRY{} block (onPart+ finallyPart? $|$ finallyPart) 5509 \TRY{} block (onPart+ finallyPart? $|$ finallyPart)
4930 . 5510 .
4931 5511
4932 {\bf onPart:}catchPart block; 5512 {\bf onPart:}catchPart block;
4933 \ON{} type catchPart? block 5513 \ON{} type catchPart? block
4934 . 5514 .
4935 5515
4936 {\bf catchPart:} 5516 {\bf catchPart:}
4937 \CATCH{} `(' identifier (`,' identifier)? `)' 5517 \CATCH{} `(' identifier (`,' identifier)? `)'
4938 . 5518 .
4939 5519
4940 {\bf finallyPart:} 5520 {\bf finallyPart:}
4941 \FINALLY{} block 5521 \FINALLY{} block
4942 . 5522 .
4943 \end{grammar} 5523 \end{grammar}
4944 5524
5525 \LMHash{}
4945 A try statement consists of a block statement, followed by at least one of: 5526 A try statement consists of a block statement, followed by at least one of:
4946 \begin{enumerate} 5527 \begin{enumerate}
4947 \item 5528 \item
4948 A set of \ON{}-\CATCH{} clauses, each of which specifies (either explicitly or implicitly) the type of exception object to be handled, one or two exception par ameters and a block statement. 5529 A set of \ON{}-\CATCH{} clauses, each of which specifies (either explicitly or implicitly) the type of exception object to be handled, one or two exception par ameters and a block statement.
4949 \item 5530 \item
4950 A \FINALLY{} clause, which consists of a block statement. 5531 A \FINALLY{} clause, which consists of a block statement.
4951 \end{enumerate} 5532 \end{enumerate}
4952 5533
4953 \rationale{ 5534 \rationale{
4954 The syntax is designed to be upward compatible with existing Javascript programs . The \ON{} clause can be omitted, leaving what looks like a Javascript catch cl ause. 5535 The syntax is designed to be upward compatible with existing Javascript programs . The \ON{} clause can be omitted, leaving what looks like a Javascript catch cl ause.
4955 } 5536 }
4956 5537
5538 \LMHash{}
4957 An \ON{}-\CATCH{} clause of the form \code{\ON{} $T$ \CATCH{} ($p_1, p_2$) $s$ } {\em matches} an object $o$ if the type of $o$ is a subtype of $T$. If $T$ is a malformed or deferred type (\ref{staticTypes}), then performing a match ca uses a run time error. 5539 An \ON{}-\CATCH{} clause of the form \code{\ON{} $T$ \CATCH{} ($p_1, p_2$) $s$ } {\em matches} an object $o$ if the type of $o$ is a subtype of $T$. If $T$ is a malformed or deferred type (\ref{staticTypes}), then performing a match ca uses a run time error.
4958 5540
4959 \commentary { 5541 \commentary {
4960 It is of course a static warning if $T$ is a deferred or malformed type. 5542 It is of course a static warning if $T$ is a deferred or malformed type.
4961 } 5543 }
4962 5544
5545 \LMHash{}
4963 An \ON{}-\CATCH{} clause of the form \code{\ON{} $T$ \CATCH{} ($p_1, p_2$) $s$ } introduces a new scope $CS$ in which final local variables specified by $p_1$ and $p_2$ are defined. The statement $s$ is enclosed within $CS$. The static typ e of $p_1$ is $T$ and the static type of $p_2$ is \code{StackTrace}. 5546 An \ON{}-\CATCH{} clause of the form \code{\ON{} $T$ \CATCH{} ($p_1, p_2$) $s$ } introduces a new scope $CS$ in which final local variables specified by $p_1$ and $p_2$ are defined. The statement $s$ is enclosed within $CS$. The static typ e of $p_1$ is $T$ and the static type of $p_2$ is \code{StackTrace}.
4964 5547
4965 5548
5549 \LMHash{}
4966 An \ON{}-\CATCH{} clause of the form \code{\ON{} $T$ \CATCH{} ($p_1$) $s$} is e quivalent to an \ON{}-\CATCH{} clause \code{\ON{} $T$ \CATCH{} ($p_1, p_2$) $s$ } where $p_2$ is an identifier that does not occur anywhere else in the program. 5550 An \ON{}-\CATCH{} clause of the form \code{\ON{} $T$ \CATCH{} ($p_1$) $s$} is e quivalent to an \ON{}-\CATCH{} clause \code{\ON{} $T$ \CATCH{} ($p_1, p_2$) $s$ } where $p_2$ is an identifier that does not occur anywhere else in the program.
4967 5551
4968 5552
5553 \LMHash{}
4969 An \ON{}-\CATCH{} clause of the form \code{\CATCH{} ($p$) $s$} is equivalent to an \ON{}-\CATCH{} clause \code{\ON{} \DYNAMIC{} \CATCH{} ($p$) $s$}. An \ON{}- \CATCH{} clause of the form \code{\CATCH{} ($p_1, p_2$) $s$} is equivalent to a n \ON{}-\CATCH{} clause \code{\ON{} \DYNAMIC{} \CATCH{} ($p_1, p_2$) $s$}. 5554 An \ON{}-\CATCH{} clause of the form \code{\CATCH{} ($p$) $s$} is equivalent to an \ON{}-\CATCH{} clause \code{\ON{} \DYNAMIC{} \CATCH{} ($p$) $s$}. An \ON{}- \CATCH{} clause of the form \code{\CATCH{} ($p_1, p_2$) $s$} is equivalent to a n \ON{}-\CATCH{} clause \code{\ON{} \DYNAMIC{} \CATCH{} ($p_1, p_2$) $s$}.
4970 5555
4971 5556
4972 %If an explicit type is associated with of $p_2$, it is a static warning if that type is not \code{Object} or \DYNAMIC{}. 5557 %If an explicit type is associated with of $p_2$, it is a static warning if that type is not \code{Object} or \DYNAMIC{}.
4973 5558
5559 \LMHash{}
4974 The {\em active stack trace} is an object whose \code{toString()} method produce s a string that is a record of exactly those function activations within the cur rent isolate that had not completed execution at the point where the current exc eption (\ref{throw}) was thrown. 5560 The {\em active stack trace} is an object whose \code{toString()} method produce s a string that is a record of exactly those function activations within the cur rent isolate that had not completed execution at the point where the current exc eption (\ref{throw}) was thrown.
4975 %\begin{enumerate} 5561 %\begin{enumerate}
4976 %\item Started execution after the currently executing function. 5562 %\item Started execution after the currently executing function.
4977 %\item Had not completed execution at the point where the exception caught by th e currently executing \ON{}-\CATCH{} clause was initially thrown. 5563 %\item Had not completed execution at the point where the exception caught by th e currently executing \ON{}-\CATCH{} clause was initially thrown.
4978 %\commentary{The active stack trace contains the frames between the exception ha ndling code and the original point when an exception is thrown, not where it was rethrown.} 5564 %\commentary{The active stack trace contains the frames between the exception ha ndling code and the original point when an exception is thrown, not where it was rethrown.}
4979 %\end{enumerate} 5565 %\end{enumerate}
4980 5566
4981 \commentary{ 5567 \commentary{
4982 This implies that no synthetic function activations may be added to the trace, n or may any source level activations be omitted. 5568 This implies that no synthetic function activations may be added to the trace, n or may any source level activations be omitted.
4983 This means, for example, that any inlining of functions done as an optimization must not be visible in the trace. Similarly, any synthetic routines used by the implementation must not appear in the trace. 5569 This means, for example, that any inlining of functions done as an optimization must not be visible in the trace. Similarly, any synthetic routines used by the implementation must not appear in the trace.
(...skipping 10 matching lines...) Expand all
4994 5580
4995 % For each such function activation, the active stack trace includes the name of the function, the bindings of all its formal parameters, local variables and \T HIS{}, and the position at which the function was executing. 5581 % For each such function activation, the active stack trace includes the name of the function, the bindings of all its formal parameters, local variables and \T HIS{}, and the position at which the function was executing.
4996 5582
4997 % Is this controversial? We were thinking of viewing the trace as a List<Invoca tion>, 5583 % Is this controversial? We were thinking of viewing the trace as a List<Invoca tion>,
4998 % but that won't capture the receiver or the locals. More generally, we need a standard interface that describes these traces, so one can type the stack trace variable in the catch. 5584 % but that won't capture the receiver or the locals. More generally, we need a standard interface that describes these traces, so one can type the stack trace variable in the catch.
4999 5585
5000 \commentary{The term position should not be interpreted as a line number, but r ather as a precise position - the exact character index of the expression that raised the exception. } 5586 \commentary{The term position should not be interpreted as a line number, but r ather as a precise position - the exact character index of the expression that raised the exception. }
5001 5587
5002 % A position can be represented via a Token. If we make that part of the core r eflection facility, we can state this here. 5588 % A position can be represented via a Token. If we make that part of the core r eflection facility, we can state this here.
5003 5589
5590 \LMHash{}
5004 A try statement \TRY{} $s_1$ $on-catch_1 \ldots on-catch_n$ \FINALLY{} $s_f$ d efines an exception handler $h$ that executes as follows: 5591 A try statement \TRY{} $s_1$ $on-catch_1 \ldots on-catch_n$ \FINALLY{} $s_f$ d efines an exception handler $h$ that executes as follows:
5005 5592
5593 \LMHash{}
5006 The \ON{}-\CATCH{} clauses are examined in order, starting with $catch_1$, until either an \ON{}-\CATCH{} clause that matches the current exception (\ref{throw} ) is found, or the list of \ON{}-\CATCH{} clauses has been exhausted. If an \ON{ }-\CATCH{} clause $on-catch_k$ is found, then $p_{k1}$ is bound to the current e xception, $p_{k2}$, if declared, is bound to the active stack trace, and then $catch_k$ is executed. If no \ON{}-\CATCH{} clause is found, the \FINALLY{} clau se is executed. Then, execution resumes at the end of the try statement. 5594 The \ON{}-\CATCH{} clauses are examined in order, starting with $catch_1$, until either an \ON{}-\CATCH{} clause that matches the current exception (\ref{throw} ) is found, or the list of \ON{}-\CATCH{} clauses has been exhausted. If an \ON{ }-\CATCH{} clause $on-catch_k$ is found, then $p_{k1}$ is bound to the current e xception, $p_{k2}$, if declared, is bound to the active stack trace, and then $catch_k$ is executed. If no \ON{}-\CATCH{} clause is found, the \FINALLY{} clau se is executed. Then, execution resumes at the end of the try statement.
5007 5595
5008 5596
5597 \LMHash{}
5009 A finally clause \FINALLY{} $s$ defines an exception handler $h$ that executes a s follows: 5598 A finally clause \FINALLY{} $s$ defines an exception handler $h$ that executes a s follows:
5010 5599
5600 \LMHash{}
5011 Let $r$ be the current return value (\ref{return}). Then the current return valu e becomes undefined. Any open streams associated with any asynchronous for loops (\ref{asynchronousFor-in}) and yield-each (\ref{yieldEach}) statements executin g within the dynamic scope of $h$ are canceled. 5601 Let $r$ be the current return value (\ref{return}). Then the current return valu e becomes undefined. Any open streams associated with any asynchronous for loops (\ref{asynchronousFor-in}) and yield-each (\ref{yieldEach}) statements executin g within the dynamic scope of $h$ are canceled.
5012 5602
5013 \rationale{ 5603 \rationale{
5014 Streams left open by for loops that were escaped for whatever reason would be ca nceled at function termination, but it is best to cancel them as soon as possibl e. 5604 Streams left open by for loops that were escaped for whatever reason would be ca nceled at function termination, but it is best to cancel them as soon as possibl e.
5015 } 5605 }
5016 5606
5607 \LMHash{}
5017 Then the \FINALLY{} clause is executed. Let $m$ be the immediately enclosing fun ction. If $r$ is defined then the current return value is set to $r$ and then: 5608 Then the \FINALLY{} clause is executed. Let $m$ be the immediately enclosing fun ction. If $r$ is defined then the current return value is set to $r$ and then:
5018 \begin{itemize} 5609 \begin{itemize}
5019 \item 5610 \item
5020 if there is a dynamically enclosing error handler $g$ defined by a \FINALLY{} c lause in $m$, control is transferred to $g$. 5611 if there is a dynamically enclosing error handler $g$ defined by a \FINALLY{} c lause in $m$, control is transferred to $g$.
5021 \item 5612 \item
5022 Otherwise $m$ terminates. 5613 Otherwise $m$ terminates.
5023 \end{itemize} 5614 \end{itemize}
5024 5615
5025 Otherwise, execution resumes at the end of the try statement. 5616 Otherwise, execution resumes at the end of the try statement.
5026 5617
5618 \LMHash{}
5027 Execution of an \ON{}-\CATCH{} clause \code{\ON{} $T$ \CATCH{} ($p_1$, $p_2$)} $ s$ of a try statement $t$ proceeds as follows: The statement $s$ is executed in the dynamic scope of the exception handler defined by the finally clause of $t$. Then, the current exception and active stack trace both become undefined. 5619 Execution of an \ON{}-\CATCH{} clause \code{\ON{} $T$ \CATCH{} ($p_1$, $p_2$)} $ s$ of a try statement $t$ proceeds as follows: The statement $s$ is executed in the dynamic scope of the exception handler defined by the finally clause of $t$. Then, the current exception and active stack trace both become undefined.
5028 5620
5621 \LMHash{}
5029 Execution of a \FINALLY{} clause \FINALLY{} $s$ of a try statement proceeds as f ollows: 5622 Execution of a \FINALLY{} clause \FINALLY{} $s$ of a try statement proceeds as f ollows:
5030 5623
5624 \LMHash{}
5031 Let $x$ be the current exception and let $t$ be the active stack trace. Then the current exception and the active stack trace both become undefined. The stateme nt $s$ is executed. Then, if $x$ is defined, it is rethrown as if by a rethrow statement (\ref{rethrow}) enclosed in a \CATCH{} clause of the form \code{\CATCH {} ($v_x$, $v_t$)} where $v_x$ and $v_t$ are fresh variables bound to $x$ and $t $ respectively. 5625 Let $x$ be the current exception and let $t$ be the active stack trace. Then the current exception and the active stack trace both become undefined. The stateme nt $s$ is executed. Then, if $x$ is defined, it is rethrown as if by a rethrow statement (\ref{rethrow}) enclosed in a \CATCH{} clause of the form \code{\CATCH {} ($v_x$, $v_t$)} where $v_x$ and $v_t$ are fresh variables bound to $x$ and $t $ respectively.
5032 5626
5033 5627
5628 \LMHash{}
5034 Execution of a try statement of the form \code{\TRY{} $s_1$ $on-catch_1 \ldots o n-catch_n$ \FINALLY{} $s_f$;} proceeds as follows: 5629 Execution of a try statement of the form \code{\TRY{} $s_1$ $on-catch_1 \ldots o n-catch_n$ \FINALLY{} $s_f$;} proceeds as follows:
5035 5630
5631 \LMHash{}
5036 The statement $s_1$ is executed in the dynamic scope of the exception handler de fined by the try statement. Then, the \FINALLY{} clause is executed. 5632 The statement $s_1$ is executed in the dynamic scope of the exception handler de fined by the try statement. Then, the \FINALLY{} clause is executed.
5037 5633
5038 \commentary{ 5634 \commentary{
5039 Whether any of the \ON{}-\CATCH{} clauses is executed depends on whether a match ing exception has been raised by $s_1$ (see the specification of the throw state ment). 5635 Whether any of the \ON{}-\CATCH{} clauses is executed depends on whether a match ing exception has been raised by $s_1$ (see the specification of the throw state ment).
5040 5636
5041 If $s_1$ has raised an exception, it will transfer control to the try statement' s handler, which will examine the catch clauses in order for a match as specifie d above. If no matches are found, the handler will execute the \FINALLY{} clause . 5637 If $s_1$ has raised an exception, it will transfer control to the try statement' s handler, which will examine the catch clauses in order for a match as specifie d above. If no matches are found, the handler will execute the \FINALLY{} clause .
5042 5638
5043 If a matching \ON{}-\CATCH{} was found, it will execute first, and then the \FIN ALLY{} clause will be executed. 5639 If a matching \ON{}-\CATCH{} was found, it will execute first, and then the \FIN ALLY{} clause will be executed.
5044 5640
5045 If an exception is thrown during execution of an \ON{}-\CATCH{} clause, this wil l transfer control to the handler for the \FINALLY{} clause, causing the \FINALL Y{} clause to execute in this case as well. 5641 If an exception is thrown during execution of an \ON{}-\CATCH{} clause, this wil l transfer control to the handler for the \FINALLY{} clause, causing the \FINALL Y{} clause to execute in this case as well.
5046 5642
5047 If no exception was raised, the \FINALLY{} clause is also executed. Execution of the \FINALLY{} clause could also raise an exception, which will cause transfer of control to the next enclosing handler. 5643 If no exception was raised, the \FINALLY{} clause is also executed. Execution of the \FINALLY{} clause could also raise an exception, which will cause transfer of control to the next enclosing handler.
5048 } 5644 }
5049 5645
5646 \LMHash{}
5050 A try statement of the form \code{\TRY{} $s_1$ $on-catch_1 \ldots on-catch_n$;} is equivalent to the statement \code{\TRY{} $s_1$ $on-catch_1 \ldots on-catch_n$ \FINALLY{} $\{\}$}. 5647 A try statement of the form \code{\TRY{} $s_1$ $on-catch_1 \ldots on-catch_n$;} is equivalent to the statement \code{\TRY{} $s_1$ $on-catch_1 \ldots on-catch_n$ \FINALLY{} $\{\}$}.
5051 5648
5052 5649
5053 \subsection{ Return} 5650 \subsection{ Return}
5054 \label{return} 5651 \LMLabel{return}
5055 5652
5653 \LMHash{}
5056 The {\em return statement} returns a result to the caller of a synchronous funct ion, completes the future associated with an asynchronous function or terminate s the stream or iterable associated with a generator (\ref{functions}). 5654 The {\em return statement} returns a result to the caller of a synchronous funct ion, completes the future associated with an asynchronous function or terminate s the stream or iterable associated with a generator (\ref{functions}).
5057 5655
5058 5656
5059 \begin{grammar} 5657 \begin{grammar}
5060 {\bf returnStatement:} 5658 {\bf returnStatement:}
5061 \RETURN{} expression? `{\escapegrammar ;}' % could do top level here 5659 \RETURN{} expression? `{\escapegrammar ;}' % could do top level here
5062 . 5660 .
5063 \end{grammar} 5661 \end{grammar}
5064 5662
5065 \commentary{ 5663 \commentary{
5066 Due to \FINALLY{} clauses, the precise behavior of \RETURN{} is a little more i nvolved. Whether the value a return statement is supposed to return is actually returned depends on the behavior of any \FINALLY{} clauses in effect when execut ing the return. A \FINALLY{} clause may choose to return another value, or throw an exception, or even redirect control flow leading to other returns or throws. All a return statement really does is set a value that is intended to be return ed when the function terminates. 5664 Due to \FINALLY{} clauses, the precise behavior of \RETURN{} is a little more i nvolved. Whether the value a return statement is supposed to return is actually returned depends on the behavior of any \FINALLY{} clauses in effect when execut ing the return. A \FINALLY{} clause may choose to return another value, or throw an exception, or even redirect control flow leading to other returns or throws. All a return statement really does is set a value that is intended to be return ed when the function terminates.
5067 } 5665 }
5068 5666
5667 \LMHash{}
5069 The {\em current return value} is a unique value specific to a given function ac tivation. It is undefined unless explicitly set in this specification. 5668 The {\em current return value} is a unique value specific to a given function ac tivation. It is undefined unless explicitly set in this specification.
5070 5669
5670 \LMHash{}
5071 Executing a return statement \code{\RETURN{} $e$;} proceeds as follows: 5671 Executing a return statement \code{\RETURN{} $e$;} proceeds as follows:
5072 5672
5673 \LMHash{}
5073 First the expression $e$ is evaluated, producing an object $o$. Next: 5674 First the expression $e$ is evaluated, producing an object $o$. Next:
5074 \begin{itemize} 5675 \begin{itemize}
5075 \item 5676 \item
5076 The current return value is set to $o$ and the current exception (\ref{throw}) a nd active stack trace (\ref{try}) become undefined. 5677 The current return value is set to $o$ and the current exception (\ref{throw}) a nd active stack trace (\ref{try}) become undefined.
5077 \item 5678 \item
5078 Let $c$ be the \FINALLY{} clause of the innermost enclosing try-finally statemen t (\ref{try}), if any. If $c$ is defined, let $h$ be the handler induced by $c$. If $h$ is defined, control is transferred to $h$. 5679 Let $c$ be the \FINALLY{} clause of the innermost enclosing try-finally statemen t (\ref{try}), if any. If $c$ is defined, let $h$ be the handler induced by $c$. If $h$ is defined, control is transferred to $h$.
5079 \item 5680 \item
5080 Otherwise execution of the current method terminates. 5681 Otherwise execution of the current method terminates.
5081 \end{itemize} 5682 \end{itemize}
5082 5683
5083 \commentary{ 5684 \commentary{
5084 In the simplest case, the immediately enclosing function is an ordinary, synchro nous non-generator, and upon function termination, the current return value is g iven to the caller. The other possibility is that the function is marked \ASYNC {}, in which case the current return value is used to complete the future associ ated with the function invocation. Both these scenarios are specified in section \ref{functionInvocation}. 5685 In the simplest case, the immediately enclosing function is an ordinary, synchro nous non-generator, and upon function termination, the current return value is g iven to the caller. The other possibility is that the function is marked \ASYNC {}, in which case the current return value is used to complete the future associ ated with the function invocation. Both these scenarios are specified in section \ref{functionInvocation}.
5085 The enclosing function cannot be marked as generator (i.e, \ASYNC* or \SYNC*), s ince generators are not allowed to contain a statement of the form \code{\RETURN {} $e$;} as discussed below. 5686 The enclosing function cannot be marked as generator (i.e, \ASYNC* or \SYNC*), s ince generators are not allowed to contain a statement of the form \code{\RETURN {} $e$;} as discussed below.
5086 } 5687 }
5087 5688
5689 \LMHash{}
5088 Let $T$ be the static type of $e$ and let $f$ be the immediately enclosing funct ion. 5690 Let $T$ be the static type of $e$ and let $f$ be the immediately enclosing funct ion.
5089 5691
5692 \LMHash{}
5090 It is a static type warning if the body of $f$ is marked \ASYNC{} and the type \ code{Future$<$flatten(T)$>$} (\ref{awaitExpressions}) may not be assigned to the declared return type of $f$. Otherwise, it is a static type warning if $T$ ma y not be assigned to the declared return type of $f$. 5693 It is a static type warning if the body of $f$ is marked \ASYNC{} and the type \ code{Future$<$flatten(T)$>$} (\ref{awaitExpressions}) may not be assigned to the declared return type of $f$. Otherwise, it is a static type warning if $T$ ma y not be assigned to the declared return type of $f$.
5091 5694
5695 \LMHash{}
5092 Let $S$ be the runtime type of $o$. In checked mode: 5696 Let $S$ be the runtime type of $o$. In checked mode:
5093 \begin{itemize} 5697 \begin{itemize}
5094 \item If the body of $f$ is marked \ASYNC{} (\ref{functions}) it is a dynamic t ype error if $o$ is not \NULL{} (\ref{null}) and \code{Future$<$S$>$} is not a s ubtype of the actual return type (\ref{actualTypeOfADeclaration}) of $f$. 5698 \item If the body of $f$ is marked \ASYNC{} (\ref{functions}) it is a dynamic t ype error if $o$ is not \NULL{} (\ref{null}) and \code{Future$<$S$>$} is not a s ubtype of the actual return type (\ref{actualTypeOfADeclaration}) of $f$.
5095 \item Otherwise, it is a dynamic type error if $o$ is not \NULL{} and the runtim e type of $o$ is not a subtype of the actual return type of $f$. 5699 \item Otherwise, it is a dynamic type error if $o$ is not \NULL{} and the runtim e type of $o$ is not a subtype of the actual return type of $f$.
5096 \end{itemize} 5700 \end{itemize}
5097 5701
5702 \LMHash{}
5098 It is a compile-time error if a return statement of the form \code{\RETURN{} $e$ ;} appears in a generative constructor (\ref{generativeConstructors}). 5703 It is a compile-time error if a return statement of the form \code{\RETURN{} $e$ ;} appears in a generative constructor (\ref{generativeConstructors}).
5099 5704
5100 \rationale{ 5705 \rationale{
5101 It is quite easy to forget to add the factory prefix for a constructor, accident ally converting a factory into a generative constructor. The static checker may detect a type mismatch in some, but not all, of these cases. The rule above help s catch such errors, which can otherwise be very hard to recognize. There is no real downside to it, as returning a value from a generative constructor is meani ngless. 5706 It is quite easy to forget to add the factory prefix for a constructor, accident ally converting a factory into a generative constructor. The static checker may detect a type mismatch in some, but not all, of these cases. The rule above help s catch such errors, which can otherwise be very hard to recognize. There is no real downside to it, as returning a value from a generative constructor is meani ngless.
5102 } 5707 }
5103 5708
5709 \LMHash{}
5104 It is a compile-time error if a return statement of the form \code{\RETURN{} $e$ ;} appears in a generator function. 5710 It is a compile-time error if a return statement of the form \code{\RETURN{} $e$ ;} appears in a generator function.
5105 5711
5106 \rationale{ 5712 \rationale{
5107 In the case of a generator function, the value returned by the function is the i terable or stream associated with it, and individual elements are added to that iterable using yield statements, and so returning a value makes no sense. 5713 In the case of a generator function, the value returned by the function is the i terable or stream associated with it, and individual elements are added to that iterable using yield statements, and so returning a value makes no sense.
5108 } 5714 }
5109 5715
5716 \LMHash{}
5110 Let $f$ be the function immediately enclosing a return statement of the form \RE TURN{}; It is a static warning $f$ is neither a generator nor a generative cons tructor and either: 5717 Let $f$ be the function immediately enclosing a return statement of the form \RE TURN{}; It is a static warning $f$ is neither a generator nor a generative cons tructor and either:
5111 \begin{itemize} 5718 \begin{itemize}
5112 \item $f$ is synchronous and the return type of $f$ may not be assigned to \VOI D{} (\ref{typeVoid}) or, 5719 \item $f$ is synchronous and the return type of $f$ may not be assigned to \VOI D{} (\ref{typeVoid}) or,
5113 \item $f$ is asynchronous and the return type of $f$ may not be assigned to \co de{Future$<$Null$>$}. 5720 \item $f$ is asynchronous and the return type of $f$ may not be assigned to \co de{Future$<$Null$>$}.
5114 \end{itemize} 5721 \end{itemize}
5115 5722
5116 \commentary{ 5723 \commentary{
5117 Hence, a static warning will not be issued if $f$ has no declared return type, s ince the return type would be \DYNAMIC{} and \DYNAMIC{} may be assigned to \VO ID{} and to \code{Future$<$Null$>$}. However, any synchronous non-generator func tion that declares a return type must return an expression explicitly. 5724 Hence, a static warning will not be issued if $f$ has no declared return type, s ince the return type would be \DYNAMIC{} and \DYNAMIC{} may be assigned to \VO ID{} and to \code{Future$<$Null$>$}. However, any synchronous non-generator func tion that declares a return type must return an expression explicitly.
5118 } 5725 }
5119 \rationale{This helps catch situations where users forget to return a value in a return statement.} 5726 \rationale{This helps catch situations where users forget to return a value in a return statement.}
5120 5727
5121 \rationale{ An asynchronous non-generator always returns a future of some sort. If no expression is given, the future will be completed with \NULL{} and this mo tivates the requirement above.} \commentary{Leaving the return type of a functio n marked \ASYNC{} blank will be interpreted as \DYNAMIC{} as always, and cause no type error. Using \code{Future} or \code{Future$<$Object$>$} is acceptable as well, but any other type will cause a warning, since \NULL{} has no subtypes.} 5728 \rationale{ An asynchronous non-generator always returns a future of some sort. If no expression is given, the future will be completed with \NULL{} and this mo tivates the requirement above.} \commentary{Leaving the return type of a functio n marked \ASYNC{} blank will be interpreted as \DYNAMIC{} as always, and cause no type error. Using \code{Future} or \code{Future$<$Object$>$} is acceptable as well, but any other type will cause a warning, since \NULL{} has no subtypes.}
5122 5729
5730 \LMHash{}
5123 A return statement with no expression, \code{\RETURN;} is executed as follows: 5731 A return statement with no expression, \code{\RETURN;} is executed as follows:
5124 5732
5733 \LMHash{}
5125 If the immediately enclosing function $f$ is a generator, then: 5734 If the immediately enclosing function $f$ is a generator, then:
5126 \begin{itemize} 5735 \begin{itemize}
5127 \item 5736 \item
5128 The current return value is set to \NULL{}. 5737 The current return value is set to \NULL{}.
5129 \item 5738 \item
5130 Let $c$ be the \FINALLY{} clause of the innermost enclosing try-finally statemen t, if any. If $c$ is defined, let $h$ be the handler induced by $c$. If $h$ is defined, control is transferred to $h$. 5739 Let $c$ be the \FINALLY{} clause of the innermost enclosing try-finally statemen t, if any. If $c$ is defined, let $h$ be the handler induced by $c$. If $h$ is defined, control is transferred to $h$.
5131 \item 5740 \item
5132 Otherwise, execution of the current method terminates. 5741 Otherwise, execution of the current method terminates.
5133 \end{itemize} 5742 \end{itemize}
5134 5743
5744 \LMHash{}
5135 Otherwise the return statement is executed by executing the statement \code{\RE TURN{} \NULL{};} if it occurs inside a method, getter, setter or factory; otherw ise, the return statement necessarily occurs inside a generative constructor, in which case it is executed by executing \code{\RETURN{} \THIS{};}. 5745 Otherwise the return statement is executed by executing the statement \code{\RE TURN{} \NULL{};} if it occurs inside a method, getter, setter or factory; otherw ise, the return statement necessarily occurs inside a generative constructor, in which case it is executed by executing \code{\RETURN{} \THIS{};}.
5136 5746
5137 \commentary{Despite the fact that \code{\RETURN{};} is executed as if by a \code {\RETURN{} $e$;}, it is important to understand that it is not a static warning to include a statement of the form \code{\RETURN{};} 5747 \commentary{Despite the fact that \code{\RETURN{};} is executed as if by a \code {\RETURN{} $e$;}, it is important to understand that it is not a static warning to include a statement of the form \code{\RETURN{};}
5138 %in a \VOID{} function; neither is it illegal 5748 %in a \VOID{} function; neither is it illegal
5139 in a generative constructor. The rules relate only to the specific syntactic for m \code{\RETURN{} $e$;}. 5749 in a generative constructor. The rules relate only to the specific syntactic for m \code{\RETURN{} $e$;}.
5140 } 5750 }
5141 5751
5142 5752
5143 \rationale{ 5753 \rationale{
5144 The motivation for formulating \code{\RETURN{};} in this way stems from the basi c requirement that all function invocations indeed return a value. Function invo cations are expressions, and we cannot rely on a mandatory typechecker to always prohibit use of \VOID{} functions in expressions. Hence, a return statement mus t always return a value, even if no expression is specified. 5754 The motivation for formulating \code{\RETURN{};} in this way stems from the basi c requirement that all function invocations indeed return a value. Function invo cations are expressions, and we cannot rely on a mandatory typechecker to always prohibit use of \VOID{} functions in expressions. Hence, a return statement mus t always return a value, even if no expression is specified.
5145 5755
5146 The question then becomes, what value should a return statement return when no r eturn expression is given. In a generative constructor, it is obviously the obje ct being constructed (\THIS{}). A void function is not expected to participate i n an expression, which is why it is marked \VOID{} in the first place. Hence, th is situation is a mistake which should be detected as soon as possible. The stat ic rules help here, but if the code is executed, using \NULL{} leads to fast fai lure, which is desirable in this case. The same rationale applies for function b odies that do not contain a return statement at all. 5756 The question then becomes, what value should a return statement return when no r eturn expression is given. In a generative constructor, it is obviously the obje ct being constructed (\THIS{}). A void function is not expected to participate i n an expression, which is why it is marked \VOID{} in the first place. Hence, th is situation is a mistake which should be detected as soon as possible. The stat ic rules help here, but if the code is executed, using \NULL{} leads to fast fai lure, which is desirable in this case. The same rationale applies for function b odies that do not contain a return statement at all.
5147 } 5757 }
5148 5758
5759 \LMHash{}
5149 It is a static warning if a function contains both one or more explicit return statements of the form \code{\RETURN;} and one or more return statements of the form \code{\RETURN{} $e$;}. 5760 It is a static warning if a function contains both one or more explicit return statements of the form \code{\RETURN;} and one or more return statements of the form \code{\RETURN{} $e$;}.
5150 5761
5151 5762
5152 5763
5153 5764
5154 \subsection{ Labels} 5765 \subsection{ Labels}
5155 \label{labels} 5766 \LMLabel{labels}
5156 5767
5768 \LMHash{}
5157 A {\em label} is an identifier followed by a colon. A {\em labeled statement} is a statement prefixed by a label $L$. A {\em labeled case clause} is a case cla use within a switch statement (\ref{switch}) prefixed by a label $L$. 5769 A {\em label} is an identifier followed by a colon. A {\em labeled statement} is a statement prefixed by a label $L$. A {\em labeled case clause} is a case cla use within a switch statement (\ref{switch}) prefixed by a label $L$.
5158 5770
5159 \rationale{The sole role of labels is to provide targets for the break (\ref{bre ak}) and continue (\ref{continue}) statements.} 5771 \rationale{The sole role of labels is to provide targets for the break (\ref{bre ak}) and continue (\ref{continue}) statements.}
5160 5772
5161 %\Q{Are labels in a separate namespace? Bug 49774299} 5773 %\Q{Are labels in a separate namespace? Bug 49774299}
5162 5774
5163 \begin{grammar} 5775 \begin{grammar}
5164 {\bf label:} 5776 {\bf label:}
5165 identifier `{\escapegrammar :}' 5777 identifier `{\escapegrammar :}'
5166 . 5778 .
5167 \end{grammar} 5779 \end{grammar}
5168 5780
5781 \LMHash{}
5169 The semantics of a labeled statement $L: s$ are identical to those of the state ment $s$. The namespace of labels is distinct from the one used for types, funct ions and variables. 5782 The semantics of a labeled statement $L: s$ are identical to those of the state ment $s$. The namespace of labels is distinct from the one used for types, funct ions and variables.
5170 5783
5784 \LMHash{}
5171 The scope of a label that labels a statement $s$ is $s$. The scope of a label th at labels a case clause of a switch statement $s$ is $s$. 5785 The scope of a label that labels a statement $s$ is $s$. The scope of a label th at labels a case clause of a switch statement $s$ is $s$.
5172 5786
5173 \rationale{Labels should be avoided by programmers at all costs. The motivation for including labels in the language is primarily making Dart a better target fo r code generation. 5787 \rationale{Labels should be avoided by programmers at all costs. The motivation for including labels in the language is primarily making Dart a better target fo r code generation.
5174 } 5788 }
5175 5789
5176 5790
5177 \subsection{ Break} 5791 \subsection{ Break}
5178 \label{break} 5792 \LMLabel{break}
5179 5793
5794 \LMHash{}
5180 The {\em break statement} consists of the reserved word \BREAK{} and an optional label (\ref{labels}). 5795 The {\em break statement} consists of the reserved word \BREAK{} and an optional label (\ref{labels}).
5181 5796
5182 \begin{grammar} 5797 \begin{grammar}
5183 {\bf breakStatement:} 5798 {\bf breakStatement:}
5184 \BREAK{} identifier? `{\escapegrammar ;}' 5799 \BREAK{} identifier? `{\escapegrammar ;}'
5185 . 5800 .
5186 \end{grammar} 5801 \end{grammar}
5187 5802
5803 \LMHash{}
5188 Let $s_b$ be a \BREAK{} statement. If $s_b$ is of the form \code{\BREAK{} $L$;} , then let $s_E$ be the the innermost labeled statement with label $L$ enclosing $s_b$. If $s_b$ is of the form \code{\BREAK{};}, then let $s_E$ be the the inn ermost \DO{} (\ref{do}), \FOR{} (\ref{for}), \SWITCH{} (\ref{switch}) or \WHILE {} (\ref{while}) statement enclosing $s_b$. It is a compile-time error if no su ch statement $s_E$ exists within the innermost function in which $s_b$ occurs. Furthermore, let $s_1, \ldots, s_n$ be those \TRY{} statements that are both en closed in $s_E$ and that enclose $s_b$, and that have a \FINALLY{} clause. Last ly, let $f_j$ be the \FINALLY{} clause of $s_j, 1 \le j \le n$. Executing $s_ b$ first executes $f_1, \ldots, f_n$ in innermost-clause-first order and then terminates $s_E$. 5804 Let $s_b$ be a \BREAK{} statement. If $s_b$ is of the form \code{\BREAK{} $L$;} , then let $s_E$ be the the innermost labeled statement with label $L$ enclosing $s_b$. If $s_b$ is of the form \code{\BREAK{};}, then let $s_E$ be the the inn ermost \DO{} (\ref{do}), \FOR{} (\ref{for}), \SWITCH{} (\ref{switch}) or \WHILE {} (\ref{while}) statement enclosing $s_b$. It is a compile-time error if no su ch statement $s_E$ exists within the innermost function in which $s_b$ occurs. Furthermore, let $s_1, \ldots, s_n$ be those \TRY{} statements that are both en closed in $s_E$ and that enclose $s_b$, and that have a \FINALLY{} clause. Last ly, let $f_j$ be the \FINALLY{} clause of $s_j, 1 \le j \le n$. Executing $s_ b$ first executes $f_1, \ldots, f_n$ in innermost-clause-first order and then terminates $s_E$.
5189 5805
5806 \LMHash{}
5190 If $s_E$ is an asynchronous for loop (\ref{asynchronousFor-in}), its associated stream subscription is canceled. Furthermore, let $a_k$ be the set of asynchrono us for loops and yield-each statements (\ref{yieldEach}) enclosing $s_b$ that a re enclosed in $s_E , 1 \le k \le m$. The stream subscriptions associated with $a_j$ are canceled, $1 \le j \le m$. 5807 If $s_E$ is an asynchronous for loop (\ref{asynchronousFor-in}), its associated stream subscription is canceled. Furthermore, let $a_k$ be the set of asynchrono us for loops and yield-each statements (\ref{yieldEach}) enclosing $s_b$ that a re enclosed in $s_E , 1 \le k \le m$. The stream subscriptions associated with $a_j$ are canceled, $1 \le j \le m$.
5191 5808
5192 5809
5193 5810
5194 \subsection{ Continue} 5811 \subsection{ Continue}
5195 \label{continue} 5812 \LMLabel{continue}
5196 5813
5814 \LMHash{}
5197 The {\em continue statement} consists of the reserved word \CONTINUE{} and an op tional label (\ref{labels}). 5815 The {\em continue statement} consists of the reserved word \CONTINUE{} and an op tional label (\ref{labels}).
5198 5816
5199 \begin{grammar} 5817 \begin{grammar}
5200 {\bf continueStatement:} 5818 {\bf continueStatement:}
5201 \CONTINUE{} identifier? `{\escapegrammar ;}' 5819 \CONTINUE{} identifier? `{\escapegrammar ;}'
5202 . 5820 .
5203 \end{grammar} 5821 \end{grammar}
5204 5822
5823 \LMHash{}
5205 Let $s_c$ be a \CONTINUE{} statement. If $s_c$ is of the form \code{\CONTINUE{ } $L$;}, then let $s_E$ be the the innermost labeled \DO{} (\ref{do}), \FOR{} (\ ref{for}) or \WHILE{} (\ref{while}) statement or case clause with label $L$ encl osing $s_c$. If $s_c$ is of the form \code{\CONTINUE{};} then let $s_E$ be the the innermost \DO{} (\ref{do}), \FOR{} (\ref{for}) or \WHILE{} (\ref{while}) st atement enclosing $s_c$. It is a compile-time error if no such statement or cas e clause $s_E$ exists within the innermost function in which $s_c$ occurs. Fur thermore, let $s_1, \ldots, s_n$ be those \TRY{} statements that are both enclos ed in $s_E$ and that enclose $s_c$, and that have a \FINALLY{} clause. Lastly, let $f_j$ be the \FINALLY{} clause of $s_j, 1 \le j \le n$. Executing $s_c$ f irst executes $f_1, \ldots, f_n$ in innermost-clause-first order. Then, if $s_ E$ is a case clause, control is transferred to the case clause. Otherwise, $s_E$ is necessarily a loop and execution resumes after the last statement in the loo p body. 5824 Let $s_c$ be a \CONTINUE{} statement. If $s_c$ is of the form \code{\CONTINUE{ } $L$;}, then let $s_E$ be the the innermost labeled \DO{} (\ref{do}), \FOR{} (\ ref{for}) or \WHILE{} (\ref{while}) statement or case clause with label $L$ encl osing $s_c$. If $s_c$ is of the form \code{\CONTINUE{};} then let $s_E$ be the the innermost \DO{} (\ref{do}), \FOR{} (\ref{for}) or \WHILE{} (\ref{while}) st atement enclosing $s_c$. It is a compile-time error if no such statement or cas e clause $s_E$ exists within the innermost function in which $s_c$ occurs. Fur thermore, let $s_1, \ldots, s_n$ be those \TRY{} statements that are both enclos ed in $s_E$ and that enclose $s_c$, and that have a \FINALLY{} clause. Lastly, let $f_j$ be the \FINALLY{} clause of $s_j, 1 \le j \le n$. Executing $s_c$ f irst executes $f_1, \ldots, f_n$ in innermost-clause-first order. Then, if $s_ E$ is a case clause, control is transferred to the case clause. Otherwise, $s_E$ is necessarily a loop and execution resumes after the last statement in the loo p body.
5206 5825
5207 \commentary{ 5826 \commentary{
5208 In a while loop, that would be the boolean expression before the body. In a do loop, it would be the boolean expression after the body. In a for loop, it would be the increment clause. In other words, execution continues to the next itera tion of the loop. 5827 In a while loop, that would be the boolean expression before the body. In a do loop, it would be the boolean expression after the body. In a for loop, it would be the increment clause. In other words, execution continues to the next itera tion of the loop.
5209 } 5828 }
5210 5829
5830 \LMHash{}
5211 If $s_E$ is an asynchronous for loop (\ref{asynchronousFor-in}), let $a_k$ be t he set of asynchronous for loops and yield-each statements (\ref{yieldEach}) enc losing $s_c$ that are enclosed in $s_E , 1 \le k \le m$. The stream subscripti ons associated with $a_j$ are canceled, $1 \le j \le m$. 5831 If $s_E$ is an asynchronous for loop (\ref{asynchronousFor-in}), let $a_k$ be t he set of asynchronous for loops and yield-each statements (\ref{yieldEach}) enc losing $s_c$ that are enclosed in $s_E , 1 \le k \le m$. The stream subscripti ons associated with $a_j$ are canceled, $1 \le j \le m$.
5212 5832
5213 \subsection{ Yield and Yield-Each} 5833 \subsection{ Yield and Yield-Each}
5214 \label{yieldAndYieldEach} 5834 \LMLabel{yieldAndYieldEach}
5215 5835
5216 \subsubsection{ Yield} 5836 \subsubsection{ Yield}
5217 \label{yield} 5837 \LMLabel{yield}
5218 5838
5839 \LMHash{}
5219 The {\em yield statement} adds an element to the result of a generator function (\ref{functions}). 5840 The {\em yield statement} adds an element to the result of a generator function (\ref{functions}).
5220 5841
5221 \begin{grammar} 5842 \begin{grammar}
5222 {\bf yieldStatement:} 5843 {\bf yieldStatement:}
5223 \YIELD{} expression `{\escapegrammar ;}' 5844 \YIELD{} expression `{\escapegrammar ;}'
5224 . 5845 .
5225 \end{grammar} 5846 \end{grammar}
5226 5847
5848 \LMHash{}
5227 Execution of a statement $s$ of the form \code{\YIELD{} $e$;} proceeds as follo ws: 5849 Execution of a statement $s$ of the form \code{\YIELD{} $e$;} proceeds as follo ws:
5228 5850
5851 \LMHash{}
5229 First, the expression $e$ is evaluated to an object $o$. If the enclosing functi on $m$ is marked \ASYNC* (\ref{functions}) and the stream $u$ associated with $m $ has been paused, then execution of $m$ is suspended until $u$ is resumed or c anceled. 5852 First, the expression $e$ is evaluated to an object $o$. If the enclosing functi on $m$ is marked \ASYNC* (\ref{functions}) and the stream $u$ associated with $m $ has been paused, then execution of $m$ is suspended until $u$ is resumed or c anceled.
5230 5853
5854 \LMHash{}
5231 Next, $o$ is added to the iterable or stream associated with the immediately enc losing function. 5855 Next, $o$ is added to the iterable or stream associated with the immediately enc losing function.
5232 5856
5857 \LMHash{}
5233 If the enclosing function $m$ is marked \ASYNC* and the stream $u$ associated wi th $m$ has been canceled, then let $c$ be the \FINALLY{} clause (\ref{try}) of t he innermost enclosing try-finally statement, if any. If $c$ is defined, let $h$ be the handler induced by $c$. If $h$ is defined, control is transferred to $h$ . If $h$ is undefined, the immediately enclosing function terminates. 5858 If the enclosing function $m$ is marked \ASYNC* and the stream $u$ associated wi th $m$ has been canceled, then let $c$ be the \FINALLY{} clause (\ref{try}) of t he innermost enclosing try-finally statement, if any. If $c$ is defined, let $h$ be the handler induced by $c$. If $h$ is defined, control is transferred to $h$ . If $h$ is undefined, the immediately enclosing function terminates.
5234 5859
5235 \rationale{ 5860 \rationale{
5236 The stream associated with an asynchronous generator could be canceled by any co de with a reference to that stream at any point where the generator was passivat ed. Such a cancellation constitutes an irretrievable error for the generator. A t this point, the only plausible action for the generator is to clean up after i tself via its \FINALLY{} clauses. 5861 The stream associated with an asynchronous generator could be canceled by any co de with a reference to that stream at any point where the generator was passivat ed. Such a cancellation constitutes an irretrievable error for the generator. A t this point, the only plausible action for the generator is to clean up after i tself via its \FINALLY{} clauses.
5237 } 5862 }
5238 5863
5864 \LMHash{}
5239 If the enclosing function $m$ is marked \SYNC* (\ref{functions}) then: 5865 If the enclosing function $m$ is marked \SYNC* (\ref{functions}) then:
5240 \begin{itemize} 5866 \begin{itemize}
5241 \item 5867 \item
5242 Execution of the function $m$ immediately enclosing $s$ is suspended until the m ethod \code{moveNext()} is invoked upon the iterator used to initiate the curren t invocation of $m$. 5868 Execution of the function $m$ immediately enclosing $s$ is suspended until the m ethod \code{moveNext()} is invoked upon the iterator used to initiate the curren t invocation of $m$.
5243 \item 5869 \item
5244 The current call to \code{moveNext()} returns \TRUE. 5870 The current call to \code{moveNext()} returns \TRUE.
5245 \end{itemize} 5871 \end{itemize}
5246 5872
5873 \LMHash{}
5247 It is a compile-time error if a yield statement appears in a function that is no t a generator function. 5874 It is a compile-time error if a yield statement appears in a function that is no t a generator function.
5248 5875
5876 \LMHash{}
5249 Let $T$ be the static type of $e$ and let $f$ be the immediately enclosing funct ion. It is a static type warning if either: 5877 Let $T$ be the static type of $e$ and let $f$ be the immediately enclosing funct ion. It is a static type warning if either:
5250 \begin{itemize} 5878 \begin{itemize}
5251 \item 5879 \item
5252 the body of $f$ is marked \ASYNC* and the type \code{Stream$<$T$>$} may not be assigned to the declared return type of $f$. 5880 the body of $f$ is marked \ASYNC* and the type \code{Stream$<$T$>$} may not be assigned to the declared return type of $f$.
5253 \item 5881 \item
5254 the body of $f$ is marked \SYNC* and the type \code{Iterable$<$T$>$} may not be assigned to the declared return type of $f$. 5882 the body of $f$ is marked \SYNC* and the type \code{Iterable$<$T$>$} may not be assigned to the declared return type of $f$.
5255 \end{itemize} 5883 \end{itemize}
5256 5884
5257 5885
5258 \subsubsection{ Yield-Each} 5886 \subsubsection{ Yield-Each}
5259 \label{yieldEach} 5887 \LMLabel{yieldEach}
5260 5888
5889 \LMHash{}
5261 The {\em yield-each statement} adds a series of values to the result of a gener ator function (\ref{functions}). 5890 The {\em yield-each statement} adds a series of values to the result of a gener ator function (\ref{functions}).
5262 5891
5263 \begin{grammar} 5892 \begin{grammar}
5264 {\bf yieldEachStatement:} 5893 {\bf yieldEachStatement:}
5265 \YIELD* expression `{\escapegrammar ;}' 5894 \YIELD* expression `{\escapegrammar ;}'
5266 . 5895 .
5267 \end{grammar} 5896 \end{grammar}
5268 5897
5898 \LMHash{}
5269 Execution of a statement s of the form \code{\YIELD* $e$;} proceeds as follows: 5899 Execution of a statement s of the form \code{\YIELD* $e$;} proceeds as follows:
5270 5900
5901 \LMHash{}
5271 First, the expression $e$ is evaluated to an object $o$. If the immediately encl osing function $m$ is synchronous, then it is a dynamic error if the class of $o $ does not implement \code{Iterable}. If $m$ asynchronous, then it is a dynamic error if the class of $o$ does not implement \code{Stream}. Next, for each elem ent $x$ of $o$: 5902 First, the expression $e$ is evaluated to an object $o$. If the immediately encl osing function $m$ is synchronous, then it is a dynamic error if the class of $o $ does not implement \code{Iterable}. If $m$ asynchronous, then it is a dynamic error if the class of $o$ does not implement \code{Stream}. Next, for each elem ent $x$ of $o$:
5272 \begin{itemize} 5903 \begin{itemize}
5273 \item 5904 \item
5274 If $m$ is marked \ASYNC* (\ref{functions}) and the stream $u$ associated with $m $ has been paused, then execution of $m$ is suspended until $u$ is resumed or c anceled. 5905 If $m$ is marked \ASYNC* (\ref{functions}) and the stream $u$ associated with $m $ has been paused, then execution of $m$ is suspended until $u$ is resumed or c anceled.
5275 \item 5906 \item
5276 $x$ is added to the iterable or stream associated with $m$ in the order it appe ars in $o$. 5907 $x$ is added to the iterable or stream associated with $m$ in the order it appe ars in $o$.
5277 \item 5908 \item
5278 If $m$ is marked \ASYNC* and the stream $u$ associated with $m$ has been cancele d, then let $c$ be the \FINALLY{} clause (\ref{try}) of the innermost enclosing try-finally statement, if any. If $c$ is defined, let $h$ be the handler induce d by $c$. If $h$ is defined, control is transferred to $h$. If $h$ is undefined, the immediately enclosing function terminates. 5909 If $m$ is marked \ASYNC* and the stream $u$ associated with $m$ has been cancele d, then let $c$ be the \FINALLY{} clause (\ref{try}) of the innermost enclosing try-finally statement, if any. If $c$ is defined, let $h$ be the handler induce d by $c$. If $h$ is defined, control is transferred to $h$. If $h$ is undefined, the immediately enclosing function terminates.
5279 \end{itemize} 5910 \end{itemize}
5280 5911
5912 \LMHash{}
5281 If the enclosing function is marked \SYNC* (\ref{functions}) then: 5913 If the enclosing function is marked \SYNC* (\ref{functions}) then:
5282 \begin{itemize} 5914 \begin{itemize}
5283 \item 5915 \item
5284 Execution of the function $m$ immediately enclosing $s$ is suspended until the m ethod \code{moveNext()} is invoked upon the iterator used to initiate the curren t invocation of $m$. 5916 Execution of the function $m$ immediately enclosing $s$ is suspended until the m ethod \code{moveNext()} is invoked upon the iterator used to initiate the curren t invocation of $m$.
5285 \item 5917 \item
5286 The current call to \code{moveNext()} returns \TRUE. 5918 The current call to \code{moveNext()} returns \TRUE.
5287 \end{itemize} 5919 \end{itemize}
5288 5920
5921 \LMHash{}
5289 It is a compile-time error if a yield-each statement appears in a function that is not a generator function. 5922 It is a compile-time error if a yield-each statement appears in a function that is not a generator function.
5290 5923
5924 \LMHash{}
5291 Let $T$ be the static type of $e$ and let $f$ be the immediately enclosing funct ion. It is a static type warning if $T$ may not be assigned to the declared ret urn type of $f$. 5925 Let $T$ be the static type of $e$ and let $f$ be the immediately enclosing funct ion. It is a static type warning if $T$ may not be assigned to the declared ret urn type of $f$.
5292 5926
5293 5927
5294 \subsection{ Assert} 5928 \subsection{ Assert}
5295 \label{assert} 5929 \LMLabel{assert}
5296 5930
5931 \LMHash{}
5297 An {\em assert statement} is used to disrupt normal execution if a given boolean condition does not hold. 5932 An {\em assert statement} is used to disrupt normal execution if a given boolean condition does not hold.
5298 5933
5299 \begin{grammar} 5934 \begin{grammar}
5300 {\bf assertStatement:} 5935 {\bf assertStatement:}
5301 assert `(' conditionalExpression `)' `{\escapegrammar ;}' 5936 assert `(' conditionalExpression `)' `{\escapegrammar ;}'
5302 . 5937 .
5303 \end{grammar} 5938 \end{grammar}
5304 5939
5940 \LMHash{}
5305 The assert statement has no effect in production mode. In checked mode, executio n of an assert statement \code{\ASSERT{}($e$);} proceeds as follows: 5941 The assert statement has no effect in production mode. In checked mode, executio n of an assert statement \code{\ASSERT{}($e$);} proceeds as follows:
5306 5942
5943 \LMHash{}
5307 The conditional expression $e$ is evaluated to an object $o$. If the class of $o $ is a subtype of \code{Function} then let $r$ be the result of invoking $o$ wit h no arguments. Otherwise, let $r$ be $o$. 5944 The conditional expression $e$ is evaluated to an object $o$. If the class of $o $ is a subtype of \code{Function} then let $r$ be the result of invoking $o$ wit h no arguments. Otherwise, let $r$ be $o$.
5308 It is a dynamic type error if $o$ is not of type \code{bool} or of type \code{Fu nction}, or if $r$ is not of type \code{bool}. If $r$ is \FALSE{}, we say that the assertion failed. If $r$ is \TRUE{}, we say that the assertion succeeded. If the assertion succeeded, execution of the assert statement is complete. If the assertion failed, an \code{AssertionError} is thrown. 5945 It is a dynamic type error if $o$ is not of type \code{bool} or of type \code{Fu nction}, or if $r$ is not of type \code{bool}. If $r$ is \FALSE{}, we say that the assertion failed. If $r$ is \TRUE{}, we say that the assertion succeeded. If the assertion succeeded, execution of the assert statement is complete. If the assertion failed, an \code{AssertionError} is thrown.
5309 5946
5310 %\Q{Might be cleaner to define it as \code{if (!$e$) \{\THROW{} \NEW{} Assertion Error();\}} (in checked mode only). 5947 %\Q{Might be cleaner to define it as \code{if (!$e$) \{\THROW{} \NEW{} Assertion Error();\}} (in checked mode only).
5311 %What about an error message as part of the assert?} 5948 %What about an error message as part of the assert?}
5312 5949
5950 \LMHash{}
5313 It is a static type warning if the type of $e$ may not be assigned to either \ code{bool} or $() \rightarrow$ \code{bool}. 5951 It is a static type warning if the type of $e$ may not be assigned to either \ code{bool} or $() \rightarrow$ \code{bool}.
5314 5952
5315 \rationale{Why is this a statement, not a built in function call? Because it is handled magically so it has no effect and no overhead in production mode. Also, in the absence of final methods. one could not prevent it being overridden (thou gh there is no real harm in that). It cannot be viewed as a function call that is being optimized away because the argument might have side effects. 5953 \rationale{Why is this a statement, not a built in function call? Because it is handled magically so it has no effect and no overhead in production mode. Also, in the absence of final methods. one could not prevent it being overridden (thou gh there is no real harm in that). It cannot be viewed as a function call that is being optimized away because the argument might have side effects.
5316 } 5954 }
5317 5955
5318 %If a lexically visible declaration named \code{assert} is in scope, an assert s tatement 5956 %If a lexically visible declaration named \code{assert} is in scope, an assert s tatement
5319 %\code{\ASSERT{} (e); } 5957 %\code{\ASSERT{} (e); }
5320 %is interpreted as an expression statement \code{(assert(e));} . 5958 %is interpreted as an expression statement \code{(assert(e));} .
5321 5959
5322 %\rationale{ 5960 %\rationale{
5323 %Since \ASSERT{} is a built-in identifier, one might define a function or method with this name. 5961 %Since \ASSERT{} is a built-in identifier, one might define a function or method with this name.
5324 %It is impossible to distinguish as \ASSERT{} statement from a method invocation in such a situation. 5962 %It is impossible to distinguish as \ASSERT{} statement from a method invocation in such a situation.
5325 %One could choose to always interpret such code as an \ASSERT{} statement. Or we could choose to give priority to any lexically visible user defined function. The former can cause rather puzzling situations, e.g.,} 5963 %One could choose to always interpret such code as an \ASSERT{} statement. Or we could choose to give priority to any lexically visible user defined function. The former can cause rather puzzling situations, e.g.,}
5326 5964
5327 %\begin{dartCode} 5965 %\begin{dartCode}
5328 % assert(bool b)\{print('My Personal Assertion \$b');\} 5966 % assert(bool b)\{print('My Personal Assertion \$b');\}
5329 5967
5330 % assert\_puzzler() \{ 5968 % assert\_puzzler() \{
5331 % (assert(\TRUE{})); // prints true 5969 % (assert(\TRUE{})); // prints true
5332 % assert(\TRUE{}); // would do nothing 5970 % assert(\TRUE{}); // would do nothing
5333 % (assert(\FALSE{})); // prints false 5971 % (assert(\FALSE{})); // prints false
5334 % assert(\FALSE{}); // would throw if asserts enabled, or do nothing otherwise 5972 % assert(\FALSE{}); // would throw if asserts enabled, or do nothing otherwise
5335 % \} 5973 % \}
5336 5974
5337 %\end{dartCode} 5975 %\end{dartCode}
5338 5976
5339 %\rationale{therefore, we opt for the second option. Alternately, one could insi st that assert be a reserved word, which may have an undesirable effect with res pect to compatibility of Javascript code ported to Dart.} 5977 %\rationale{therefore, we opt for the second option. Alternately, one could insi st that assert be a reserved word, which may have an undesirable effect with res pect to compatibility of Javascript code ported to Dart.}
5340 5978
5341 \section{Libraries and Scripts} 5979 \section{Libraries and Scripts}
5342 \label{librariesAndScripts} 5980 \LMLabel{librariesAndScripts}
5343 5981
5982 \LMHash{}
5344 A Dart program consists of one or more libraries, and may be built out of one or more {\em compilation units}. A compilation unit may be a library or a part (\r ef{parts}). 5983 A Dart program consists of one or more libraries, and may be built out of one or more {\em compilation units}. A compilation unit may be a library or a part (\r ef{parts}).
5345 5984
5985 \LMHash{}
5346 A library consists of (a possibly empty) set of imports, a set of exports, and a set of top-level declarations. A top-level declaration is either a class (\ref {classes}), a type alias declaration (\ref{typedef}), a function (\ref{functions }) or a variable declaration (\ref{variables}). The members of a library $L$ are those top level declarations given within $L$. 5986 A library consists of (a possibly empty) set of imports, a set of exports, and a set of top-level declarations. A top-level declaration is either a class (\ref {classes}), a type alias declaration (\ref{typedef}), a function (\ref{functions }) or a variable declaration (\ref{variables}). The members of a library $L$ are those top level declarations given within $L$.
5347 5987
5348 \begin{grammar} 5988 \begin{grammar}
5349 {\bf topLevelDefinition:}classDefinition; 5989 {\bf topLevelDefinition:}classDefinition;
5350 enumType; 5990 enumType;
5351 % classDefinitionOrInterfaceInjection; 5991 % classDefinitionOrInterfaceInjection;
5352 % interfaceDefinitionOrInterfaceInjection; 5992 % interfaceDefinitionOrInterfaceInjection;
5353 % mixinApplication; 5993 % mixinApplication;
5354 typeAlias; 5994 typeAlias;
5355 \EXTERNAL{}? functionSignature `{\escapegrammar ;}'; 5995 \EXTERNAL{}? functionSignature `{\escapegrammar ;}';
(...skipping 30 matching lines...) Expand all
5386 . 6026 .
5387 6027
5388 {\bf libraryName:} 6028 {\bf libraryName:}
5389 metadata \LIBRARY{} identifier (`{\escapegrammar .}' identifier)* `{\escapegr ammar ;}' 6029 metadata \LIBRARY{} identifier (`{\escapegrammar .}' identifier)* `{\escapegr ammar ;}'
5390 . 6030 .
5391 6031
5392 {\bf importOrExport:}libraryImport ; 6032 {\bf importOrExport:}libraryImport ;
5393 libraryExport 6033 libraryExport
5394 \end{grammar} 6034 \end{grammar}
5395 6035
6036 \LMHash{}
5396 Libraries may be {\em explicitly named} or {\em implicitly named}. An explicitl y named library begins with the word \LIBRARY{} (possibly prefaced with any ap plicable metadata annotations), followed by a qualified identifier that gives th e name of the library. 6037 Libraries may be {\em explicitly named} or {\em implicitly named}. An explicitl y named library begins with the word \LIBRARY{} (possibly prefaced with any ap plicable metadata annotations), followed by a qualified identifier that gives th e name of the library.
5397 6038
5398 \commentary{ 6039 \commentary{
5399 Technically, each dot and identifier is a separate token and so spaces between them are acceptable. However, the actual library name is the concatenation of th e simple identifiers and dots and contains no spaces. 6040 Technically, each dot and identifier is a separate token and so spaces between them are acceptable. However, the actual library name is the concatenation of th e simple identifiers and dots and contains no spaces.
5400 } 6041 }
5401 6042
6043 \LMHash{}
5402 An implicitly named library has the empty string as its name. 6044 An implicitly named library has the empty string as its name.
5403 6045
5404 \rationale{ 6046 \rationale{
5405 The name of a library is used to tie it to separately compiled parts of the libr ary (called parts) and can be used for printing and, more generally, reflection . The name may be relevant for further language evolution. 6047 The name of a library is used to tie it to separately compiled parts of the libr ary (called parts) and can be used for printing and, more generally, reflection . The name may be relevant for further language evolution.
5406 } 6048 }
5407 6049
5408 \commentary{ 6050 \commentary{
5409 Libraries intended for widespread use should avoid name collisions. Dart's \cod e{pub} package management system provides a mechanism for doing so. Each pub pa ckage is guaranteed a unique name, effectively enforcing a global namespace. 6051 Libraries intended for widespread use should avoid name collisions. Dart's \cod e{pub} package management system provides a mechanism for doing so. Each pub pa ckage is guaranteed a unique name, effectively enforcing a global namespace.
5410 } 6052 }
5411 6053
6054 \LMHash{}
5412 A library may optionally begin with a {\em script tag}. Script tags are intende d for use with scripts (\ref{scripts}). A script tag can be used to identify th e interpreter of the script to whatever computing environment the script is embe dded in. The script tag must appear before any whitespace or comments. A script tag begins with the characters \#! and ends at the end of the line. Any charac ters that follow \#! in the script tag are ignored by the Dart implementation. 6055 A library may optionally begin with a {\em script tag}. Script tags are intende d for use with scripts (\ref{scripts}). A script tag can be used to identify th e interpreter of the script to whatever computing environment the script is embe dded in. The script tag must appear before any whitespace or comments. A script tag begins with the characters \#! and ends at the end of the line. Any charac ters that follow \#! in the script tag are ignored by the Dart implementation.
5413 6056
6057 \LMHash{}
5414 Libraries are units of privacy. A private declaration declared within a library $L$ can only be accessed by code within $L$. Any attempt to access a private mem ber declaration from outside $L$ will cause a method, getter or setter lookup fa ilure. 6058 Libraries are units of privacy. A private declaration declared within a library $L$ can only be accessed by code within $L$. Any attempt to access a private mem ber declaration from outside $L$ will cause a method, getter or setter lookup fa ilure.
5415 6059
5416 \commentary{Since top level privates are not imported, using the top level priva tes of another library is never possible. } 6060 \commentary{Since top level privates are not imported, using the top level priva tes of another library is never possible. }
5417 6061
6062 \LMHash{}
5418 The {\em public namespace} of library $L$ is the mapping that maps the simple na me of each public top-level member $m$ of $L$ to $m$. 6063 The {\em public namespace} of library $L$ is the mapping that maps the simple na me of each public top-level member $m$ of $L$ to $m$.
5419 The scope of a library $L$ consists of the names introduced by all top-level dec larations declared in $L$, and the names added by $L$'s imports (\ref{imports}). 6064 The scope of a library $L$ consists of the names introduced by all top-level dec larations declared in $L$, and the names added by $L$'s imports (\ref{imports}).
5420 6065
5421 6066
5422 \subsection{Imports} 6067 \subsection{Imports}
5423 \label{imports} 6068 \LMLabel{imports}
5424 6069
6070 \LMHash{}
5425 An {\em import} specifies a library to be used in the scope of another library. 6071 An {\em import} specifies a library to be used in the scope of another library.
5426 \begin{grammar} 6072 \begin{grammar}
5427 {\bf libraryImport:} 6073 {\bf libraryImport:}
5428 metadata importSpecification 6074 metadata importSpecification
5429 . 6075 .
5430 6076
5431 {\bf importSpecification:} 6077 {\bf importSpecification:}
5432 \IMPORT{} uri (\AS{} identifier)? combinator* `{\escapegrammar ;}'; 6078 \IMPORT{} uri (\AS{} identifier)? combinator* `{\escapegrammar ;}';
5433 \IMPORT{} uri \DEFERRED{} \AS{} identifier combinator* `{\escapegrammar ; }' 6079 \IMPORT{} uri \DEFERRED{} \AS{} identifier combinator* `{\escapegrammar ; }'
5434 . 6080 .
5435 6081
5436 {\bf combinator:}\SHOW{} identifierList; 6082 {\bf combinator:}\SHOW{} identifierList;
5437 \HIDE{} identifierList 6083 \HIDE{} identifierList
5438 . 6084 .
5439 6085
5440 {\bf identifierList:} 6086 {\bf identifierList:}
5441 identifier (, identifier)* 6087 identifier (, identifier)*
5442 \end{grammar} 6088 \end{grammar}
5443 6089
5444 6090
6091 \LMHash{}
5445 An import specifies a URI $x$ where the declaration of an imported library is to be found. 6092 An import specifies a URI $x$ where the declaration of an imported library is to be found.
5446 6093
6094 \LMHash{}
5447 Imports may be {\em deferred} or {\em immediate}. A deferred import is distingui shed by the appearance of the built-in identifier \DEFERRED{} after the URI. Any import that is not deferred is immediate. 6095 Imports may be {\em deferred} or {\em immediate}. A deferred import is distingui shed by the appearance of the built-in identifier \DEFERRED{} after the URI. Any import that is not deferred is immediate.
5448 6096
6097 \LMHash{}
5449 It is a compile-time error if the specified URI of an immediate import does not refer to a library declaration. The interpretation of URIs is described in sec tion \ref{uris} below. 6098 It is a compile-time error if the specified URI of an immediate import does not refer to a library declaration. The interpretation of URIs is described in sec tion \ref{uris} below.
5450 6099
6100 \LMHash{}
5451 It is a static warning if the specified URI of a deferred import does not refer to a library declaration. 6101 It is a static warning if the specified URI of a deferred import does not refer to a library declaration.
5452 6102
5453 \rationale{ 6103 \rationale{
5454 One cannot detect the problem at compile time because compilation often occurs during execution and one does not know what the URI refers to. However the dev elopment environment should detect the problem. 6104 One cannot detect the problem at compile time because compilation often occurs during execution and one does not know what the URI refers to. However the dev elopment environment should detect the problem.
5455 } 6105 }
5456 6106
5457 6107
6108 \LMHash{}
5458 The {\em current library} is the library currently being compiled. The import mo difies the namespace of the current library in a manner that is determined by t he imported library and by the optional elements of the import. 6109 The {\em current library} is the library currently being compiled. The import mo difies the namespace of the current library in a manner that is determined by t he imported library and by the optional elements of the import.
5459 6110
6111 \LMHash{}
5460 An immediate import directive $I$ may optionally include a prefix clause of the form \AS{} \code{Id} used to prefix names imported by $I$. A deferred import mus t include a prefix clause or a compile time error occurs. It is a compile-time e rror if a prefix used in a deferred import is used in another import clause. 6112 An immediate import directive $I$ may optionally include a prefix clause of the form \AS{} \code{Id} used to prefix names imported by $I$. A deferred import mus t include a prefix clause or a compile time error occurs. It is a compile-time e rror if a prefix used in a deferred import is used in another import clause.
5461 6113
6114 \LMHash{}
5462 An import directive $I$ may optionally include a namespace combinator clauses us ed to restrict the set of names imported by $I$. Currently, two namespace combin ators are supported: \HIDE{} and \SHOW{}. 6115 An import directive $I$ may optionally include a namespace combinator clauses us ed to restrict the set of names imported by $I$. Currently, two namespace combin ators are supported: \HIDE{} and \SHOW{}.
5463 6116
6117 \LMHash{}
5464 Let $I$ be an import directive that refers to a URI via the string $s_1$. Evalua tion of $I$ proceeds as follows: 6118 Let $I$ be an import directive that refers to a URI via the string $s_1$. Evalua tion of $I$ proceeds as follows:
5465 6119
6120 \LMHash{}
5466 If $I$ is a deferred import, no evaluation takes place. Instead, an mapping the name of the prefix, $p$ to a {\em deferred prefix object} is added to the scope of $L$. 6121 If $I$ is a deferred import, no evaluation takes place. Instead, an mapping the name of the prefix, $p$ to a {\em deferred prefix object} is added to the scope of $L$.
5467 The deferred prefix object has the following methods: 6122 The deferred prefix object has the following methods:
5468 6123
5469 \begin{itemize} 6124 \begin{itemize}
5470 \item \code{loadLibrary}. This method returns a future $f$. When called, the met hod causes an immediate import $IÕ$ to be executed at some future time, where $I Õ$ is is derived from $I$ by eliding the word \DEFERRED{} and adding a \HIDE{} \ code{loadLibrary} combinator clause. When $IÕ$ executes without error, $f$ comp letes successfully. If $IÕ$ executes without error, we say that the call to \cod e{loadLibrary} has succeeded, otherwise we say the call has failed. 6125 \item \code{loadLibrary}. This method returns a future $f$. When called, the met hod causes an immediate import $I'$ to be executed at some future time, where $I '$ is is derived from $I$ by eliding the word \DEFERRED{} and adding a \HIDE{} \ code{loadLibrary} combinator clause. When $I'$ executes without error, $f$ comp letes successfully. If $I'$ executes without error, we say that the call to \cod e{loadLibrary} has succeeded, otherwise we say the call has failed.
5471 \item For every top level function $f$ named $id$ in $L$, a corresponding metho d named $id$ with the same signature as $f$. Calling the method results in a run time error. 6126 \item For every top level function $f$ named $id$ in $L$, a corresponding metho d named $id$ with the same signature as $f$. Calling the method results in a run time error.
5472 \item For every top level getter $g$ named $id$ in $L$, a corresponding getter n amed $id$ with the same signature as $g$. Calling the method results in a runti me error. 6127 \item For every top level getter $g$ named $id$ in $L$, a corresponding getter n amed $id$ with the same signature as $g$. Calling the method results in a runti me error.
5473 \item For every top level setter $s$ named $id$ in $L$, a corresponding setter n amed $id$ with the same signature as $s$. Calling the method results in a runti me error. 6128 \item For every top level setter $s$ named $id$ in $L$, a corresponding setter n amed $id$ with the same signature as $s$. Calling the method results in a runti me error.
5474 \item For every type $T$ named $id$ in $L$, a corresponding getter named $id$ wi th return type \code{Type}. Calling the method results in a runtime error. 6129 \item For every type $T$ named $id$ in $L$, a corresponding getter named $id$ wi th return type \code{Type}. Calling the method results in a runtime error.
5475 \end{itemize} 6130 \end{itemize}
5476 6131
6132 \LMHash{}
5477 After a call succeeds, the name $p$ is mapped to a non-deferred prefix object as described below. In addition, the prefix object also supports the \code{loadLib rary} method, and so it is possible to call \code{loadLibrary} again. If a call fails, nothing happens, and one again has the option to call \code{loadLibrary} again. Whether a repeated call to \code{loadLibrary} succeeds will vary as descr ibed below. 6133 After a call succeeds, the name $p$ is mapped to a non-deferred prefix object as described below. In addition, the prefix object also supports the \code{loadLib rary} method, and so it is possible to call \code{loadLibrary} again. If a call fails, nothing happens, and one again has the option to call \code{loadLibrary} again. Whether a repeated call to \code{loadLibrary} succeeds will vary as descr ibed below.
5478 6134
6135 \LMHash{}
5479 The effect of a repeated call to \code{$p$.loadLibrary} is as follows: 6136 The effect of a repeated call to \code{$p$.loadLibrary} is as follows:
5480 \begin{itemize} 6137 \begin{itemize}
5481 \item 6138 \item
5482 If another call to \code{$p$.loadLibrary} has already succeeded, the repeated ca ll also succeeds. 6139 If another call to \code{$p$.loadLibrary} has already succeeded, the repeated ca ll also succeeds.
5483 Otherwise, 6140 Otherwise,
5484 \item 6141 \item
5485 If another call to to \code{$p$.loadLibrary} has failed: 6142 If another call to to \code{$p$.loadLibrary} has failed:
5486 \begin{itemize} 6143 \begin{itemize}
5487 \item 6144 \item
5488 If the failure is due to a compilation error, the repeated call fails for the sa me reason. 6145 If the failure is due to a compilation error, the repeated call fails for the sa me reason.
5489 \item 6146 \item
5490 If the failure is due to other causes, the repeated call behaves as if no previo us call had been made. 6147 If the failure is due to other causes, the repeated call behaves as if no previo us call had been made.
5491 \end{itemize} 6148 \end{itemize}
5492 \end{itemize} 6149 \end{itemize}
5493 6150
5494 \commentary{ 6151 \commentary{
5495 In other words, one can retry a deferred load after a network failure or because a file is absent, but once one finds some content and loads it, one can no long er reload. 6152 In other words, one can retry a deferred load after a network failure or because a file is absent, but once one finds some content and loads it, one can no long er reload.
5496 6153
5497 We do not specify what value the future returned resolves to. 6154 We do not specify what value the future returned resolves to.
5498 } 6155 }
5499 6156
6157 \LMHash{}
5500 If $I$ is an immediate import then, first 6158 If $I$ is an immediate import then, first
5501 6159
5502 \begin{itemize} 6160 \begin{itemize}
5503 \item 6161 \item
5504 If the URI that is the value of $s_1$ has not yet been accessed by an import or export (\ref{exports}) directive in the current isolate then the contents of t he URI are compiled to yield a library $B$. \commentary{Because libraries may h ave mutually recursive imports, care must be taken to avoid an infinite regress. 6162 If the URI that is the value of $s_1$ has not yet been accessed by an import or export (\ref{exports}) directive in the current isolate then the contents of t he URI are compiled to yield a library $B$. \commentary{Because libraries may h ave mutually recursive imports, care must be taken to avoid an infinite regress.
5505 } 6163 }
5506 \item Otherwise, the contents of the URI denoted by $s_1$ have been compiled int o a library $B$ within the current isolate. 6164 \item Otherwise, the contents of the URI denoted by $s_1$ have been compiled int o a library $B$ within the current isolate.
5507 \end{itemize} 6165 \end{itemize}
5508 6166
5509 6167
6168 \LMHash{}
5510 Let $NS_0$ be the exported namespace (\ref{exports}) of $B$. Then, for each comb inator clause $C_i, i \in 1..n$ in $I$: 6169 Let $NS_0$ be the exported namespace (\ref{exports}) of $B$. Then, for each comb inator clause $C_i, i \in 1..n$ in $I$:
5511 \begin{itemize} 6170 \begin{itemize}
5512 \item If $C_i$ is of the form 6171 \item If $C_i$ is of the form
5513 6172
5514 \code{\SHOW{} $id_1, \ldots, id_k$} 6173 \code{\SHOW{} $id_1, \ldots, id_k$}
5515 6174
5516 then let $NS_i = \SHOW{}([id_1, \ldots, id_k], NS_{i-1}$) 6175 then let $NS_i = \SHOW{}([id_1, \ldots, id_k], NS_{i-1}$)
5517 6176
5518 where $show(l,n)$ takes a list of identifiers $l$ and a namespace $n$, and produ ces a namespace that maps each name in $l$ to the same element that $n$ does. Fu rthermore, for each name $x$ in $l$, if $n$ defines the name $x=$ then the new namespace maps $x=$ to the same element that $n$ does. Otherwise the resulting m apping is undefined. 6177 where $show(l,n)$ takes a list of identifiers $l$ and a namespace $n$, and produ ces a namespace that maps each name in $l$ to the same element that $n$ does. Fu rthermore, for each name $x$ in $l$, if $n$ defines the name $x=$ then the new namespace maps $x=$ to the same element that $n$ does. Otherwise the resulting m apping is undefined.
5519 6178
5520 \item If $C_i$ is of the form 6179 \item If $C_i$ is of the form
5521 6180
5522 \code{\HIDE{} $id_1, \ldots, id_k$} 6181 \code{\HIDE{} $id_1, \ldots, id_k$}
5523 6182
5524 then let $NS_i = \HIDE{}([id_1, \ldots, id_k], NS_{i-1}$) 6183 then let $NS_i = \HIDE{}([id_1, \ldots, id_k], NS_{i-1}$)
5525 6184
5526 where $hide(l, n)$ takes a list of identfiers $l$ and a namespace $n$, and produ ces a namespace that is identical to $n$ except that for each name $k$ in $l$, $ k$ and $k=$ are undefined. 6185 where $hide(l, n)$ takes a list of identfiers $l$ and a namespace $n$, and produ ces a namespace that is identical to $n$ except that for each name $k$ in $l$, $ k$ and $k=$ are undefined.
5527 \end{itemize} 6186 \end{itemize}
5528 6187
6188 \LMHash{}
5529 Next, if $I$ includes a prefix clause of the form \AS{} $p$, let $NS = NS_n \cu p \{p: prefixObject(NS_n)\}$ where $prefixObject(NS_n)$ is a {\em prefix object} for the namespace $NS_n$, which is an object that has the following members: 6189 Next, if $I$ includes a prefix clause of the form \AS{} $p$, let $NS = NS_n \cu p \{p: prefixObject(NS_n)\}$ where $prefixObject(NS_n)$ is a {\em prefix object} for the namespace $NS_n$, which is an object that has the following members:
5530 6190
5531 \begin{itemize} 6191 \begin{itemize}
5532 \item For every top level function $f$ named $id$ in $NS_n$, a corresponding me thod with the same name and signature as $f$ that forwards (\ref{functionDeclar ations}) to $f$. 6192 \item For every top level function $f$ named $id$ in $NS_n$, a corresponding me thod with the same name and signature as $f$ that forwards (\ref{functionDeclar ations}) to $f$.
5533 \item For every top level getter with the same name and signature as $g$ named $id$ in $NS_n$, a corresponding getter that forwards to $g$. 6193 \item For every top level getter with the same name and signature as $g$ named $id$ in $NS_n$, a corresponding getter that forwards to $g$.
5534 \item For every top level setter $s$ with the same name and signature as named $id$ in $NS_n$, a corresponding setter that forwards to $s$. 6194 \item For every top level setter $s$ with the same name and signature as named $id$ in $NS_n$, a corresponding setter that forwards to $s$.
5535 \item For every type $T$ named $id$ in $NS_n$, a corresponding getter named $id$ with return type \code{Type}, that, when invoked, returns the type object for $ T$. 6195 \item For every type $T$ named $id$ in $NS_n$, a corresponding getter named $id$ with return type \code{Type}, that, when invoked, returns the type object for $ T$.
5536 \end{itemize} 6196 \end{itemize}
5537 6197
6198 \LMHash{}
5538 Otherwise, let $NS = NS_n$. 6199 Otherwise, let $NS = NS_n$.
5539 It is a compile-time error if the current library declares a top-level member na med $p$. 6200 It is a compile-time error if the current library declares a top-level member na med $p$.
5540 6201
5541 % This is problematic, because it implies that p.T would be available even in a scope that declared p. We really need to think of p as a single object with prop erties p.T etc., except it isn't really that 6202 % This is problematic, because it implies that p.T would be available even in a scope that declared p. We really need to think of p as a single object with prop erties p.T etc., except it isn't really that
5542 % either. After all, p isn't actually available as a stand alone name. 6203 % either. After all, p isn't actually available as a stand alone name.
5543 6204
6205 \LMHash{}
5544 Then, for each entry mapping key $k$ to declaration $d$ in $NS$, $d$ is made av ailable in the top level scope of $L$ under the name $k$ unless either: 6206 Then, for each entry mapping key $k$ to declaration $d$ in $NS$, $d$ is made av ailable in the top level scope of $L$ under the name $k$ unless either:
5545 \begin{itemize} 6207 \begin{itemize}
5546 \item 6208 \item
5547 a top-level declaration with the name $k$ exists in $L$, OR 6209 a top-level declaration with the name $k$ exists in $L$, OR
5548 \item a prefix clause of the form \AS{} $k$ is used in $L$. 6210 \item a prefix clause of the form \AS{} $k$ is used in $L$.
5549 \end{itemize} 6211 \end{itemize}
5550 6212
5551 \rationale{The greatly increases the chance that a member can be added to a libr ary without breaking its importers.} 6213 \rationale{The greatly increases the chance that a member can be added to a libr ary without breaking its importers.}
5552 6214
6215 \LMHash{}
5553 A {\em system library} is a library that is part of the Dart implementation. Any other library is a {\em non-system library}. If a name $N$ is referenced by a l ibrary $L$ and $N$ would be introduced into the top level scope of $L$ by 6216 A {\em system library} is a library that is part of the Dart implementation. Any other library is a {\em non-system library}. If a name $N$ is referenced by a l ibrary $L$ and $N$ would be introduced into the top level scope of $L$ by
5554 imports of two libraries, $L_1$ and $L_2$, and the exported namespace of $L_1$ b inds $N$ to a declaration originating in a system library: 6217 imports of two libraries, $L_1$ and $L_2$, and the exported namespace of $L_1$ b inds $N$ to a declaration originating in a system library:
5555 6218
5556 %an import of a system library and an import of a non-system library: 6219 %an import of a system library and an import of a non-system library:
5557 \begin{itemize} 6220 \begin{itemize}
5558 \item The import of $L_1$ is implicitly extended by a \code{\HIDE{} $N$} clause. 6221 \item The import of $L_1$ is implicitly extended by a \code{\HIDE{} $N$} clause.
5559 \item A static warning is issued. 6222 \item A static warning is issued.
5560 \end{itemize} 6223 \end{itemize}
5561 6224
5562 \rationale { 6225 \rationale {
5563 Whereas normal conflicts are resolved at deployment time, the functionality of \ code{dart:} libraries is injected into an application at run time, and may vary over time as browsers are upgraded. Thus, conflicts with \code{dart:} libraries can arise at runtime, outside the developerÕs control. To avoid breaking deploy ed applications in this way, conflicts with the \code{dart:} libraries are treat ed specially. 6226 Whereas normal conflicts are resolved at deployment time, the functionality of \ code{dart:} libraries is injected into an application at run time, and may vary over time as browsers are upgraded. Thus, conflicts with \code{dart:} libraries can arise at runtime, outside the developer's control. To avoid breaking deploy ed applications in this way, conflicts with the \code{dart:} libraries are treat ed specially.
5564 6227
5565 It is recommended that tools that deploy Dart code produce output in which all i mports use show clauses to ensure that additions to the namespace of a library n ever impact deployed code. 6228 It is recommended that tools that deploy Dart code produce output in which all i mports use show clauses to ensure that additions to the namespace of a library n ever impact deployed code.
5566 } 6229 }
5567 6230
6231 \LMHash{}
5568 If a name $N$ is referenced by a library $L$ and $N$ is introduced into the to p level scope of $L$ by more than one import, and not all the imports denote the same declaration, then: 6232 If a name $N$ is referenced by a library $L$ and $N$ is introduced into the to p level scope of $L$ by more than one import, and not all the imports denote the same declaration, then:
5569 \begin{itemize} 6233 \begin{itemize}
5570 \item A static warning occurs. 6234 \item A static warning occurs.
5571 \item If $N$ is referenced as a function, getter or setter, a \code{NoSuchMethod Error} is thrown. 6235 \item If $N$ is referenced as a function, getter or setter, a \code{NoSuchMethod Error} is thrown.
5572 \item If $N$ is referenced as a type, it is treated as a malformed type. 6236 \item If $N$ is referenced as a type, it is treated as a malformed type.
5573 6237
5574 \end{itemize} 6238 \end{itemize}
5575 6239
6240 \LMHash{}
5576 We say that the namespace $NS$ {\em has been imported into} $L$. 6241 We say that the namespace $NS$ {\em has been imported into} $L$.
5577 6242
5578 \commentary{ 6243 \commentary{
5579 It is neither an error nor a warning if $N$ is introduced by two or more import s but never referred to. 6244 It is neither an error nor a warning if $N$ is introduced by two or more import s but never referred to.
5580 } 6245 }
5581 6246
5582 \rationale{ 6247 \rationale{
5583 The policy above makes libraries more robust in the face of additions made to th eir imports. 6248 The policy above makes libraries more robust in the face of additions made to th eir imports.
5584 6249
5585 A clear distinction needs to be made between this approach, and seemingly simila r policies with respect to classes or interfaces. The use of a class or interfa ce, and of its members, is separate from its declaration. The usage and declarat ion may occur in widely separated places in the code, and may in fact be authore d by different people or organizations. It is important that errors are given a t the offending declaration so that the party that receives the error can respon d to it a meaningful way. 6250 A clear distinction needs to be made between this approach, and seemingly simila r policies with respect to classes or interfaces. The use of a class or interfa ce, and of its members, is separate from its declaration. The usage and declarat ion may occur in widely separated places in the code, and may in fact be authore d by different people or organizations. It is important that errors are given a t the offending declaration so that the party that receives the error can respon d to it a meaningful way.
5586 6251
5587 In contrast a library comprises both imports and their usage; the library is und er the control of a single party and so any problem stemming from the import can be resolved even if it is reported at the use site. 6252 In contrast a library comprises both imports and their usage; the library is und er the control of a single party and so any problem stemming from the import can be resolved even if it is reported at the use site.
5588 6253
5589 %On a related note, the provenance of the conflicting elements is not considered . An element that is imported via distinct paths may conflict with itself. This avoids variants of the well known "diamond" problem. 6254 %On a related note, the provenance of the conflicting elements is not considered . An element that is imported via distinct paths may conflict with itself. This avoids variants of the well known "diamond" problem.
5590 } 6255 }
5591 6256
6257 \LMHash{}
5592 It is a static warning to import two different libraries with the same name. 6258 It is a static warning to import two different libraries with the same name.
5593 6259
5594 \commentary{ 6260 \commentary{
5595 A widely disseminated library should be given a name that will not conflict with other such libraries. The preferred mechanism for this is using pub, the Dart p ackage manager, which provides a global namespace for libraries, and conventions that leverage that namespace. 6261 A widely disseminated library should be given a name that will not conflict with other such libraries. The preferred mechanism for this is using pub, the Dart p ackage manager, which provides a global namespace for libraries, and conventions that leverage that namespace.
5596 } 6262 }
5597 6263
5598 \commentary{Note that no errors or warnings are given if one hides or shows a na me that is not in a namespace.} 6264 \commentary{Note that no errors or warnings are given if one hides or shows a na me that is not in a namespace.}
5599 \rationale{ 6265 \rationale{
5600 This prevents situations where removing a name from a library would cause breaka ge of a client library. 6266 This prevents situations where removing a name from a library would cause breaka ge of a client library.
5601 } 6267 }
5602 6268
6269 \LMHash{}
5603 The dart core library \code{dart:core} is implicitly imported into every dart li brary other than itself via an import clause of the form 6270 The dart core library \code{dart:core} is implicitly imported into every dart li brary other than itself via an import clause of the form
5604 6271
5605 \code{\IMPORT{} `dart:core';} 6272 \code{\IMPORT{} `dart:core';}
5606 6273
5607 unless the importing library explicitly imports \code{dart:core}. 6274 unless the importing library explicitly imports \code{dart:core}.
5608 6275
5609 \commentary{ 6276 \commentary{
5610 Any import of \code{dart:core}, even if restricted via \SHOW{}, \HIDE{} or \AS{} , preempts the automatic import. 6277 Any import of \code{dart:core}, even if restricted via \SHOW{}, \HIDE{} or \AS{} , preempts the automatic import.
5611 } 6278 }
5612 6279
5613 \rationale{ 6280 \rationale{
5614 It would be nice if there was nothing special about \code{dart:core}. However, i ts use is pervasive, which leads to the decision to import it automatically. Ho wever, some library $L$ may wish to define entities with names used by \code{da rt:core} (which it can easily do, as the names declared by a library take preced ence). Other libraries may wish to use $L$ and may want to use members of $L$ th at conflict with the core library without having to use a prefix and without enc ountering warnings. The above rule makes this possible, essentially canceling \c ode{dart:core}'s special treatment by means of yet another special rule. 6281 It would be nice if there was nothing special about \code{dart:core}. However, i ts use is pervasive, which leads to the decision to import it automatically. Ho wever, some library $L$ may wish to define entities with names used by \code{da rt:core} (which it can easily do, as the names declared by a library take preced ence). Other libraries may wish to use $L$ and may want to use members of $L$ th at conflict with the core library without having to use a prefix and without enc ountering warnings. The above rule makes this possible, essentially canceling \c ode{dart:core}'s special treatment by means of yet another special rule.
5615 } 6282 }
5616 6283
5617 \subsection{Exports} 6284 \subsection{Exports}
5618 \label{exports} 6285 \LMLabel{exports}
5619 6286
6287 \LMHash{}
5620 A library $L$ exports a namespace (\ref{scoping}), meaning that the declarations in the namespace are made available to other libraries if they choose to import $L$ (\ref{imports}). The namespace that $L$ exports is known as its {\em expor ted namespace}. 6288 A library $L$ exports a namespace (\ref{scoping}), meaning that the declarations in the namespace are made available to other libraries if they choose to import $L$ (\ref{imports}). The namespace that $L$ exports is known as its {\em expor ted namespace}.
5621 6289
5622 \begin{grammar} 6290 \begin{grammar}
5623 {\bf libraryExport:} 6291 {\bf libraryExport:}
5624 metadata \EXPORT{} uri combinator* `{\escapegrammar ;}' 6292 metadata \EXPORT{} uri combinator* `{\escapegrammar ;}'
5625 . 6293 .
5626 \end{grammar} 6294 \end{grammar}
5627 6295
6296 \LMHash{}
5628 An export specifies a URI $x$ where the declaration of an exported library is t o be found. It is a compile-time error if the specified URI does not refer to a library declaration. 6297 An export specifies a URI $x$ where the declaration of an exported library is t o be found. It is a compile-time error if the specified URI does not refer to a library declaration.
5629 6298
6299 \LMHash{}
5630 We say that a name {\em is exported by a library} (or equivalently, that a libra ry {\em exports a name}) if the name is in the library's exported namespace. We say that a declaration {\em is exported by a library} (or equivalently, that a l ibrary {\em exports a declaration}) if the declaration is in the library's expor ted namespace. 6300 We say that a name {\em is exported by a library} (or equivalently, that a libra ry {\em exports a name}) if the name is in the library's exported namespace. We say that a declaration {\em is exported by a library} (or equivalently, that a l ibrary {\em exports a declaration}) if the declaration is in the library's expor ted namespace.
5631 6301
6302 \LMHash{}
5632 A library always exports all names and all declarations in its public namespace. In addition, a library may choose to re-export additional libraries via {\em ex port directives}, often referred to simply as {\em exports}. 6303 A library always exports all names and all declarations in its public namespace. In addition, a library may choose to re-export additional libraries via {\em ex port directives}, often referred to simply as {\em exports}.
5633 6304
6305 \LMHash{}
5634 Let $E$ be an export directive that refers to a URI via the string $s_1$. Evalua tion of $E$ proceeds as follows: 6306 Let $E$ be an export directive that refers to a URI via the string $s_1$. Evalua tion of $E$ proceeds as follows:
5635 6307
6308 \LMHash{}
5636 First, 6309 First,
5637 6310
5638 \begin{itemize} 6311 \begin{itemize}
5639 \item 6312 \item
5640 If the URI that is the value of $s_1$ has not yet been accessed by an import or export directive in the current isolate then the contents of the URI are comp iled to yield a library $B$. 6313 If the URI that is the value of $s_1$ has not yet been accessed by an import or export directive in the current isolate then the contents of the URI are comp iled to yield a library $B$.
5641 \item Otherwise, the contents of the URI denoted by $s_1$ have been compiled int o a library $B$ within the current isolate. 6314 \item Otherwise, the contents of the URI denoted by $s_1$ have been compiled int o a library $B$ within the current isolate.
5642 \end{itemize} 6315 \end{itemize}
5643 6316
5644 6317
6318 \LMHash{}
5645 Let $NS_0$ be the exported namespace of $B$. Then, for each combinator clause $C _i, i \in 1..n$ in $E$: 6319 Let $NS_0$ be the exported namespace of $B$. Then, for each combinator clause $C _i, i \in 1..n$ in $E$:
5646 \begin{itemize} 6320 \begin{itemize}
5647 \item If $C_i$ is of the form \code{\SHOW{} $id_1, \ldots, id_k$} then let 6321 \item If $C_i$ is of the form \code{\SHOW{} $id_1, \ldots, id_k$} then let
5648 6322
5649 $NS_i = \SHOW{}([id_1, \ldots, id_k], NS_{i-1}$). 6323 $NS_i = \SHOW{}([id_1, \ldots, id_k], NS_{i-1}$).
5650 \item If $C_i$ is of the form \code{\HIDE{} $id_1, \ldots, id_k$} 6324 \item If $C_i$ is of the form \code{\HIDE{} $id_1, \ldots, id_k$}
5651 6325
5652 then let $NS_i = \HIDE{}([id_1, \ldots, id_k], NS_{i-1}$). 6326 then let $NS_i = \HIDE{}([id_1, \ldots, id_k], NS_{i-1}$).
5653 \end{itemize} 6327 \end{itemize}
5654 6328
6329 \LMHash{}
5655 For each 6330 For each
5656 entry mapping key $k$ to declaration $d$ in $NS_n$ an entry mapping $k$ to $d$ i s added to the exported namespace of $L$ unless a top-level declaration with th e name $k$ exists in $L$. 6331 entry mapping key $k$ to declaration $d$ in $NS_n$ an entry mapping $k$ to $d$ i s added to the exported namespace of $L$ unless a top-level declaration with th e name $k$ exists in $L$.
5657 6332
6333 \LMHash{}
5658 If a name $N$ is referenced by a library $L$ and $N$ would be introduced into th e exported namespace of $L$ by exports of two libraries, $L_1$ and $L_2$, and th e exported namespace of $L_1$ binds $N$ to a declaration originating in a system library: 6334 If a name $N$ is referenced by a library $L$ and $N$ would be introduced into th e exported namespace of $L$ by exports of two libraries, $L_1$ and $L_2$, and th e exported namespace of $L_1$ binds $N$ to a declaration originating in a system library:
5659 %an export of a system library and an export of a non-system library: 6335 %an export of a system library and an export of a non-system library:
5660 \begin{itemize} 6336 \begin{itemize}
5661 \item The export of $L_1$ is implicitly extended by a \code{\HIDE{} $N$} clause. 6337 \item The export of $L_1$ is implicitly extended by a \code{\HIDE{} $N$} clause.
5662 \item A static warning is issued. 6338 \item A static warning is issued.
5663 \end{itemize} 6339 \end{itemize}
5664 6340
5665 \rationale{ 6341 \rationale{
5666 See the discussion in section \ref{imports} for the reasoning behind this rule. 6342 See the discussion in section \ref{imports} for the reasoning behind this rule.
5667 } 6343 }
5668 6344
6345 \LMHash{}
5669 We say that $L$ {\em re-exports library } $B$, and also that $L$ {\em re-exports namespace } $NS_n$. When no confusion can arise, we may simply state that $L$ { \em re-exports }$B$, or that $L$ {\em re-exports }$NS_n$. 6346 We say that $L$ {\em re-exports library } $B$, and also that $L$ {\em re-exports namespace } $NS_n$. When no confusion can arise, we may simply state that $L$ { \em re-exports }$B$, or that $L$ {\em re-exports }$NS_n$.
5670 6347
6348 \LMHash{}
5671 It is a compile-time error if a name $N$ is re-exported by a library $L$ and $N$ is introduced into the export namespace of $L$ by more than one export, unless all exports refer to same declaration for the name $N$. It is a static warnin g to export two different libraries with the same name. 6349 It is a compile-time error if a name $N$ is re-exported by a library $L$ and $N$ is introduced into the export namespace of $L$ by more than one export, unless all exports refer to same declaration for the name $N$. It is a static warnin g to export two different libraries with the same name.
5672 6350
5673 6351
5674 6352
5675 \subsection{Parts} 6353 \subsection{Parts}
5676 \label{parts} 6354 \LMLabel{parts}
5677 6355
6356 \LMHash{}
5678 A library may be divided into {\em parts}, each of which can be stored in a sepa rate location. A library identifies its parts by listing them via \PART{} direct ives. 6357 A library may be divided into {\em parts}, each of which can be stored in a sepa rate location. A library identifies its parts by listing them via \PART{} direct ives.
5679 6358
6359 \LMHash{}
5680 A {\em part directive} specifies a URI where a Dart compilation unit that should be incorporated into the current library may be found. 6360 A {\em part directive} specifies a URI where a Dart compilation unit that should be incorporated into the current library may be found.
5681 6361
5682 \begin{grammar} 6362 \begin{grammar}
5683 {\bf partDirective:} 6363 {\bf partDirective:}
5684 metadata \PART{} uri '{\escapegrammar ;}' 6364 metadata \PART{} uri '{\escapegrammar ;}'
5685 . 6365 .
5686 6366
5687 {\bf partHeader:} 6367 {\bf partHeader:}
5688 metadata \PART{} \OF{} identifier (`{\escapegrammar .}' identifier)* `{\es capegrammar ;}' 6368 metadata \PART{} \OF{} identifier (`{\escapegrammar .}' identifier)* `{\es capegrammar ;}'
5689 . 6369 .
5690 {\bf partDeclaration:} 6370 {\bf partDeclaration:}
5691 partHeader topLevelDefinition* EOF 6371 partHeader topLevelDefinition* EOF
5692 . 6372 .
5693 \end{grammar} 6373 \end{grammar}
5694 6374
6375 \LMHash{}
5695 A {\em part header} begins with \PART{} \OF{} followed by the name of the libr ary the part belongs to. A part declaration consists of a part header followed by a sequence of top-level declarations. 6376 A {\em part header} begins with \PART{} \OF{} followed by the name of the libr ary the part belongs to. A part declaration consists of a part header followed by a sequence of top-level declarations.
5696 6377
6378 \LMHash{}
5697 Compiling a part directive of the form \code{\PART{} $s$;} causes the Dart syste m to attempt to compile the contents of the URI that is the value of $s$. The to p-level declarations at that URI are then compiled by the Dart compiler in the s cope of the current library. It is a compile-time error if the contents of the U RI are not a valid part declaration. It is a static warning if the referenced pa rt declaration $p$ names a library other than the current library as the library to which $p$ belongs. 6379 Compiling a part directive of the form \code{\PART{} $s$;} causes the Dart syste m to attempt to compile the contents of the URI that is the value of $s$. The to p-level declarations at that URI are then compiled by the Dart compiler in the s cope of the current library. It is a compile-time error if the contents of the U RI are not a valid part declaration. It is a static warning if the referenced pa rt declaration $p$ names a library other than the current library as the library to which $p$ belongs.
5698 6380
5699 \subsection{Scripts} 6381 \subsection{Scripts}
5700 \label{scripts} 6382 \LMLabel{scripts}
5701 6383
6384 \LMHash{}
5702 A {\em script} is a library whose exported namespace (\ref{exports}) includes a top-level function \code{main}. 6385 A {\em script} is a library whose exported namespace (\ref{exports}) includes a top-level function \code{main}.
5703 A script $S$ may be executed as follows: 6386 A script $S$ may be executed as follows:
5704 6387
6388 \LMHash{}
5705 First, $S$ is compiled as a library as specified above. Then, the top-level func tion \code{main} that is in the exported namespace of $S$ is invoked. If \code{m ain} has no positional parameters, it is invoked with no arguments. Otherwise if \code{main} has exactly one positional parameter, it is invoked with a single a ctual argument whose runtime type implements \code{List$<$String$>$}. Otherwise \code{main} is invoked with the following two actual arguments: 6389 First, $S$ is compiled as a library as specified above. Then, the top-level func tion \code{main} that is in the exported namespace of $S$ is invoked. If \code{m ain} has no positional parameters, it is invoked with no arguments. Otherwise if \code{main} has exactly one positional parameter, it is invoked with a single a ctual argument whose runtime type implements \code{List$<$String$>$}. Otherwise \code{main} is invoked with the following two actual arguments:
5706 \begin{enumerate} 6390 \begin{enumerate}
5707 \item An object whose runtime type implements \code{List$<$String$>$}. 6391 \item An object whose runtime type implements \code{List$<$String$>$}.
5708 \item The initial message of the current isolate $i$ as determined by the invoca tion of \code{Isolate.spawnUri} that spawned $i$. 6392 \item The initial message of the current isolate $i$ as determined by the invoca tion of \code{Isolate.spawnUri} that spawned $i$.
5709 \end{enumerate} 6393 \end{enumerate}
5710 6394
6395 \LMHash{}
5711 It is a run time error if $S$ does not declare or import a top-level function \c ode{main}. It is a static warning if \code{main} has more than two required para meters. 6396 It is a run time error if $S$ does not declare or import a top-level function \c ode{main}. It is a static warning if \code{main} has more than two required para meters.
5712 6397
5713 \commentary { 6398 \commentary {
5714 Note that if \code{main} requires more than two arguments, a run time error will occur. 6399 Note that if \code{main} requires more than two arguments, a run time error will occur.
5715 } 6400 }
5716 6401
5717 \rationale{ 6402 \rationale{
5718 The names of scripts are optional, in the interests of interactive, informal use . However, any script of long term value should be given a name as a matter of g ood practice. 6403 The names of scripts are optional, in the interests of interactive, informal use . However, any script of long term value should be given a name as a matter of g ood practice.
5719 } 6404 }
5720 6405
5721 \commentary { 6406 \commentary {
5722 A Dart program will typically be executed by executing a script. 6407 A Dart program will typically be executed by executing a script.
5723 } 6408 }
5724 6409
5725 \subsection{URIs} 6410 \subsection{URIs}
5726 \label{uris} 6411 \LMLabel{uris}
5727 6412
6413 \LMHash{}
5728 URIs are specified by means of string literals: 6414 URIs are specified by means of string literals:
5729 6415
5730 \begin{grammar} 6416 \begin{grammar}
5731 {\bf uri:} 6417 {\bf uri:}
5732 stringLiteral 6418 stringLiteral
5733 . 6419 .
5734 \end{grammar} 6420 \end{grammar}
5735 6421
6422 \LMHash{}
5736 It is a compile-time error if the string literal $x$ that describes a URI is no t a compile-time constant, or if $x$ involves string interpolation. 6423 It is a compile-time error if the string literal $x$ that describes a URI is no t a compile-time constant, or if $x$ involves string interpolation.
5737 6424
6425 \LMHash{}
5738 This specification does not discuss the interpretation of URIs, with the followi ng exceptions. 6426 This specification does not discuss the interpretation of URIs, with the followi ng exceptions.
5739 6427
5740 \rationale{ 6428 \rationale{
5741 The interpretation of URIs is mostly left to the surrounding computing environm ent. For example, if Dart is running in a web browser, that browser will likely interpret some URIs. While it might seem attractive to specify, say, that URIs a re interpreted with respect to a standard such as IETF RFC 3986, in practice thi s will usually depend on the browser and cannot be relied upon. 6429 The interpretation of URIs is mostly left to the surrounding computing environm ent. For example, if Dart is running in a web browser, that browser will likely interpret some URIs. While it might seem attractive to specify, say, that URIs a re interpreted with respect to a standard such as IETF RFC 3986, in practice thi s will usually depend on the browser and cannot be relied upon.
5742 } 6430 }
5743 6431
6432 \LMHash{}
5744 A URI of the form \code{dart:$s$} is interpreted as a reference to a system libr ary (\ref{imports}) $s$. 6433 A URI of the form \code{dart:$s$} is interpreted as a reference to a system libr ary (\ref{imports}) $s$.
5745 6434
6435 \LMHash{}
5746 A URI of the form \code{package:$s$} is interpreted as a URI of the form \code{p ackages/s} relative to an implementation specified location. 6436 A URI of the form \code{package:$s$} is interpreted as a URI of the form \code{p ackages/s} relative to an implementation specified location.
5747 6437
5748 \commentary{ 6438 \commentary{
5749 This location will often be the location of the root library presented to the Da rt compiler. However, implementations may supply means to override or replace th is choice. 6439 This location will often be the location of the root library presented to the Da rt compiler. However, implementations may supply means to override or replace th is choice.
5750 } 6440 }
5751 6441
5752 \rationale{ 6442 \rationale{
5753 The intent is that, during development, Dart programmers can rely on a package m anager to find elements of their program. Such package managers may provide a di rectory structure starting at a local directory \code{packages} where they place the required dart code (or links thereto). 6443 The intent is that, during development, Dart programmers can rely on a package m anager to find elements of their program. Such package managers may provide a di rectory structure starting at a local directory \code{packages} where they place the required dart code (or links thereto).
5754 } 6444 }
5755 6445
6446 \LMHash{}
5756 Otherwise, any relative URI is interpreted as relative to the the location of th e current library. All further interpretation of URIs is implementation dependen t. 6447 Otherwise, any relative URI is interpreted as relative to the the location of th e current library. All further interpretation of URIs is implementation dependen t.
5757 6448
5758 \commentary{This means it is dependent on the embedder.} 6449 \commentary{This means it is dependent on the embedder.}
5759 6450
5760 6451
5761 \section{Types} 6452 \section{Types}
5762 \label{types} 6453 \LMLabel{types}
5763 6454
6455 \LMHash{}
5764 Dart supports optional typing based on interface types. 6456 Dart supports optional typing based on interface types.
5765 6457
5766 \rationale{The type system is unsound, due to the covariance of generic types. T his is a deliberate choice (and undoubtedly controversial). Experience has show n that sound type rules for generics fly in the face of programmer intuition. It is easy for tools to provide a sound type analysis if they choose, which may be useful for tasks like refactoring. 6458 \rationale{The type system is unsound, due to the covariance of generic types. T his is a deliberate choice (and undoubtedly controversial). Experience has show n that sound type rules for generics fly in the face of programmer intuition. It is easy for tools to provide a sound type analysis if they choose, which may be useful for tasks like refactoring.
5767 } 6459 }
5768 6460
5769 \subsection{Static Types} 6461 \subsection{Static Types}
5770 \label{staticTypes} 6462 \LMLabel{staticTypes}
5771 6463
6464 \LMHash{}
5772 Static type annotations are used in variable declarations (\ref{variables}) (inc luding formal parameters (\ref{formalParameters})), in the return types of funct ions (\ref{functions}) and in the bounds of type variables. Static type annotat ions are used during static checking and when running programs in checked mode. They have no effect whatsoever in production mode. 6465 Static type annotations are used in variable declarations (\ref{variables}) (inc luding formal parameters (\ref{formalParameters})), in the return types of funct ions (\ref{functions}) and in the bounds of type variables. Static type annotat ions are used during static checking and when running programs in checked mode. They have no effect whatsoever in production mode.
5773 6466
5774 \begin{grammar} 6467 \begin{grammar}
5775 {\bf type:} 6468 {\bf type:}
5776 typeName typeArguments? 6469 typeName typeArguments?
5777 . 6470 .
5778 6471
5779 {\bf typeName:} 6472 {\bf typeName:}
5780 qualified 6473 qualified
5781 . 6474 .
5782 6475
5783 {\bf typeArguments:} 6476 {\bf typeArguments:}
5784 '<' typeList '>' 6477 '<' typeList '>'
5785 . 6478 .
5786 6479
5787 {\bf typeList:} 6480 {\bf typeList:}
5788 type (',' type)* 6481 type (',' type)*
5789 . 6482 .
5790 \end{grammar} 6483 \end{grammar}
5791 6484
6485 \LMHash{}
5792 A Dart implementation must provide a static checker that detects and reports exa ctly those situations this specification identifies as static warnings and only those situations. However: 6486 A Dart implementation must provide a static checker that detects and reports exa ctly those situations this specification identifies as static warnings and only those situations. However:
5793 \begin{itemize} 6487 \begin{itemize}
5794 \item Running the static checker on a program $P$ is not required for compiling and running $P$. 6488 \item Running the static checker on a program $P$ is not required for compiling and running $P$.
5795 \item Running the static checker on a program $P$ must not prevent successful co mpilation of $P$ nor may it prevent the execution of $P$, regardless of whether any static warnings occur. 6489 \item Running the static checker on a program $P$ must not prevent successful co mpilation of $P$ nor may it prevent the execution of $P$, regardless of whether any static warnings occur.
5796 \end{itemize} 6490 \end{itemize}
5797 6491
5798 \commentary{Nothing precludes additional tools that implement alternative static analyses (e.g., interpreting the existing type annotations in a sound manner su ch as either non-variant generics, or inferring declaration based variance from the actual declarations). However, using these tools must not preclude successfu l compilation and execution of Dart code. 6492 \commentary{Nothing precludes additional tools that implement alternative static analyses (e.g., interpreting the existing type annotations in a sound manner su ch as either non-variant generics, or inferring declaration based variance from the actual declarations). However, using these tools must not preclude successfu l compilation and execution of Dart code.
5799 } 6493 }
5800 6494
5801 %\Q{Should we do something with respect to non-nullable types?} 6495 %\Q{Should we do something with respect to non-nullable types?}
5802 6496
6497 \LMHash{}
5803 A type $T$ is {\em malformed} iff: 6498 A type $T$ is {\em malformed} iff:
5804 \begin{itemize} 6499 \begin{itemize}
5805 \item $T$ has the form $id$ or the form $prefix.id$, and in the enclosing lexica l scope, the name $id$ (respectively $prefix.id$) does not denote a type. 6500 \item $T$ has the form $id$ or the form $prefix.id$, and in the enclosing lexica l scope, the name $id$ (respectively $prefix.id$) does not denote a type.
5806 \item $T$ denotes a type variable in the enclosing lexical scope, but occurs in the signature or body of a static member. 6501 \item $T$ denotes a type variable in the enclosing lexical scope, but occurs in the signature or body of a static member.
5807 \item $T$ is a parameterized type of the form $G<S_1, \ldots , S_n>$, and $G$ i s malformed. 6502 \item $T$ is a parameterized type of the form $G<S_1, \ldots , S_n>$, and $G$ i s malformed.
5808 \item $T$ denotes declarations that were imported from multiple imports clauses. 6503 \item $T$ denotes declarations that were imported from multiple imports clauses.
5809 %Either $G$ or $S_i, i \in 1.. n$ are malformed. 6504 %Either $G$ or $S_i, i \in 1.. n$ are malformed.
5810 % \item $G$ is not a generic type with $n$ type parameters. 6505 % \item $G$ is not a generic type with $n$ type parameters.
5811 % \item Let $T_i$ be the type parameters of $G$ (if any) and let $B_i$ be the b ound of $T_i, i \in 1.. n$, and $S_i$ is not a subtype of $[S_1, \ldots, S_n/T _1, \ldots, T_n]B_i, i \in 1.. n$. 6506 % \item Let $T_i$ be the type parameters of $G$ (if any) and let $B_i$ be the b ound of $T_i, i \in 1.. n$, and $S_i$ is not a subtype of $[S_1, \ldots, S_n/T _1, \ldots, T_n]B_i, i \in 1.. n$.
5812 % \end{itemize} 6507 % \end{itemize}
5813 \end{itemize} 6508 \end{itemize}
5814 6509
6510 \LMHash{}
5815 Any use of a malformed type gives rise to a static warning. A malformed type i s then interpreted as \DYNAMIC{} by the static type checker and the runtime unle ss explicitly specified otherwise. 6511 Any use of a malformed type gives rise to a static warning. A malformed type i s then interpreted as \DYNAMIC{} by the static type checker and the runtime unle ss explicitly specified otherwise.
5816 6512
5817 \rationale{ 6513 \rationale{
5818 This ensures that the developer is spared a series of cascading warnings as the malformed type interacts with other types. 6514 This ensures that the developer is spared a series of cascading warnings as the malformed type interacts with other types.
5819 } 6515 }
5820 6516
6517 \LMHash{}
5821 A type $T$ is {\em deferred} iff it is of the form $p.T$ where $p$ is a deferred prefix. 6518 A type $T$ is {\em deferred} iff it is of the form $p.T$ where $p$ is a deferred prefix.
5822 It is a static warning to use a deferred type in a type annotation, type test, t ype cast or as a type parameter. However, all other static warnings must be issu ed under the assumption that all deferred libraries have successfully been loade d. 6519 It is a static warning to use a deferred type in a type annotation, type test, t ype cast or as a type parameter. However, all other static warnings must be issu ed under the assumption that all deferred libraries have successfully been loade d.
5823 6520
5824 6521
5825 \subsubsection{Type Promotion} 6522 \subsubsection{Type Promotion}
5826 \label{typePromotion} 6523 \LMLabel{typePromotion}
5827 6524
6525 \LMHash{}
5828 The static type system ascribes a static type to every expression. In some case s, the types of local variables and formal parameters may be promoted from their declared types based on control flow. 6526 The static type system ascribes a static type to every expression. In some case s, the types of local variables and formal parameters may be promoted from their declared types based on control flow.
5829 6527
6528 \LMHash{}
5830 We say that a variable $v$ is known to have type $T$ whenever we allow the type of $v$ to be promoted. The exact circumstances when type promotion is allowed ar e given in the relevant sections of the specification (\ref{logicalBooleanExpres sions}, \ref{conditional} and \ref{if}). 6529 We say that a variable $v$ is known to have type $T$ whenever we allow the type of $v$ to be promoted. The exact circumstances when type promotion is allowed ar e given in the relevant sections of the specification (\ref{logicalBooleanExpres sions}, \ref{conditional} and \ref{if}).
5831 6530
6531 \LMHash{}
5832 Type promotion for a variable $v$ is allowed only when we can deduce that such p romotion is valid based on an analysis of certain boolean expressions. In such c ases, we say that the boolean expression $b$ shows that $v$ has type $T$. As a r ule, for all variables $v$ and types $T$, a boolean expression does not show tha t $v$ has type $T$. Those situations where an expression does show that a variab le has a type are mentioned explicitly in the relevant sections of this specific ation (\ref{typeTest} and \ref{logicalBooleanExpressions}). 6532 Type promotion for a variable $v$ is allowed only when we can deduce that such p romotion is valid based on an analysis of certain boolean expressions. In such c ases, we say that the boolean expression $b$ shows that $v$ has type $T$. As a r ule, for all variables $v$ and types $T$, a boolean expression does not show tha t $v$ has type $T$. Those situations where an expression does show that a variab le has a type are mentioned explicitly in the relevant sections of this specific ation (\ref{typeTest} and \ref{logicalBooleanExpressions}).
5833 6533
5834 6534
5835 \subsection{Dynamic Type System} 6535 \subsection{Dynamic Type System}
5836 \label{dynamicTypeSystem} 6536 \LMLabel{dynamicTypeSystem}
5837 6537
6538 \LMHash{}
5838 A Dart implementation must support execution in both {\em production mode} and { \em checked mode}. Those dynamic checks specified as occurring specifically in checked mode must be performed iff the code is executed in checked mode. 6539 A Dart implementation must support execution in both {\em production mode} and { \em checked mode}. Those dynamic checks specified as occurring specifically in checked mode must be performed iff the code is executed in checked mode.
5839 6540
5840 \commentary{ 6541 \commentary{
5841 Note that this is the case even if the deferred type belongs to a prefix that ha s already been loaded. This is regrettable, since it strongly discourages the us e of type annotations that involve deferred types because Dart programmers use c hecked mode much of the time. 6542 Note that this is the case even if the deferred type belongs to a prefix that ha s already been loaded. This is regrettable, since it strongly discourages the us e of type annotations that involve deferred types because Dart programmers use c hecked mode much of the time.
5842 6543
5843 In practice, many scenarios involving deferred loading involve deferred loading of classes that implement eagerly loaded interfaces, so the situation is often l ess onerous than it seems. The current semantics were adopted based on considera tions of ease of implementation. 6544 In practice, many scenarios involving deferred loading involve deferred loading of classes that implement eagerly loaded interfaces, so the situation is often l ess onerous than it seems. The current semantics were adopted based on considera tions of ease of implementation.
5844 6545
5845 Clearly, if a deferred type has not yet been loaded, it is impossible to do a co rrect subtype test involving it, and one would expect a dynamic failure, as is t he case with type tests and casts. By the same token, one would expect checked m ode to work seamlessly once a type had been loaded. We hope to adopt these seman tics in the future; such a change would be upwardly compatible. 6546 Clearly, if a deferred type has not yet been loaded, it is impossible to do a co rrect subtype test involving it, and one would expect a dynamic failure, as is t he case with type tests and casts. By the same token, one would expect checked m ode to work seamlessly once a type had been loaded. We hope to adopt these seman tics in the future; such a change would be upwardly compatible.
5846 6547
5847 } 6548 }
5848 6549
5849 %It is a run-time type error to access an undeclared type outside . 6550 %It is a run-time type error to access an undeclared type outside .
5850 6551
6552 \LMHash{}
5851 %It is a dynamic type error if a malformed type is used in a subtype test. 6553 %It is a dynamic type error if a malformed type is used in a subtype test.
5852 In checked mode, it is a dynamic type error if a deferred, malformed or malbound ed (\ref{parameterizedTypes}) 6554 In checked mode, it is a dynamic type error if a deferred, malformed or malbound ed (\ref{parameterizedTypes})
5853 type is used in a subtype test. 6555 type is used in a subtype test.
5854 6556
5855 %In production mode, an undeclared type is treated as an instance of type \DYNAM IC{}. 6557 %In production mode, an undeclared type is treated as an instance of type \DYNAM IC{}.
5856 6558
5857 \commentary{Consider the following program} 6559 \commentary{Consider the following program}
5858 6560
5859 \begin{dartCode} 6561 \begin{dartCode}
5860 \TYPEDEF{} F(bool x); 6562 \TYPEDEF{} F(bool x);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
5922 bool b = x is I; 6624 bool b = x is I;
5923 \end{dartCode} 6625 \end{dartCode}
5924 6626
5925 \commentary{ 6627 \commentary{
5926 \code{b} is bound to \TRUE, but in checked mode the second line causes a dynamic type error. 6628 \code{b} is bound to \TRUE, but in checked mode the second line causes a dynamic type error.
5927 } 6629 }
5928 6630
5929 6631
5930 6632
5931 \subsection{Type Declarations} 6633 \subsection{Type Declarations}
5932 \label{typeDeclarations} 6634 \LMLabel{typeDeclarations}
5933 6635
5934 \subsubsection{Typedef} 6636 \subsubsection{Typedef}
5935 \label{typedef} 6637 \LMLabel{typedef}
5936 6638
6639 \LMHash{}
5937 A {\em type alias} declares a name for a type expression. 6640 A {\em type alias} declares a name for a type expression.
5938 6641
5939 6642
5940 \begin{grammar} 6643 \begin{grammar}
5941 6644
5942 {\bf typeAlias:} 6645 {\bf typeAlias:}
5943 metadata \TYPEDEF{} typeAliasBody 6646 metadata \TYPEDEF{} typeAliasBody
5944 . 6647 .
5945 6648
5946 {\bf typeAliasBody:} 6649 {\bf typeAliasBody:}
5947 functionTypeAlias 6650 functionTypeAlias
5948 . 6651 .
5949 6652
5950 {\bf functionTypeAlias:} 6653 {\bf functionTypeAlias:}
5951 functionPrefix typeParameters? formalParameterList '{\escapegrammar ;}' 6654 functionPrefix typeParameters? formalParameterList '{\escapegrammar ;}'
5952 . 6655 .
5953 6656
5954 {\bf functionPrefix:} 6657 {\bf functionPrefix:}
5955 returnType? identifier 6658 returnType? identifier
5956 . 6659 .
5957 6660
5958 \end{grammar} 6661 \end{grammar}
5959 6662
6663 \LMHash{}
5960 The effect of a type alias of the form \code{\TYPEDEF{} $T$ $id (T_1$ $p_1, \l dots, T_n$ $p_n, [T_{n+1}$ $p_{n+1}, \ldots, T_{n+k}$ $p_{n+k}])$} declared in a library $L$ is is to introduce the name $id$ into the scope of $L$, bound to th e function type $(T_1, \ldots, T_n, [T_{n+1}$ $p_{n+1}, \ldots, T_{n+k}$ $p_{n+k }]) \rightarrow T$. The effect of a type alias of the form \code{\TYPEDEF{} $T$ $id (T_1$ $p_1, \ldots, T_n$ $p_n, \{T_{n+1}$ $p_{n+1}, \ldots, T_{n+k}$ $p_ {n+k}\})$} declared in a library $L$ is is to introduce the name $id$ into the s cope of $L$, bound to the function type $(T_1, \ldots, T_n, \{T_{n+1}$ $p_{n+1}, \ldots, T_{n+k}$ $p_{n+k}\}) \rightarrow T$. . In either case, iff no return t ype is specified, it is taken to be \DYNAMIC{}. Likewise, if a type annotation i s omitted on a formal parameter, it is taken to be \DYNAMIC{}. 6664 The effect of a type alias of the form \code{\TYPEDEF{} $T$ $id (T_1$ $p_1, \l dots, T_n$ $p_n, [T_{n+1}$ $p_{n+1}, \ldots, T_{n+k}$ $p_{n+k}])$} declared in a library $L$ is is to introduce the name $id$ into the scope of $L$, bound to th e function type $(T_1, \ldots, T_n, [T_{n+1}$ $p_{n+1}, \ldots, T_{n+k}$ $p_{n+k }]) \rightarrow T$. The effect of a type alias of the form \code{\TYPEDEF{} $T$ $id (T_1$ $p_1, \ldots, T_n$ $p_n, \{T_{n+1}$ $p_{n+1}, \ldots, T_{n+k}$ $p_ {n+k}\})$} declared in a library $L$ is is to introduce the name $id$ into the s cope of $L$, bound to the function type $(T_1, \ldots, T_n, \{T_{n+1}$ $p_{n+1}, \ldots, T_{n+k}$ $p_{n+k}\}) \rightarrow T$. . In either case, iff no return t ype is specified, it is taken to be \DYNAMIC{}. Likewise, if a type annotation i s omitted on a formal parameter, it is taken to be \DYNAMIC{}.
5961 6665
6666 \LMHash{}
5962 It is a compile-time error if any default values are specified in the signature of a function type alias. 6667 It is a compile-time error if any default values are specified in the signature of a function type alias.
5963 %A typedef may only refer to itself via the bounds of its generic parameters. 6668 %A typedef may only refer to itself via the bounds of its generic parameters.
5964 Any self reference in a typedef, either directly, or recursively via another ty pedef, is a compile time error. 6669 Any self reference in a typedef, either directly, or recursively via another ty pedef, is a compile time error.
5965 %via a chain of references that does not include a class declaration. 6670 %via a chain of references that does not include a class declaration.
5966 6671
5967 6672
5968 6673
5969 \subsection{Interface Types} 6674 \subsection{Interface Types}
5970 \label{interfaceTypes} 6675 \LMLabel{interfaceTypes}
5971 6676
6677 \LMHash{}
5972 The implicit interface of class $I$ is a direct supertype of the implicit interf ace of class $J$ iff: 6678 The implicit interface of class $I$ is a direct supertype of the implicit interf ace of class $J$ iff:
5973 \begin{itemize} 6679 \begin{itemize}
5974 \item 6680 \item
5975 If $I$ is \code{Object}, and $J$ has no \EXTENDS{} clause% and no interface inje ction declaration has extended $J. 6681 If $I$ is \code{Object}, and $J$ has no \EXTENDS{} clause% and no interface inje ction declaration has extended $J.
5976 \item 6682 \item
5977 If $I$ is listed in the \EXTENDS{} clause of $J$% or an interface injection decl aration has extended $J$ with $I$ 6683 If $I$ is listed in the \EXTENDS{} clause of $J$% or an interface injection decl aration has extended $J$ with $I$
5978 . 6684 .
5979 \item If $I$ is listed in the \IMPLEMENTS{} clause of $J$ 6685 \item If $I$ is listed in the \IMPLEMENTS{} clause of $J$
5980 6686
5981 \item If $I$ is listed in the \WITH{} clause of $J$ 6687 \item If $I$ is listed in the \WITH{} clause of $J$
5982 6688
5983 \item If $J$ is a mixin application (\ref{mixinApplication}) of the mixin of $I$ . 6689 \item If $J$ is a mixin application (\ref{mixinApplication}) of the mixin of $I$ .
5984 \end{itemize} 6690 \end{itemize}
5985 6691
5986 \commentary{ 6692 \commentary{
5987 6693
5988 6694
5989 } 6695 }
5990 6696
5991 %\Q{Can wacky stuff happen with interface injection, e.g., a direct superinterfa ce becomes indirect? What about side effects - loading order can affect type rel ationships. 6697 %\Q{Can wacky stuff happen with interface injection, e.g., a direct superinterfa ce becomes indirect? What about side effects - loading order can affect type rel ationships.
5992 %} 6698 %}
5993 6699
6700 \LMHash{}
5994 A type $T$ is more specific than a type $S$, written $T << S$, if one of the fo llowing conditions is met: 6701 A type $T$ is more specific than a type $S$, written $T << S$, if one of the fo llowing conditions is met:
5995 \begin{itemize} 6702 \begin{itemize}
5996 \item $T$ is $S$. 6703 \item $T$ is $S$.
5997 \item T is $\bot$. 6704 \item T is $\bot$.
5998 \item S is \DYNAMIC{}. 6705 \item S is \DYNAMIC{}.
5999 \item $S$ is a direct supertype of $T$. 6706 \item $S$ is a direct supertype of $T$.
6000 \item $T$ is a type parameter and $S$ is the upper bound of $T$. 6707 \item $T$ is a type parameter and $S$ is the upper bound of $T$.
6001 \item $T$ is a type parameter and $S$ is \cd{Object}. 6708 \item $T$ is a type parameter and $S$ is \cd{Object}.
6002 \item $T$ is of the form $I<T_1, \ldots, T_n>$ and $S$ is of the form $I<S_1, \l dots, S_n>$ and: 6709 \item $T$ is of the form $I<T_1, \ldots, T_n>$ and $S$ is of the form $I<S_1, \l dots, S_n>$ and:
6003 $T_i << S_i, 1 \le i \le n$ 6710 $T_i << S_i, 1 \le i \le n$
6004 \item $T$ and $S$ are both function types, and $T << S$ under the rules of secti on \ref{functionTypes}. 6711 \item $T$ and $S$ are both function types, and $T << S$ under the rules of secti on \ref{functionTypes}.
6005 \item $T$ is a function type and $S$ is \cd{Function}. 6712 \item $T$ is a function type and $S$ is \cd{Function}.
6006 \item $T << U$ and $U << S$. 6713 \item $T << U$ and $U << S$.
6007 \end{itemize} 6714 \end{itemize}
6008 6715
6716 \LMHash{}
6009 $<<$ is a partial order on types. 6717 $<<$ is a partial order on types.
6010 $T$ is a subtype of $S$, written $T <: S$, iff $[\bot/\DYNAMIC{}]T << S$. 6718 $T$ is a subtype of $S$, written $T <: S$, iff $[\bot/\DYNAMIC{}]T << S$.
6011 6719
6012 \rationale{ 6720 \rationale{
6013 Note that $<:$ is not a partial order on types, it is only binary relation on ty pes. This is because $<:$ is not transitive. If it was, the subtype rule would h ave a cycle. For example: 6721 Note that $<:$ is not a partial order on types, it is only binary relation on ty pes. This is because $<:$ is not transitive. If it was, the subtype rule would h ave a cycle. For example:
6014 $List <: List<String>$ and $List<int> <: List$, but $List<int>$ is not a subtype of $List<String>$. 6722 $List <: List<String>$ and $List<int> <: List$, but $List<int>$ is not a subtype of $List<String>$.
6015 Although $<:$ is not a partial order on types, it does contain a partial order, namely $<<$. This means that, barring raw types, intuition about classical subty pe rules does apply. 6723 Although $<:$ is not a partial order on types, it does contain a partial order, namely $<<$. This means that, barring raw types, intuition about classical subty pe rules does apply.
6016 } 6724 }
6017 6725
6726 \LMHash{}
6018 $S$ is a supertype of $T$, written $S :> T$, iff $T$ is a subtype of $S$. 6727 $S$ is a supertype of $T$, written $S :> T$, iff $T$ is a subtype of $S$.
6019 6728
6020 \commentary{The supertypes of an interface are its direct supertypes and their s upertypes. } 6729 \commentary{The supertypes of an interface are its direct supertypes and their s upertypes. }
6021 6730
6731 \LMHash{}
6022 An interface type $T$ may be assigned to a type $S$, written $T \Longleftrighta rrow S$, iff either $T <: S$ or $S <: T$. 6732 An interface type $T$ may be assigned to a type $S$, written $T \Longleftrighta rrow S$, iff either $T <: S$ or $S <: T$.
6023 6733
6024 \rationale{This rule may surprise readers accustomed to conventional typecheckin g. The intent of the $\Longleftrightarrow$ relation is not to ensure that an ass ignment is correct. Instead, it aims to only flag assignments that are almost ce rtain to be erroneous, without precluding assignments that may work. 6734 \rationale{This rule may surprise readers accustomed to conventional typecheckin g. The intent of the $\Longleftrightarrow$ relation is not to ensure that an ass ignment is correct. Instead, it aims to only flag assignments that are almost ce rtain to be erroneous, without precluding assignments that may work.
6025 6735
6026 For example, assigning a value of static type Object to a variable with static t ype String, while not guaranteed to be correct, might be fine if the runtime val ue happens to be a string. 6736 For example, assigning a value of static type Object to a variable with static t ype String, while not guaranteed to be correct, might be fine if the runtime val ue happens to be a string.
6027 } 6737 }
6028 6738
6029 \subsection{Function Types} 6739 \subsection{Function Types}
6030 \label{functionTypes} 6740 \LMLabel{functionTypes}
6031 6741
6742 \LMHash{}
6032 Function types come in two variants: 6743 Function types come in two variants:
6033 \begin{enumerate} 6744 \begin{enumerate}
6034 \item 6745 \item
6035 The types of functions that only have positional parameters. These have the gen eral form $(T_1, \ldots, T_n, [T_{n+1} \ldots, T_{n+k}]) \rightarrow T$. 6746 The types of functions that only have positional parameters. These have the gen eral form $(T_1, \ldots, T_n, [T_{n+1} \ldots, T_{n+k}]) \rightarrow T$.
6036 \item 6747 \item
6037 The types of functions with named parameters. These have the general form $(T_1 , \ldots, T_n, \{T_{x_1}$ $x_1 \ldots, T_{x_k}$ $x_k\}) \rightarrow T$. 6748 The types of functions with named parameters. These have the general form $(T_1 , \ldots, T_n, \{T_{x_1}$ $x_1 \ldots, T_{x_k}$ $x_k\}) \rightarrow T$.
6038 \end{enumerate} 6749 \end{enumerate}
6039 6750
6040 %$(T_1, \ldots T_n) \rightarrow T$ is a subtype of $(S_1, \ldots, S_n, ) \right arrow S$, if all of the following conditions are met: 6751 %$(T_1, \ldots T_n) \rightarrow T$ is a subtype of $(S_1, \ldots, S_n, ) \right arrow S$, if all of the following conditions are met:
6041 %\begin{enumerate} 6752 %\begin{enumerate}
6042 %\item Either 6753 %\item Either
6043 %\begin{itemize} 6754 %\begin{itemize}
6044 %\item $S$ is \VOID{}, Or 6755 %\item $S$ is \VOID{}, Or
6045 %\item $T \Longleftrightarrow S$. 6756 %\item $T \Longleftrightarrow S$.
6046 %\end{itemize} 6757 %\end{itemize}
6047 %\item$ \forall i \in 1 .. n, T_i \Longleftrightarrow S_i$. 6758 %\item$ \forall i \in 1 .. n, T_i \Longleftrightarrow S_i$.
6048 %\end{enumerate} 6759 %\end{enumerate}
6049 6760
6761 \LMHash{}
6050 %A function type $(T_1, \ldots T_n, [T_{n+1} \ldots, T_{n+k}]) \rightarrow T$ i s a subtype of the 6762 %A function type $(T_1, \ldots T_n, [T_{n+1} \ldots, T_{n+k}]) \rightarrow T$ i s a subtype of the
6051 % the line below revises the rule to be more liberal 6763 % the line below revises the rule to be more liberal
6052 A function type $(T_1, \ldots T_{k}, [T_{k+1} \ldots, T_{n+m}]) \rightarrow T$ is a subtype of the 6764 A function type $(T_1, \ldots T_{k}, [T_{k+1} \ldots, T_{n+m}]) \rightarrow T$ is a subtype of the
6053 function type $(S_1, \ldots, S_{k+j}, [S_{k+j+1} \ldots, S_{n}]) \rightarrow S$, if all of the following conditions are met: 6765 function type $(S_1, \ldots, S_{k+j}, [S_{k+j+1} \ldots, S_{n}]) \rightarrow S$, if all of the following conditions are met:
6054 \begin{enumerate} 6766 \begin{enumerate}
6055 \item Either 6767 \item Either
6056 \begin{itemize} 6768 \begin{itemize}
6057 \item $S$ is \VOID{}, Or 6769 \item $S$ is \VOID{}, Or
6058 \item $T \Longleftrightarrow S$. 6770 \item $T \Longleftrightarrow S$.
6059 \end{itemize} 6771 \end{itemize}
6060 \item $\forall i \in 1 .. n, T_i \Longleftrightarrow S_i$. 6772 \item $\forall i \in 1 .. n, T_i \Longleftrightarrow S_i$.
6061 \end{enumerate} 6773 \end{enumerate}
6062 6774
6063 6775
6776 \LMHash{}
6064 A function type $(T_1, \ldots T_n, \{T_{x_1}$ $x_1, \ldots, T_{x_k}$ $x_k\}) \ri ghtarrow T$ is a subtype of the function type $(S_1, \ldots, S_n, \{S_{y_1}$ $y_ 1, \ldots, S_{y_m}$ $y_m\}) \rightarrow S$, if all of the following conditions a re met: 6777 A function type $(T_1, \ldots T_n, \{T_{x_1}$ $x_1, \ldots, T_{x_k}$ $x_k\}) \ri ghtarrow T$ is a subtype of the function type $(S_1, \ldots, S_n, \{S_{y_1}$ $y_ 1, \ldots, S_{y_m}$ $y_m\}) \rightarrow S$, if all of the following conditions a re met:
6065 \begin{enumerate} 6778 \begin{enumerate}
6066 \item Either 6779 \item Either
6067 \begin{itemize} 6780 \begin{itemize}
6068 \item $S$ is \VOID{}, Or 6781 \item $S$ is \VOID{}, Or
6069 \item $T \Longleftrightarrow S$. 6782 \item $T \Longleftrightarrow S$.
6070 \end{itemize} 6783 \end{itemize}
6071 \item $\forall i \in 1 .. n, T_i \Longleftrightarrow S_i$. 6784 \item $\forall i \in 1 .. n, T_i \Longleftrightarrow S_i$.
6072 \item $k \ge m$ and $y_i \in \{x_1, \ldots, x_k\}, i \in 1 .. m$. 6785 \item $k \ge m$ and $y_i \in \{x_1, \ldots, x_k\}, i \in 1 .. m$.
6073 %\{x_1, \ldots, x_k\}$ is a superset of $\{y_1, \ldots, y_m\}$. 6786 %\{x_1, \ldots, x_k\}$ is a superset of $\{y_1, \ldots, y_m\}$.
6074 \item For all $y_i \in \{y_1, \ldots, y_m\}, y_i = x_j \Rightarrow T_j \Longlef trightarrow S_i$ 6787 \item For all $y_i \in \{y_1, \ldots, y_m\}, y_i = x_j \Rightarrow T_j \Longlef trightarrow S_i$
6075 \end{enumerate} 6788 \end{enumerate}
6076 6789
6077 %In addition, a function type $(T_1, \ldots, Tn, [T_{n+1} x_{n+1}, \ldots, T_{n+ k} x_{n+k}]) \rightarrow T$ is a subtype of the function type $(T_1, \ldots, T_n , T_{n+1} , [T_{n+2} x_{n+2}, \ldots, T_{n+k} x_{n+k}]) \rightarrow T$. 6790 %In addition, a function type $(T_1, \ldots, Tn, [T_{n+1} x_{n+1}, \ldots, T_{n+ k} x_{n+k}]) \rightarrow T$ is a subtype of the function type $(T_1, \ldots, T_n , T_{n+1} , [T_{n+2} x_{n+2}, \ldots, T_{n+k} x_{n+k}]) \rightarrow T$.
6078 6791
6079 %\rationale{This second rule is attractive to web developers, who are used to th is sort of flexibility from Javascript. However, it may be costly to implement e fficiently.} \Q{Should we do this or not?} 6792 %\rationale{This second rule is attractive to web developers, who are used to th is sort of flexibility from Javascript. However, it may be costly to implement e fficiently.} \Q{Should we do this or not?}
6080 6793
6081 %We write $(T_1, \ldots, T_n) \rightarrow T$ as a shorthand for the type $(T_1, \ldots, T_n, []) \rightarrow T$. 6794 %We write $(T_1, \ldots, T_n) \rightarrow T$ as a shorthand for the type $(T_1, \ldots, T_n, []) \rightarrow T$.
6082 6795
6083 %The rules above need to be sanity checked, but the intent is that we view funct ions with rest parameters as having type $(T_1, ..., T_n, [\_{Tn+1}[] \_]) \righ tarrow T$, where \_ is some magical identifier. Then the rules above may cover e verything. 6796 %The rules above need to be sanity checked, but the intent is that we view funct ions with rest parameters as having type $(T_1, ..., T_n, [\_{Tn+1}[] \_]) \righ tarrow T$, where \_ is some magical identifier. Then the rules above may cover e verything.
6084 % This is wrong - from the outside, the type takes an unbounded sequence of type s, not a list. This can be modeled as $(T_1, \ldots, T_n, [T_{n+1}, \_ \ldots, T _{n+k} \_]) \rightarrow T$ for some finite $k$. 6797 % This is wrong - from the outside, the type takes an unbounded sequence of type s, not a list. This can be modeled as $(T_1, \ldots, T_n, [T_{n+1}, \_ \ldots, T _{n+k} \_]) \rightarrow T$ for some finite $k$.
6085 6798
6799 \LMHash{}
6086 In addition, the following subtype rules apply: 6800 In addition, the following subtype rules apply:
6087 6801
6088 6802
6089 $(T_1, \ldots, T_n, []) \rightarrow T <: (T_1, \ldots, T_n) \rightarrow T$. 6803 $(T_1, \ldots, T_n, []) \rightarrow T <: (T_1, \ldots, T_n) \rightarrow T$.
6090 6804
6091 $(T_1, \ldots, T_n) \rightarrow T <: (T_1, \ldots, T_n, \{\}) \rightarrow T$. 6805 $(T_1, \ldots, T_n) \rightarrow T <: (T_1, \ldots, T_n, \{\}) \rightarrow T$.
6092 6806
6093 $(T_1, \ldots, T_n, \{\}) \rightarrow T <: (T_1, \ldots, T_n) \rightarrow T$. 6807 $(T_1, \ldots, T_n, \{\}) \rightarrow T <: (T_1, \ldots, T_n) \rightarrow T$.
6094 6808
6095 $(T_1, \ldots, T_n) \rightarrow T <: (T_1, \ldots, T_n, []) \rightarrow T$. 6809 $(T_1, \ldots, T_n) \rightarrow T <: (T_1, \ldots, T_n, []) \rightarrow T$.
6096 6810
6097 \rationale{ 6811 \rationale{
6098 The naive reader might conclude that, since it is not legal to declare a functio n with an empty optional parameter list, these rules are pointless. However, the y induce useful relationships between function types that declare no optional p arameters and those that do. 6812 The naive reader might conclude that, since it is not legal to declare a functio n with an empty optional parameter list, these rules are pointless. However, the y induce useful relationships between function types that declare no optional p arameters and those that do.
6099 } 6813 }
6100 6814
6815 \LMHash{}
6101 A function type $T$ may be assigned to a function type $S$, written $T \Longlef trightarrow S$, iff $T <: S$. 6816 A function type $T$ may be assigned to a function type $S$, written $T \Longlef trightarrow S$, iff $T <: S$.
6102 6817
6818 \LMHash{}
6103 % ensure that Object and dynamic may be assign dot a function type 6819 % ensure that Object and dynamic may be assign dot a function type
6104 A function is always an instance of some class that implements the class \code{F unction} and implements a \CALL{} method with the same signature as the function . All function types are subtypes of \code{Function}. 6820 A function is always an instance of some class that implements the class \code{F unction} and implements a \CALL{} method with the same signature as the function . All function types are subtypes of \code{Function}.
6105 If a type $I$ includes an instance method named \CALL{}, and the type of \CALL{} is the function type $F$, then $I$ is considered to be more specific than $F$. It is a static warning if a concrete class implements \cd{Function} and does no t have a concrete method named \CALL{} unless that class declares its own implem entation of \cd{noSuchMethod()}. 6821 If a type $I$ includes an instance method named \CALL{}, and the type of \CALL{} is the function type $F$, then $I$ is considered to be more specific than $F$. It is a static warning if a concrete class implements \cd{Function} and does no t have a concrete method named \CALL{} unless that class declares its own implem entation of \cd{noSuchMethod()}.
6106 6822
6107 6823
6108 6824
6109 6825
6110 %\commentary{Need to specify how a function values dynamic type is derived from its static signature.} 6826 %\commentary{Need to specify how a function values dynamic type is derived from its static signature.}
6111 6827
6828 \LMHash{}
6112 A function type $(T_1, \ldots T_{k}, [T_{k+1} \ldots, T_{n+m}]) \rightarrow T$ is a more specific than the 6829 A function type $(T_1, \ldots T_{k}, [T_{k+1} \ldots, T_{n+m}]) \rightarrow T$ is a more specific than the
6113 function type $(S_1, \ldots, S_{k+j}, [S_{k+j+1} \ldots, S_{n}]) \rightarrow S$, if all of the following conditions are met: 6830 function type $(S_1, \ldots, S_{k+j}, [S_{k+j+1} \ldots, S_{n}]) \rightarrow S$, if all of the following conditions are met:
6114 \begin{enumerate} 6831 \begin{enumerate}
6115 \item Either 6832 \item Either
6116 \begin{itemize} 6833 \begin{itemize}
6117 \item $S$ is \VOID{}, Or 6834 \item $S$ is \VOID{}, Or
6118 \item $T << S$. 6835 \item $T << S$.
6119 \end{itemize} 6836 \end{itemize}
6120 \item $\forall i \in 1 .. n, T_i << S_i$. 6837 \item $\forall i \in 1 .. n, T_i << S_i$.
6121 \end{enumerate} 6838 \end{enumerate}
6122 6839
6123 6840
6841 \LMHash{}
6124 A function type $(T_1, \ldots T_n, \{T_{x_1}$ $x_1, \ldots, T_{x_k}$ $x_k\}) \ri ghtarrow T$ is more specific than the function type $(S_1, \ldots, S_n, \{S_{y_1 }$ $y_1, \ldots, S_{y_m}$ $y_m\}) \rightarrow S$, if all of the following condit ions are met: 6842 A function type $(T_1, \ldots T_n, \{T_{x_1}$ $x_1, \ldots, T_{x_k}$ $x_k\}) \ri ghtarrow T$ is more specific than the function type $(S_1, \ldots, S_n, \{S_{y_1 }$ $y_1, \ldots, S_{y_m}$ $y_m\}) \rightarrow S$, if all of the following condit ions are met:
6125 \begin{enumerate} 6843 \begin{enumerate}
6126 \item Either 6844 \item Either
6127 \begin{itemize} 6845 \begin{itemize}
6128 \item $S$ is \VOID{}, Or 6846 \item $S$ is \VOID{}, Or
6129 \item $T << S$. 6847 \item $T << S$.
6130 \end{itemize} 6848 \end{itemize}
6131 \item $\forall i \in 1 .. n, T_i << S_i$. 6849 \item $\forall i \in 1 .. n, T_i << S_i$.
6132 \item $k \ge m$ and $y_i \in \{x_1, \ldots, x_k\}, i \in 1 .. m$. 6850 \item $k \ge m$ and $y_i \in \{x_1, \ldots, x_k\}, i \in 1 .. m$.
6133 %\{x_1, \ldots, x_k\}$ is a superset of $\{y_1, \ldots, y_m\}$. 6851 %\{x_1, \ldots, x_k\}$ is a superset of $\{y_1, \ldots, y_m\}$.
6134 \item For all $y_i \in \{y_1, \ldots, y_m\}, y_i = x_j \Rightarrow T_j << S_i$ 6852 \item For all $y_i \in \{y_1, \ldots, y_m\}, y_i = x_j \Rightarrow T_j << S_i$
6135 \end{enumerate} 6853 \end{enumerate}
6136 6854
6855 \LMHash{}
6137 Furthermore, if $F$ is a function type, $F << \code{Function}$. 6856 Furthermore, if $F$ is a function type, $F << \code{Function}$.
6138 6857
6139 6858
6140 \subsection{Type \DYNAMIC{}} 6859 \subsection{Type \DYNAMIC{}}
6141 \label{typeDynamic} 6860 \LMLabel{typeDynamic}
6142 6861
6862 \LMHash{}
6143 The type \DYNAMIC{} denotes the unknown type. 6863 The type \DYNAMIC{} denotes the unknown type.
6144 6864
6865 \LMHash{}
6145 If no static type annotation has been provided the type system assumes the decla ration has the unknown type. If a generic type is used but type arguments are no t provided, then the type arguments default to the unknown type. 6866 If no static type annotation has been provided the type system assumes the decla ration has the unknown type. If a generic type is used but type arguments are no t provided, then the type arguments default to the unknown type.
6146 6867
6147 \commentary{This means that given a generic declaration $G<T_1, \ldots, T_n>$, t he type $G$ is equivalent to $G< \DYNAMIC{}, \ldots, \DYNAMIC{}>$. 6868 \commentary{This means that given a generic declaration $G<T_1, \ldots, T_n>$, t he type $G$ is equivalent to $G< \DYNAMIC{}, \ldots, \DYNAMIC{}>$.
6148 } 6869 }
6149 6870
6871 \LMHash{}
6150 Type \DYNAMIC{} has methods for every possible identifier and arity, with every possible combination of named parameters. These methods all have \DYNAMIC{} as their return type, and their formal parameters all have type \DYNAMIC{}. 6872 Type \DYNAMIC{} has methods for every possible identifier and arity, with every possible combination of named parameters. These methods all have \DYNAMIC{} as their return type, and their formal parameters all have type \DYNAMIC{}.
6151 Type \DYNAMIC{} has properties for every possible identifier. These properties all have type \DYNAMIC{}. 6873 Type \DYNAMIC{} has properties for every possible identifier. These properties all have type \DYNAMIC{}.
6152 6874
6153 \rationale{From a usability perspective, we want to ensure that the checker does not issue errors everywhere an unknown type is used. The definitions above ensu re that no secondary errors are reported when accessing an unknown type. 6875 \rationale{From a usability perspective, we want to ensure that the checker does not issue errors everywhere an unknown type is used. The definitions above ensu re that no secondary errors are reported when accessing an unknown type.
6154 6876
6155 The current rules say that missing type arguments are treated as if they were th e type \DYNAMIC{}. An alternative is to consider them as meaning \code{Object} . This would lead to earlier error detection in checked mode, and more aggressi ve errors during static typechecking. For example: 6877 The current rules say that missing type arguments are treated as if they were th e type \DYNAMIC{}. An alternative is to consider them as meaning \code{Object} . This would lead to earlier error detection in checked mode, and more aggressi ve errors during static typechecking. For example:
6156 6878
6157 (1) \code{typedAPI(G\lt{String}\gt g)\{...\}} 6879 (1) \code{typedAPI(G\lt{String}\gt g)\{...\}}
6158 6880
6159 6881
6160 (2) \code{typedAPI(new G()); } 6882 (2) \code{typedAPI(new G()); }
6161 6883
6162 6884
6163 Under the alternative rules, (2) would cause a runtime error in checked mode. Th is seems desirable from the perspective of error localization. However, when a d ynamic error is thrown at (2), the only way to keep running is rewriting (2) int o 6885 Under the alternative rules, (2) would cause a runtime error in checked mode. Th is seems desirable from the perspective of error localization. However, when a d ynamic error is thrown at (2), the only way to keep running is rewriting (2) int o
6164 6886
6165 (3) \code{typedAPI(new G\lt{String}\gt());} 6887 (3) \code{typedAPI(new G\lt{String}\gt());}
6166 6888
6167 This forces users to write type information in their client code just because th ey are calling a typed API. We do not want to impose this on Dart programmers, some of which may be blissfully unaware of types in general, and genericity in p articular. 6889 This forces users to write type information in their client code just because th ey are calling a typed API. We do not want to impose this on Dart programmers, some of which may be blissfully unaware of types in general, and genericity in p articular.
6168 6890
6169 What of static checking? Surely we would want to flag (2) when users have explic itly asked for static typechecking? Yes, but the reality is that the Dart static checker is likely to be running in the background by default. Engineering teams typically desire a ``clean build'' free of warnings and so the checker is desig ned to be extremely charitable. Other tools can interpret the type information m ore aggressively and warn about violations of conventional (and sound) static ty pe discipline. 6891 What of static checking? Surely we would want to flag (2) when users have explic itly asked for static typechecking? Yes, but the reality is that the Dart static checker is likely to be running in the background by default. Engineering teams typically desire a ``clean build'' free of warnings and so the checker is desig ned to be extremely charitable. Other tools can interpret the type information m ore aggressively and warn about violations of conventional (and sound) static ty pe discipline.
6170 } 6892 }
6171 6893
6894 \LMHash{}
6172 The name \DYNAMIC{} denotes a \cd{Type} object even though \DYNAMIC{} is not a c lass. 6895 The name \DYNAMIC{} denotes a \cd{Type} object even though \DYNAMIC{} is not a c lass.
6173 6896
6174 %\rationale { 6897 %\rationale {
6175 %Type objects reify the runtime types of instances. No instance ever has type \D YNAMIC{}. 6898 %Type objects reify the runtime types of instances. No instance ever has type \D YNAMIC{}.
6176 %} 6899 %}
6177 6900
6178 \subsection{Type Void} 6901 \subsection{Type Void}
6179 \label{typeVoid} 6902 \LMLabel{typeVoid}
6180 6903
6904 \LMHash{}
6181 The special type \VOID{} may only be used as the return type of a function: it i s a compile-time error to use \VOID{} in any other context. 6905 The special type \VOID{} may only be used as the return type of a function: it i s a compile-time error to use \VOID{} in any other context.
6182 6906
6183 \commentary{ 6907 \commentary{
6184 For example, as a type argument, or as the type of a variable or parameter 6908 For example, as a type argument, or as the type of a variable or parameter
6185 6909
6186 Void is not an interface type. 6910 Void is not an interface type.
6187 6911
6188 The only subtype relations that pertain to void are therefore: 6912 The only subtype relations that pertain to void are therefore:
6189 \begin{itemize} 6913 \begin{itemize}
6190 \item 6914 \item
(...skipping 14 matching lines...) Expand all
6205 \commentary {The name \VOID{} does not denote a \cd{Type} object.} 6929 \commentary {The name \VOID{} does not denote a \cd{Type} object.}
6206 6930
6207 \rationale { 6931 \rationale {
6208 It is syntacticly illegal to use \VOID{} as an expression, and it would make no sense to do so. 6932 It is syntacticly illegal to use \VOID{} as an expression, and it would make no sense to do so.
6209 Type objects reify the runtime types of instances. No instance ever has type \VO ID{}. 6933 Type objects reify the runtime types of instances. No instance ever has type \VO ID{}.
6210 } 6934 }
6211 6935
6212 6936
6213 6937
6214 \subsection{Parameterized Types} 6938 \subsection{Parameterized Types}
6215 \label{parameterizedTypes} 6939 \LMLabel{parameterizedTypes}
6216 6940
6941 \LMHash{}
6217 A {\em parameterized type} is an invocation of a generic type declaration. 6942 A {\em parameterized type} is an invocation of a generic type declaration.
6218 6943
6944 \LMHash{}
6219 Let $T$ be a parameterized type $G<S_1, \ldots, S_n>$. If $G$ is not a generic type, the type arguments $S_i$, $1 \le i \le n$ are discarded. If $G$ has $m \n e n$ type parameters, $T$ is treated as as a parameterized type with $m$ argumen ts, all of which are \DYNAMIC{}. 6945 Let $T$ be a parameterized type $G<S_1, \ldots, S_n>$. If $G$ is not a generic type, the type arguments $S_i$, $1 \le i \le n$ are discarded. If $G$ has $m \n e n$ type parameters, $T$ is treated as as a parameterized type with $m$ argumen ts, all of which are \DYNAMIC{}.
6220 6946
6221 \commentary{In short, any arity mismatch results in all type arguments being dro pped, and replaced with the correct number of type arguments, all set to \DYNAMI C{}. Of course, a static warning will be issued. 6947 \commentary{In short, any arity mismatch results in all type arguments being dro pped, and replaced with the correct number of type arguments, all set to \DYNAMI C{}. Of course, a static warning will be issued.
6222 } 6948 }
6223 6949
6950 \LMHash{}
6224 Otherwise, let 6951 Otherwise, let
6225 $T_i$ be the type parameters of $G$ and let $B_i$ be the bound of $T_i, i \in 1.. n$,. $T$ is {\em malbounded} iff either $S_i$ is malbounded or $S_i$ is not a subtype of $[S_1, \ldots, S_n/T_1, \ldots, T_n]B_i, i \in 1.. n$. 6952 $T_i$ be the type parameters of $G$ and let $B_i$ be the bound of $T_i, i \in 1.. n$,. $T$ is {\em malbounded} iff either $S_i$ is malbounded or $S_i$ is not a subtype of $[S_1, \ldots, S_n/T_1, \ldots, T_n]B_i, i \in 1.. n$.
6226 6953
6227 \commentary{ 6954 \commentary{
6228 Note, that, in checked mode, it is a dynamic type error if a malbounded type is used in a type test as specified in \ref{dynamicTypeSystem}. 6955 Note, that, in checked mode, it is a dynamic type error if a malbounded type is used in a type test as specified in \ref{dynamicTypeSystem}.
6229 } 6956 }
6230 6957
6958 \LMHash{}
6231 Any use of a malbounded type gives rise to a static warning. 6959 Any use of a malbounded type gives rise to a static warning.
6232 6960
6961 \LMHash{}
6233 If $S$ is the static type of a member $m$ of $G$, then the static type of the me mber $m$ of $G<A_1, \ldots, A_n>$ is $[A_1, \ldots, A_n/T_1, \ldots, T_n]S$ where $T_1, \ldots, T_n$ are the formal type parameters of $G$. Let $B_i$, be the bounds of $T_i, 1 \le i \le n$. It is a static type warning if $A_i$ is not a subtype of $[A_1, \ldots, A_n/T_1, \ldots, T_n]B_i, i \in 1..n$. It is a s tatic type warning if $G$ is not a generic type with exactly $n$ type parameters . 6962 If $S$ is the static type of a member $m$ of $G$, then the static type of the me mber $m$ of $G<A_1, \ldots, A_n>$ is $[A_1, \ldots, A_n/T_1, \ldots, T_n]S$ where $T_1, \ldots, T_n$ are the formal type parameters of $G$. Let $B_i$, be the bounds of $T_i, 1 \le i \le n$. It is a static type warning if $A_i$ is not a subtype of $[A_1, \ldots, A_n/T_1, \ldots, T_n]B_i, i \in 1..n$. It is a s tatic type warning if $G$ is not a generic type with exactly $n$ type parameters .
6234 6963
6235 6964
6236 6965
6237 6966
6238 6967
6239 \subsubsection{Actual Type of Declaration} 6968 \subsubsection{Actual Type of Declaration}
6240 \label{actualTypeOfADeclaration} 6969 \LMLabel{actualTypeOfADeclaration}
6241 6970
6971 \LMHash{}
6242 A type $T$ {\em depends on a type parameter} $U$ iff: 6972 A type $T$ {\em depends on a type parameter} $U$ iff:
6243 \begin{itemize} 6973 \begin{itemize}
6244 \item $T$ is $U$. 6974 \item $T$ is $U$.
6245 \item $T$ is a parameterized type, and one of the type arguments of $T$ depends on $U$. 6975 \item $T$ is a parameterized type, and one of the type arguments of $T$ depends on $U$.
6246 \end{itemize} 6976 \end{itemize}
6247 6977
6978 \LMHash{}
6248 Let $T$ be the declared type of a declaration $d$, as it appears in the program source. The {\em actual type} of $d$ is 6979 Let $T$ be the declared type of a declaration $d$, as it appears in the program source. The {\em actual type} of $d$ is
6249 6980
6250 \begin{itemize} 6981 \begin{itemize}
6251 \item $[A_1, \ldots, A_n/U_1, \ldots, U_n]T$ if $d$ depends on type parameters $U_1, \ldots, U_n$, and $A_i$ is the value of $U_i, 1 \le i \le n$. 6982 \item $[A_1, \ldots, A_n/U_1, \ldots, U_n]T$ if $d$ depends on type parameters $U_1, \ldots, U_n$, and $A_i$ is the value of $U_i, 1 \le i \le n$.
6252 \item $T$ otherwise. 6983 \item $T$ otherwise.
6253 \end{itemize} 6984 \end{itemize}
6254 6985
6255 \subsubsection{Least Upper Bounds} 6986 \subsubsection{Least Upper Bounds}
6256 \label{leastUpperBounds} 6987 \LMLabel{leastUpperBounds}
6257 6988
6989 \LMHash{}
6258 % does this diverge in some cases? 6990 % does this diverge in some cases?
6259 Given two interfaces $I$ and $J$, let $S_I$ be the set of superinterfaces of $I$ , let $S_J$ be the set of superinterfaces of $J$ and let $S = (I \cup S_I) \ca p (J \cup S_J)$. Furthermore, we define $S_n = \{T | T \in S \wedge depth(T) = n\}$ for any finite $n$ %, and $k=max(depth(T_1), \ldots, depth(T_m)), T_i \in S , i \in 1..m$, 6991 Given two interfaces $I$ and $J$, let $S_I$ be the set of superinterfaces of $I$ , let $S_J$ be the set of superinterfaces of $J$ and let $S = (I \cup S_I) \ca p (J \cup S_J)$. Furthermore, we define $S_n = \{T | T \in S \wedge depth(T) = n\}$ for any finite $n$ %, and $k=max(depth(T_1), \ldots, depth(T_m)), T_i \in S , i \in 1..m$,
6260 where $depth(T)$ is the number of steps in the longest inheritance path from $T$ to \code{Object}. Let $q$ be the largest number such that $S_q$ has cardinality one. The least upper bound of $I$ and $J$ is the sole element of $S_q$. 6992 where $depth(T)$ is the number of steps in the longest inheritance path from $T$ to \code{Object}. Let $q$ be the largest number such that $S_q$ has cardinality one. The least upper bound of $I$ and $J$ is the sole element of $S_q$.
6261 6993
6994 \LMHash{}
6262 The least upper bound of \DYNAMIC{} and any type $T$ is \DYNAMIC{}. 6995 The least upper bound of \DYNAMIC{} and any type $T$ is \DYNAMIC{}.
6263 The least upper bound of \VOID{} and any type $T \ne \DYNAMIC{}$ is \VOID{}. 6996 The least upper bound of \VOID{} and any type $T \ne \DYNAMIC{}$ is \VOID{}.
6264 Let $U$ be a type variable with upper bound $B$. The least upper bound of $U$ an d a type $T$ is the least upper bound of $B$ and $T$. 6997 Let $U$ be a type variable with upper bound $B$. The least upper bound of $U$ an d a type $T$ is the least upper bound of $B$ and $T$.
6265 6998
6999 \LMHash{}
6266 The least upper bound relation is symmetric and reflexive. 7000 The least upper bound relation is symmetric and reflexive.
6267 7001
6268 % Function types 7002 % Function types
6269 7003
7004 \LMHash{}
6270 The least upper bound of a function type and an interface type $T$ is the least upper bound of \cd{Function} and $T$. 7005 The least upper bound of a function type and an interface type $T$ is the least upper bound of \cd{Function} and $T$.
6271 Let $F$ and $G$ be function types. If $F$ and $G$ differ in their number of requ ired parameters, then the least upper bound of $F$ and $G$ is \cd{Function}. Ot herwise: 7006 Let $F$ and $G$ be function types. If $F$ and $G$ differ in their number of requ ired parameters, then the least upper bound of $F$ and $G$ is \cd{Function}. Ot herwise:
6272 \begin{itemize} 7007 \begin{itemize}
6273 \item If 7008 \item If
6274 7009
6275 $F= (T_1 \ldots T_r, [T_{r+1}, \ldots, T_n]) \longrightarrow T_0$, 7010 $F= (T_1 \ldots T_r, [T_{r+1}, \ldots, T_n]) \longrightarrow T_0$,
6276 7011
6277 $G= (S_1 \ldots S_r, [S_{r+1}, \ldots, S_k]) \longrightarrow S_0$ 7012 $G= (S_1 \ldots S_r, [S_{r+1}, \ldots, S_k]) \longrightarrow S_0$
6278 7013
6279 where $k \le n$ then the least upper bound of $F$ and $G$ is 7014 where $k \le n$ then the least upper bound of $F$ and $G$ is
(...skipping 22 matching lines...) Expand all
6302 then let $\{x_m, \ldots x_n\} = \{p_{r+1}, \ldots, p_f\} \cap \{q_{r+1}, \ldots , q_g\}$ and let $X_j$ be the least upper bound of the types of $x_j$ in $F$ and $G, j \in m..n$. Then 7037 then let $\{x_m, \ldots x_n\} = \{p_{r+1}, \ldots, p_f\} \cap \{q_{r+1}, \ldots , q_g\}$ and let $X_j$ be the least upper bound of the types of $x_j$ in $F$ and $G, j \in m..n$. Then
6303 the least upper bound of $F$ and $G$ is 7038 the least upper bound of $F$ and $G$ is
6304 7039
6305 $(L_1 \ldots L_r, \{ X_m$ $x_m, \ldots, X_n$ $x_n\}) \longrightarrow L_0$ 7040 $(L_1 \ldots L_r, \{ X_m$ $x_m, \ldots, X_n$ $x_n\}) \longrightarrow L_0$
6306 7041
6307 where $L_i$ is the least upper bound of $T_i$ and $S_i, i \in 0..r$ 7042 where $L_i$ is the least upper bound of $T_i$ and $S_i, i \in 0..r$
6308 \end{itemize} 7043 \end{itemize}
6309 7044
6310 7045
6311 \section{Reference} 7046 \section{Reference}
6312 \label{reference} 7047 \LMLabel{reference}
6313 7048
6314 \subsection{Lexical Rules} 7049 \subsection{Lexical Rules}
6315 \label{lexicalRules} 7050 \LMLabel{lexicalRules}
6316 7051
7052 \LMHash{}
6317 Dart source text is represented as a sequence of Unicode code points. This sequ ence is first converted into a sequence of tokens according to the lexical rules given in this specification. At any point in the tokenization process, the lon gest possible token is recognized. 7053 Dart source text is represented as a sequence of Unicode code points. This sequ ence is first converted into a sequence of tokens according to the lexical rules given in this specification. At any point in the tokenization process, the lon gest possible token is recognized.
6318 7054
6319 \subsubsection{Reserved Words} 7055 \subsubsection{Reserved Words}
6320 \label{reservedWords} 7056 \LMLabel{reservedWords}
6321 7057
7058 \LMHash{}
6322 A {\em reserved word} may not be used as an identifier; it is a compile-time err or if a reserved word is used where an identifier is expected. 7059 A {\em reserved word} may not be used as an identifier; it is a compile-time err or if a reserved word is used where an identifier is expected.
6323 7060
6324 \ASSERT{}, \BREAK{}, \CASE{}, \CATCH{}, \CLASS{}, \CONST{}, \CONTINUE{}, \DEFAUL T{}, \DO{}, \ELSE{}, \ENUM{}, \EXTENDS{}, \FALSE{}, \FINAL{}, \FINALLY{}, \FOR{} , \IF{}, \IN{}, \IS{}, \NEW{}, \NULL{}, \RETHROW, \RETURN{}, \SUPER{}, \SWITCH{} , \THIS{}, \THROW{}, \TRUE{}, \TRY{}, \VAR{}, \VOID{}, \WHILE{}, \WITH{}. 7061 \ASSERT{}, \BREAK{}, \CASE{}, \CATCH{}, \CLASS{}, \CONST{}, \CONTINUE{}, \DEFAUL T{}, \DO{}, \ELSE{}, \ENUM{}, \EXTENDS{}, \FALSE{}, \FINAL{}, \FINALLY{}, \FOR{} , \IF{}, \IN{}, \IS{}, \NEW{}, \NULL{}, \RETHROW, \RETURN{}, \SUPER{}, \SWITCH{} , \THIS{}, \THROW{}, \TRUE{}, \TRY{}, \VAR{}, \VOID{}, \WHILE{}, \WITH{}.
6325 7062
6326 7063
6327 7064
6328 %\Q{Unicode characters.} 7065 %\Q{Unicode characters.}
6329 7066
6330 \begin{grammar} 7067 \begin{grammar}
6331 {\bf LETTER:}`a' {\escapegrammar ..} `z'; 7068 {\bf LETTER:}`a' {\escapegrammar ..} `z';
6332 `A' {\escapegrammar ..}`Z' 7069 `A' {\escapegrammar ..}`Z'
6333 . 7070 .
6334 7071
6335 {\bf DIGIT:} 7072 {\bf DIGIT:}
6336 `0' {\escapegrammar ..} `9' 7073 `0' {\escapegrammar ..} `9'
6337 . 7074 .
6338 7075
6339 {\bf WHITESPACE:} 7076 {\bf WHITESPACE:}
6340 (`$\backslash$t' $|$ ` ' $|$ NEWLINE)+ 7077 (`$\backslash$t' $|$ ` ' $|$ NEWLINE)+
6341 . 7078 .
6342 \end{grammar} 7079 \end{grammar}
6343 7080
6344 \subsubsection{Comments} 7081 \subsubsection{Comments}
6345 \label{comments} 7082 \LMLabel{comments}
6346 7083
7084 \LMHash{}
6347 {\em Comments} are sections of program text that are used for documentation. 7085 {\em Comments} are sections of program text that are used for documentation.
6348 7086
6349 \begin{grammar}{\bf SINGLE\_LINE\_COMMENT:} 7087 \begin{grammar}{\bf SINGLE\_LINE\_COMMENT:}
6350 `//' \~{}(NEWLINE)* (NEWLINE)? 7088 `//' \~{}(NEWLINE)* (NEWLINE)?
6351 . 7089 .
6352 7090
6353 {\bf MULTI\_LINE\_COMMENT:} 7091 {\bf MULTI\_LINE\_COMMENT:}
6354 `/*' (MULTI\_LINE\_COMMENT $|$ \~{} `*/')* `*/' 7092 `/*' (MULTI\_LINE\_COMMENT $|$ \~{} `*/')* `*/'
6355 . 7093 .
6356 \end{grammar} 7094 \end{grammar}
6357 7095
7096 \LMHash{}
6358 Dart supports both single-line and multi-line comments. A {\em single line comme nt} begins with the token \code{//}. Everything between \code{//} and the end of line must be ignored by the Dart compiler unless the comment is a documentation comment. . 7097 Dart supports both single-line and multi-line comments. A {\em single line comme nt} begins with the token \code{//}. Everything between \code{//} and the end of line must be ignored by the Dart compiler unless the comment is a documentation comment. .
6359 7098
7099 \LMHash{}
6360 A {\em multi-line comment} begins with the token \code{/*} and ends with the tok en \code{*/}. Everything between \code{/}* and \code{*}/ must be ignored by the Dart compiler unless the comment is a documentation comment. Comments may nest. 7100 A {\em multi-line comment} begins with the token \code{/*} and ends with the tok en \code{*/}. Everything between \code{/}* and \code{*}/ must be ignored by the Dart compiler unless the comment is a documentation comment. Comments may nest.
6361 7101
7102 \LMHash{}
6362 {\em Documentation comments} are comments that begin with the tokens \code{///} or \code{/**}. Documentation comments are intended to be processed by a tool t hat produces human readable documentation. 7103 {\em Documentation comments} are comments that begin with the tokens \code{///} or \code{/**}. Documentation comments are intended to be processed by a tool t hat produces human readable documentation.
6363 7104
7105 \LMHash{}
6364 The scope of a documentation comment always excludes the imported namespace of the enclosing library. Only names declared in the enclosing library are consider ed in scope within a documentation comment. 7106 The scope of a documentation comment always excludes the imported namespace of the enclosing library. Only names declared in the enclosing library are consider ed in scope within a documentation comment.
6365 7107
7108 \LMHash{}
6366 The scope of a documentation comment immediately preceding the declaration of a class $C$ is the instance scope of $C$, excluding any names introduced via the i mport namespace of the enclosing library. 7109 The scope of a documentation comment immediately preceding the declaration of a class $C$ is the instance scope of $C$, excluding any names introduced via the i mport namespace of the enclosing library.
6367 7110
7111 \LMHash{}
6368 The scope of a documentation comment immediately preceding the declaration of a function $f$ is the scope in force at the very beginning of the body of $f$, excluding any names introduced via the import namespace of the enclosing library . 7112 The scope of a documentation comment immediately preceding the declaration of a function $f$ is the scope in force at the very beginning of the body of $f$, excluding any names introduced via the import namespace of the enclosing library .
6369 7113
6370 7114
6371 7115
6372 7116
6373 7117
6374 %\subsection{Grammar} 7118 %\subsection{Grammar}
6375 \subsection{Operator Precedence} 7119 \subsection{Operator Precedence}
6376 \label{operatorPrecedence} 7120 \LMLabel{operatorPrecedence}
6377 7121
7122 \LMHash{}
6378 Operator precedence is given implicitly by the grammar. 7123 Operator precedence is given implicitly by the grammar.
6379 7124
6380 \commentary{The following non-normative table may be helpful 7125 \commentary{The following non-normative table may be helpful
6381 \newline 7126 \newline
6382 7127
6383 \begin{tabular}{| r | r | r | r |} 7128 \begin{tabular}{| r | r | r | r |}
6384 \hline 7129 \hline
6385 Description & Operator & Associativity & Precedence \\ 7130 Description & Operator & Associativity & Precedence \\
6386 \hline 7131 \hline
6387 Unary postfix & ., e++, e--, e1[e2], e1() , () & None & 15 \\ 7132 Unary postfix & ., e++, e--, e1[e2], e1() , () & None & 15 \\
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
6428 \item The names of compile time constant variables never use lower case letters. If they consist of multiple words, those words are separated by underscores. Ex amples: PI, I\_AM\_A\_CONSTANT. 7173 \item The names of compile time constant variables never use lower case letters. If they consist of multiple words, those words are separated by underscores. Ex amples: PI, I\_AM\_A\_CONSTANT.
6429 \item The names of functions (including getters, setters, methods and local or l ibrary functions) and non-constant variables begin with a lowercase letter. If t he name consists of multiple words, each word (except the first) begins with an uppercase letter. No other uppercase letters are used. Examples: camlCase, dar t4TheWorld 7174 \item The names of functions (including getters, setters, methods and local or l ibrary functions) and non-constant variables begin with a lowercase letter. If t he name consists of multiple words, each word (except the first) begins with an uppercase letter. No other uppercase letters are used. Examples: camlCase, dar t4TheWorld
6430 \item The names of types (including classes and type aliases) begin with an uppe r case letter. If the name consists of multiple words, each word begins with an uppercase letter. No other uppercase letters are used. Examples: CamlCase, D art4TheWorld. 7175 \item The names of types (including classes and type aliases) begin with an uppe r case letter. If the name consists of multiple words, each word begins with an uppercase letter. No other uppercase letters are used. Examples: CamlCase, D art4TheWorld.
6431 \item The names of type variables are short (preferably single letter). Examples : T, S, K, V , E. 7176 \item The names of type variables are short (preferably single letter). Examples : T, S, K, V , E.
6432 \item The names of libraries or library prefixes never use upper case letters. I f they consist of multiple words, those words are separated by underscores. Exam ple: my\_favorite\_library. 7177 \item The names of libraries or library prefixes never use upper case letters. I f they consist of multiple words, those words are separated by underscores. Exam ple: my\_favorite\_library.
6433 \end{itemize} 7178 \end{itemize}
6434 } 7179 }
6435 7180
6436 7181
6437 \end{document} 7182 \end{document}
7183
7184 [Text after \end{document} is ignored, hence we do not need "%"]
7185 ----------------------------------------------------------------------
7186
7187 * On Location Markers
7188
7189 This is a description of location markers, giving some information
7190 about the underlying motivation and rationale, the actual
7191 implementation, and the relevant tool support.
7192
7193 ** What is a Location Marker?
7194
7195 In order to support more fine-grained update propagation from this
7196 language specification to artifacts that depend on it, location
7197 markers have been added. The idea is that each logical unit (section,
7198 subsection, etc) and each paragraph containing normative text should
7199 be addressable using these markers, such that source code (compilers
7200 and other tools, tests, etc.) can contain location markers, and the
7201 corresponding location in the spec may be looked up using standard
7202 document viewer search features.
7203
7204 An SHA1 hash value of the text is associated with each location
7205 marker, such that changes in the text will incur changes in this hash
7206 value. Consequently, source code in tools/tests that depend on
7207 specific parts of the spec may be flagged for revision by checking
7208 whether these hash values have changed: If a given test T depends on
7209 a paragraph with hash value V in the spec, and the search for V fails
7210 in a new version of the spec, then that paragraph has changed and T
7211 should be revisited and possible revised.
7212
7213 As a result, the search for parts of source code and similar artifacts
7214 in likely need of updates because of spec changes can be performed
7215 mechanically, which should help ensure that the conformance of all
7216 artifacts depending on this spec is maintained more easily, and hence
7217 more consistently. Note that it makes no difference whether the need
7218 for an update has arisen in a very recent version of the spec or it
7219 has existed for a long time, because the hash value just remains
7220 different as long as the text is different from what it was when the
7221 location marker was harvested from the spec.
7222
7223 ** LaTeX Commands Supporting Location Markers
7224
7225 Concretely, this is based on the commands \LMHash and \LMLabel.
7226 \LMHash{V} is used to add the text V in the margin, intended to mark
7227 a paragraph of normative text with the SHA1 hash value of the text, V.
7228 \LMLabel{L} has the effect of \label{L}, and moreover it shows the
7229 text sec:L in the margin. In order to indicate a dependency on a
7230 section or subsection an \LMLabel location marker is used, and in
7231 order to indicate a dependency on a specific paragraph, the hash value
7232 of that paragraph is used.
7233
7234 In this file, each normative paragraph has had the command \LMHash{}
7235 added at the beginning, such that each of these paragraphs can be
7236 decorated with their hash value. Similarly, all \section{}s,
7237 \subsection{}s, \subsubsection{}s, and \paragraph{}s have had
7238 their \label commands changed to \LMLabel, such that they are
7239 decorated with logical names.
7240
7241 ** Rationale
7242
7243 The design of location markers was proposed by Erik Ernst and
7244 developed through discussions with several others, in particular Gilad
7245 Bracha and Lars Bak. Some discussions along the way that gave rise to
7246 the given design are outlined below.
7247
7248 The basic idea is that a hash value based on the actual text will
7249 serve well to identify a piece of text, because it will change
7250 whenever the text changes, and it remains the same if the text is
7251 moved to a different location; in other words, it characterizes the
7252 text itself, independently of the rest of the document. Hence:
7253
7254 - references to specific paragraphs in the spec are easy to create:
7255 copy the marker and paste it into the source code (but see below
7256 why this uses an extra indirection as far as possible)
7257
7258 - such references would be robust in the sense that they depend on
7259 the actual text alone, i.e., they would not be invalidated by
7260 updates to section numbers, relocation of the paragraph, or
7261 updates to text in different paragraphs; as Lars mentioned, we
7262 should use a "stripped" version of the text, removing comments,
7263 normalizing white space, etc., which would make the refs even more
7264 robust in case of "inessential" changes
7265
7266 - artifacts depending on a given part of the spec that was
7267 changed could easily be pointed out: After an update to a
7268 part of the spec, that artifact would hold a marker associated
7269 with a hash value which does not any more occur in the spec,
7270 maintainers of the artifact would then receive a notification
7271 ("test1773 depends on a part of the spec that was updated").
7272 Nice tool support would show them the paragraph in the most recent
7273 version of the spec as well as the old version that the artifact
7274 used to depend on, and a comparison of the two would help
7275 clarifying what needs fixing because of this change, if anything.
7276
7277 However, there is a conflict in this scenario: Lars pointed out that
7278 it is very inconvenient to have to create a lot of revision control
7279 commits (e.g., new versions of tests), just because a large number of
7280 artifacts depend on a specific hash value that changed, if that change
7281 has no real impact on each of those artifacts. The obvious solution
7282 to this problem would be to use symbolic names and keep the actual
7283 hash values out of the primary artifacts.
7284
7285 This approach has been used for \section{}s, \subsection{}s, etc., by
7286 using their labels as location markers. For instance, dependency on
7287 \subsubsection{New} would be marked as a dependency on 'sec:new',
7288 which will (most likely) exist with the same label in the spec for a
7289 long time. To detect a need for updates, the hash value associated
7290 with \subsubsection{New} from the date of the latest check of this
7291 kind to the dependent artifact should be compared with the current
7292 hash value for the same \subsubsection{}: The artifact should be
7293 revisited iff those hash values differ. As an easy approximation to
7294 this scheme, the hash values for all location markers would be
7295 computed for each spec update, and the location markers that have new
7296 hash values should cause revisits to all artifacts depending on that
7297 location marker.
7298
7299 The symbolic location markers on larger units like \section{}
7300 etc. enable location marking in a hierarchical fashion: Dependencies
7301 on a \subsubsection{} or on a \section{} can be chosen according to
7302 the actual needs with each dependent artifact. In general, fine
7303 granularity helps avoiding false positives, where an update somewhere
7304 in a large unit will flag too many dependent artifacts for revisits.
7305 In contrast, coarse granularity enables other artifacts to declare the
7306 actual dependencies when small units would be impractical because the
7307 artifact depends on so many of them. But there is a problem at the
7308 bottom of this hierarchy, namely with paragraphs.
7309
7310 It would be very inconvenient to have to invent a logical name for
7311 every paragraph. Similarly, using a simple paragraph numbering would
7312 be unstable (add one new paragraph in the beginning of a section, and
7313 all the rest have new numbers, creating a massive flood of false
7314 update alerts, or, even worse, corrupting the declared dependencies in
7315 artifacts because they point to the wrong paragraphs).
7316
7317 Hence, paragraphs have no other label than their actual hash value.
7318 Artifacts that depend on very specific elements in the spec may
7319 declare so by using an actual hash value for a given paragraph, and in
7320 return they pay in terms of potential updates to the marker when that
7321 paragraph changes, even in cases where the actual change makes no
7322 difference for that particular artifact. This choice of granularity
7323 vs. stability is up to the creator of each artifact.
7324
7325 ** Maintenance of this document
7326
7327 The invariant that each normative paragraph is associated with a line
7328 containing the text \LMHash{} should be maintained. Extra occurrences
7329 of \LMHash{} can be added if needed, e.g., in order to make
7330 individual \item{}s in itemized lists addressable. Each \LM.. command
7331 must occur on a separate line. \LMHash{} must occur immediately
7332 before the associated paragraph, and \LMLabel must occur immediately
7333 after the associated \section{}, \subsection{} etc.
7334
7335 ----------------------------------------------------------------------
OLDNEW
« no previous file with comments | « docs/language/dart.sty ('k') | tests/standalone/io/addlatexhash_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698