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

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

Issue 715653003: orrect cut/paste error that replicated an item in the list of constants and (worse) deleted another. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 1 month 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 | « no previous file | no next file » | 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}
4 \usepackage{dart} 3 \usepackage{dart}
5 \usepackage{bnf} 4 \usepackage{bnf}
6 \usepackage{hyperref} 5 \usepackage{hyperref}
7 \usepackage{lmodern}
8 \newcommand{\code}[1]{{\sf #1}} 6 \newcommand{\code}[1]{{\sf #1}}
9 \title{Dart Programming Language Specification \\ 7 \title{Dart Programming Language Specification \\
10 {\large Version 1.6}} 8 {\large Version 1.6}}
11 %\author{The Dart Team} 9 %\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
17 \begin{document} 10 \begin{document}
18 \maketitle 11 \maketitle
19 \tableofcontents 12 \tableofcontents
20 13
21 14
22 \newpage 15 \newpage
23 16
24 \pagestyle{myheadings} 17 \pagestyle{myheadings}
25 \markright{Dart Programming Language Specification} 18 \markright{Dart Programming Language Specification}
26 19
27 % begin Ecma boilerplate 20 % begin Ecma boilerplate
28 \section{Scope} 21 \section{Scope}
29 \LMLabel{ecmaScope} 22 \label{ecmaScope}
30 23
31 \LMHash{}
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}). 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}).
33 25
34 \section{Conformance} 26 \section{Conformance}
35 \LMLabel{ecmaConformance} 27 \label{ecmaConformance}
36 28
37 \LMHash{}
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. 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.
39 30
40 \LMHash{}
41 A conforming implementation is permitted to provide additional APIs, but not add itional syntax. 31 A conforming implementation is permitted to provide additional APIs, but not add itional syntax.
42 32
43 % A claim of conformance with this Ecma Standard shall specify? 33 % A claim of conformance with this Ecma Standard shall specify?
44 34
45 \section{Normative References} 35 \section{Normative References}
46 \LMLabel{ecmaNormativeReferences} 36 \label{ecmaNormativeReferences}
47 37
48 \LMHash{}
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. 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.
50 39
51 \begin{enumerate} 40 \begin{enumerate}
52 \item 41 \item
53 The Unicode Standard, Version 5.0, as amended by Unicode 5.1.0, or successor. 42 The Unicode Standard, Version 5.0, as amended by Unicode 5.1.0, or successor.
54 \item 43 \item
55 Dart API Reference, https://api.dartlang.org/ 44 Dart API Reference, https://api.dartlang.org/
56 \end{enumerate} 45 \end{enumerate}
57 46
58 47
59 \section{Terms and Definitions} 48 \section{Terms and Definitions}
60 \LMLabel{ecmaTermsAndDefinitions} 49 \label{ecmaTermsAndDefinitions}
61 50
62 \LMHash{}
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'. 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'.
64 % End Ecma Boilerplate 52 % End Ecma Boilerplate
65 53
66 54
67 \section{Notation} 55 \section{Notation}
68 \LMLabel{notation} 56 \label{notation}
69 57
70 \LMHash{}
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: 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:
72 \begin{itemize} 59 \begin{itemize}
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.} 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.}
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. } 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. }
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?} 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?}
76 \end{itemize} 63 \end{itemize}
77 64
78 \LMHash{}
79 Reserved words and built-in identifiers (\ref{identifierReference}) appear in { \bf bold}. 65 Reserved words and built-in identifiers (\ref{identifierReference}) appear in { \bf bold}.
80 66
81 \commentary{ 67 \commentary{
82 Examples would be \SWITCH{} or \CLASS{}. 68 Examples would be \SWITCH{} or \CLASS{}.
83 } 69 }
84 70
85 71
86 \LMHash{}
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. 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.
88 73
89 \commentary{ An example would be:} 74 \commentary{ An example would be:}
90 75
91 \begin{grammar} 76 \begin{grammar}
92 {\sf 77 {\sf
93 {\bf AProduction:}AnAlternative; 78 {\bf AProduction:}AnAlternative;
94 AnotherAlternative; 79 AnotherAlternative;
95 OneThing After Another; 80 OneThing After Another;
96 ZeroOrMoreThings*; 81 ZeroOrMoreThings*;
97 OneOrMoreThings+; 82 OneOrMoreThings+;
98 AnOptionalThing?; 83 AnOptionalThing?;
99 (Some Grouped Things); 84 (Some Grouped Things);
100 \~{}NotAThing; 85 \~{}NotAThing;
101 A\_LEXICAL\_THING 86 A\_LEXICAL\_THING
102 . 87 .
103 } 88 }
104 \end{grammar} 89 \end{grammar}
105 90
106 % need a match anything or a production that does that, so we can correct bugs w rt use 91 % need a match anything or a production that does that, so we can correct bugs w rt use
107 % ~. ~ does not actually parse stuff - it just looks ahead and checks. To get th e effect of 92 % ~. ~ does not actually parse stuff - it just looks ahead and checks. To get th e effect of
108 % parsing anything but X, one needs ~X ANYTHING, not just ~X. There are bugs in the 93 % parsing anything but X, one needs ~X ANYTHING, not just ~X. There are bugs in the
109 % grammar related to this. 94 % grammar related to this.
110 % The alternative is to define ~X as anything but X, or to introduce an anthingB ut(X) 95 % The alternative is to define ~X as anything but X, or to introduce an anthingB ut(X)
111 % combinator, such as !X 96 % combinator, such as !X
112 97
113 \LMHash{}
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. 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.
115 Punctuation tokens appear in quotes. 99 Punctuation tokens appear in quotes.
116 100
117 \LMHash{}
118 Productions are embedded, as much as possible, in the discussion of the construc ts they represent. 101 Productions are embedded, as much as possible, in the discussion of the construc ts they represent.
119 102
120 \LMHash{}
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. 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.
122 104
123 \LMHash{}
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$. 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$.
125 106
126 \LMHash{}
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$). 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$).
128 108
129 \LMHash{}
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: 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:
131 \begin{itemize} 110 \begin{itemize}
132 \item 111 \item
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$. 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$.
134 \end{itemize} 113 \end{itemize}
135 114
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. 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.
137 } 116 }
138 117
139 \LMHash{}
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. 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.
141 119
142 \LMHash{}
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. 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.
144 121
145 \commentary{ 122 \commentary{
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. 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.
147 } 124 }
148 125
149 \section{Overview} 126 \section{Overview}
150 \LMLabel{overview} 127 \label{overview}
151 128
152 \LMHash{}
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. 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.
154 130
155 \LMHash{}
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. 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.
157 132
158 \LMHash{}
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. 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.
160 134
161 \commentary{ 135 \commentary{
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. 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.
163 137
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. 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.
165 } 139 }
166 140
167 \LMHash{}
168 In checked mode, assignments are dynamically checked, and certain violations of the type system raise exceptions at run time. 141 In checked mode, assignments are dynamically checked, and certain violations of the type system raise exceptions at run time.
169 142
170 \commentary{ 143 \commentary{
171 The coexistence between optional typing and reification is based on the followin g: 144 The coexistence between optional typing and reification is based on the followin g:
172 \begin{enumerate} 145 \begin{enumerate}
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. 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.
174 \item Static type annotations determine the types of variables and function decl arations (including methods and constructors). 147 \item Static type annotations determine the types of variables and function decl arations (including methods and constructors).
175 \item Production mode respects optional typing. Static type annotations do not a ffect runtime behavior. 148 \item Production mode respects optional typing. Static type annotations do not a ffect runtime behavior.
176 \item Checked mode utilizes static type annotations and dynamic type information aggressively yet selectively to provide early error detection during developmen t. 149 \item Checked mode utilizes static type annotations and dynamic type information aggressively yet selectively to provide early error detection during developmen t.
177 \end{enumerate} 150 \end{enumerate}
178 } 151 }
179 152
180 \LMHash{}
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. 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.
182 154
183 \commentary{However they are not first class. To get multiple copies of a libra ry running simultaneously, one needs to spawn an isolate. 155 \commentary{However they are not first class. To get multiple copies of a libra ry running simultaneously, one needs to spawn an isolate.
184 } 156 }
185 157
186 \subsection{Scoping} 158 \subsection{Scoping}
187 \LMLabel{scoping} 159 \label{scoping}
188 160
189 \LMHash{}
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$. 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$.
191 162
192 \LMHash{}
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. 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.
194 164
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. 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.
196 } 166 }
197 167
198 \LMHash{}
199 It is a compile-time error if there is more than one entity with the same name d eclared in the same scope. 168 It is a compile-time error if there is more than one entity with the same name d eclared in the same scope.
200 169
201 \commentary{ 170 \commentary{
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-. 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-.
203 } 172 }
204 173
205 \LMHash{}
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. 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.
207 175
208 176
209 \LMHash{}
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$. 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$.
211 178
212 \commentary { 179 \commentary {
213 A consequence of these rules is that it is possible to hide a type with a method or variable. 180 A consequence of these rules is that it is possible to hide a type with a method or variable.
214 Naming conventions usually prevent such abuses. Nevertheless,the following progr am is legal: 181 Naming conventions usually prevent such abuses. Nevertheless,the following progr am is legal:
215 } 182 }
216 183
217 \begin{dartCode} 184 \begin{dartCode}
218 \CLASS{} HighlyStrung \{ 185 \CLASS{} HighlyStrung \{
219 String() $=>$ "?"; 186 String() $=>$ "?";
220 \} 187 \}
221 \end{dartCode} 188 \end{dartCode}
222 189
223 \LMHash{}
224 Names may be introduced into a scope by declarations within the scope or by ot her mechanisms such as imports or inheritance. 190 Names may be introduced into a scope by declarations within the scope or by ot her mechanisms such as imports or inheritance.
225 191
226 \rationale{ 192 \rationale{
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. 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.
228 194
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: 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:
230 } 196 }
231 197
232 \begin{dartCode} 198 \begin{dartCode}
233 \LIBRARY{} L1; 199 \LIBRARY{} L1;
(...skipping 20 matching lines...) Expand all
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. 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.
255 221
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. 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.
257 223
258 } 224 }
259 225
260 226
261 227
262 228
263 \subsection{Privacy} 229 \subsection{Privacy}
264 \LMLabel{privacy} 230 \label{privacy}
265 231
266 \LMHash{}
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 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
268 begins with an underscore (the \_ character) otherwise it is {\em public.} 233 begins with an underscore (the \_ character) otherwise it is {\em public.}
269 234
270 \LMHash{}
271 A declaration $m$ is {\em accessible to library $L$} if $m$ is declared in $L$ or if $m$ is public. 235 A declaration $m$ is {\em accessible to library $L$} if $m$ is declared in $L$ or if $m$ is public.
272 236
273 \commentary{ 237 \commentary{
274 This means private declarations may only be accessed within the library in which they are declared. 238 This means private declarations may only be accessed within the library in which they are declared.
275 } 239 }
276 240
277 \LMHash{}
278 Privacy applies only to declarations within a library, not to library declaratio ns themselves. 241 Privacy applies only to declarations within a library, not to library declaratio ns themselves.
279 242
280 \rationale{Libraries do not reference each other by name and so the idea of a pr ivate library is meaningless. 243 \rationale{Libraries do not reference each other by name and so the idea of a pr ivate library is meaningless.
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. 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.
282 } 245 }
283 246
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. 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.
285 248
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.} 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.}
287 250
288 \subsection{Concurrency} 251 \subsection{Concurrency}
289 252
290 \LMHash{}
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}. 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}.
292 254
293 \LMHash{}
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}). 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}).
295 256
296 257
297 \section{Errors and Warnings} 258 \section{Errors and Warnings}
298 \LMLabel{errorsAndWarnings} 259 \label{errorsAndWarnings}
299 260
300 \LMHash{}
301 This specification distinguishes between several kinds of errors. 261 This specification distinguishes between several kinds of errors.
302 262
303 \LMHash{}
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. 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.
305 264
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. 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.
307 266
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). 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).
309 268
310 In a development environment a compiler should of course report compilation erro rs eagerly so as to best serve the programmer. 269 In a development environment a compiler should of course report compilation erro rs eagerly so as to best serve the programmer.
311 } 270 }
312 271
313 \LMHash{}
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. 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.
315 273
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. 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.
317 A Dart engine runs in the context of an {\em embedder}, 275 A Dart engine runs in the context of an {\em embedder},
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. 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.
319 } 277 }
320 278
321 \LMHash{}
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. 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.
323 280
324 \LMHash{}
325 {\em Dynamic type errors} are type errors reported in checked mode. 281 {\em Dynamic type errors} are type errors reported in checked mode.
326 282
327 \LMHash{}
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. 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.
329 284
330 \LMHash{}
331 If an uncaught exception is thrown by a running isolate $A$, $A$ is immediately suspended. 285 If an uncaught exception is thrown by a running isolate $A$, $A$ is immediately suspended.
332 286
333 287
334 \section{Variables} 288 \section{Variables}
335 \LMLabel{variables} 289 \label{variables}
336 290
337 \LMHash{}
338 Variables are storage locations in memory. 291 Variables are storage locations in memory.
339 292
340 \begin{grammar} 293 \begin{grammar}
341 {\bf variableDeclaration:} 294 {\bf variableDeclaration:}
342 declaredIdentifier (`,' identifier)* 295 declaredIdentifier (`,' identifier)*
343 . 296 .
344 297
345 {\bf declaredIdentifier:} 298 {\bf declaredIdentifier:}
346 metadata finalConstVarOrType identifier 299 metadata finalConstVarOrType identifier
347 . 300 .
(...skipping 17 matching lines...) Expand all
365 318
366 {\bf initializedIdentifierList:} 319 {\bf initializedIdentifierList:}
367 initializedIdentifier (`,' initializedIdentifier)* 320 initializedIdentifier (`,' initializedIdentifier)*
368 . 321 .
369 322
370 323
371 324
372 325
373 \end{grammar} 326 \end{grammar}
374 327
375 \LMHash{}
376 A variable that has not been initialized has the initial value \NULL{} (\ref{nul l}). 328 A variable that has not been initialized has the initial value \NULL{} (\ref{nul l}).
377 329
378 \LMHash{}
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. 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.
380 331
381 \LMHash{}
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{}. 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{}.
383 333
384 \LMHash{}
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}. 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}.
386 335
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. 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.
388 } 337 }
389 338
390 \LMHash{}
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 {}. 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 {}.
392 340
393 \LMHash{}
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. 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.
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. 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.
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. 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.
397 344
398 \commentary{ 345 \commentary{
399 346
400 A library or static variable is guaranteed to have an initializer at its declara tion by the grammar. 347 A library or static variable is guaranteed to have an initializer at its declara tion by the grammar.
401 348
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. 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.
403 350
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. 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.
405 } 352 }
406 353
407 \LMHash{}
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. 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.
409 355
410 \LMHash{}
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$. 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$.
412 357
413 \LMHash{}
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}). 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}).
415 359
416 \LMHash{}
417 A variable is {\em mutable} if it is not final. 360 A variable is {\em mutable} if it is not final.
418 Static and instance variable declarations always induce implicit getters. If the variable is mutable it also introduces an implicit setter. 361 Static and instance variable declarations always induce implicit getters. If the variable is mutable it also introduces an implicit setter.
419 The scope into which the implicit getters and setters are introduced depends on the kind of variable declaration involved. 362 The scope into which the implicit getters and setters are introduced depends on the kind of variable declaration involved.
420 363
421 \LMHash{}
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. 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.
423 365
424 \LMHash{}
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. 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.
426 367
427 \LMHash{}
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. 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.
429 369
430 \rationale { 370 \rationale {
431 We allow the error to be reported at the declaration to allow implementations to avoid an extra processing phase. 371 We allow the error to be reported at the declaration to allow implementations to avoid an extra processing phase.
432 } 372 }
433 373
434 \commentary{ 374 \commentary{
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$. 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$.
436 } 376 }
437 377
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 415
476 \rationale{ 416 \rationale{
477 As a rule, type annotations are ignored in production mode. However, we do 417 As a rule, type annotations are ignored in production mode. However, we do
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. 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.
479 } 419 }
480 420
481 \end{dartCode} 421 \end{dartCode}
482 422
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. 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.
484 424
485 \LMHash{}
486 The following rules apply to all static and instance variables. 425 The following rules apply to all static and instance variables.
487 426
488 \LMHash{}
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 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
490 428
491 $T$ \GET{} $v$ 429 $T$ \GET{} $v$
492 430
493 whose invocation evaluates as described below (\ref{evaluationOfImplicitVariable Getters}). 431 whose invocation evaluates as described below (\ref{evaluationOfImplicitVariable Getters}).
494 432
495 433
496 \LMHash{}
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 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
498 435
499 \GET{} $v$ 436 \GET{} $v$
500 437
501 whose invocation evaluates as described below (\ref{evaluationOfImplicitVariabl eGetters}). 438 whose invocation evaluates as described below (\ref{evaluationOfImplicitVariabl eGetters}).
502 439
503 \LMHash{}
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 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
505 441
506 \VOID{} \SET{} $v=(T$ $x)$ 442 \VOID{} \SET{} $v=(T$ $x)$
507 443
508 whose execution sets the value of $v$ to the incoming argument $x$. 444 whose execution sets the value of $v$ to the incoming argument $x$.
509 445
510 \LMHash{}
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 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
512 447
513 \SET{} $v=(x)$ 448 \SET{} $v=(x)$
514 449
515 whose execution sets the value of $v$ to the incoming argument $x$. 450 whose execution sets the value of $v$ to the incoming argument $x$.
516 451
517 452
518 \subsection{Evaluation of Implicit Variable Getters} 453 \subsection{Evaluation of Implicit Variable Getters}
519 \LMLabel{evaluationOfImplicitVariableGetters} 454 \label{evaluationOfImplicitVariableGetters}
520 455
521 \LMHash{}
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$. 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$.
523 If $d$ is a static or library variable then the implicit getter method of $v$ ex ecutes as follows: 457 If $d$ is a static or library variable then the implicit getter method of $v$ ex ecutes as follows:
524 \begin{itemize} 458 \begin{itemize}
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$. 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$.
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. } 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. }
527 Otherwise 461 Otherwise
528 \item {\bf Variable declaration without initializer}. The result of executing th e getter method is the value stored in $v$. 462 \item {\bf Variable declaration without initializer}. The result of executing th e getter method is the value stored in $v$.
529 \end{itemize} 463 \end{itemize}
530 464
531 465
532 466
533 467
534 468
535 \section{Functions} 469 \section{Functions}
536 \LMLabel{functions} 470 \label{functions}
537 471
538 \LMHash{}
539 Functions abstract over executable actions. 472 Functions abstract over executable actions.
540 473
541 \begin{grammar} 474 \begin{grammar}
542 {\bf functionSignature:} 475 {\bf functionSignature:}
543 metadata returnType? identifier formalParameterList 476 metadata returnType? identifier formalParameterList
544 . 477 .
545 478
546 {\bf returnType:} 479 {\bf returnType:}
547 \VOID{}; 480 \VOID{};
548 type 481 type
549 . 482 .
550 483
551 {\bf functionBody:} \ASYNC{}? `={\escapegrammar \gt}' expression `{\escapegramm ar ;}'; 484 {\bf functionBody:} \ASYNC{}? `={\escapegrammar \gt}' expression `{\escapegramm ar ;}';
552 (\ASYNC{} $|$ \ASYNC* $|$ \SYNC*)? block 485 (\ASYNC{} $|$ \ASYNC* $|$ \SYNC*)? block
553 . 486 .
554 487
555 {\bf block:} 488 {\bf block:}
556 `\{' statements `\}' 489 `\{' statements `\}'
557 . 490 .
558 491
559 \end{grammar} 492 \end{grammar}
560 493
561 \LMHash{}
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}). 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}).
563 495
564 \LMHash{}
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: 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:
566 \begin{itemize} 497 \begin{itemize}
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. 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.
568 499
569 \rationale{ 500 \rationale{
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}. 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}.
571 } 502 }
572 503
573 OR 504 OR
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.} 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.}
575 506
576 \end{itemize} 507 \end{itemize}
577 508
578 \LMHash{}
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. 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.
580 510
581 \commentary{ 511 \commentary{
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. 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.
583 } 513 }
584 514
585 \LMHash{}
586 It is a compile-time error if an \ASYNC, \ASYNC* or \SYNC* modifier is attached to the body of a setter or constructor. 515 It is a compile-time error if an \ASYNC, \ASYNC* or \SYNC* modifier is attached to the body of a setter or constructor.
587 516
588 \rationale{ 517 \rationale{
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. 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.
590 519
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. 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.
592 521
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. 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.
594 } 523 }
595 524
596 525
597 \subsection{Function Declarations} 526 \subsection{Function Declarations}
598 \LMLabel{functionDeclarations} 527 \label{functionDeclarations}
599 528
600 \LMHash{}
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 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
602 %(including getters and setters) 530 %(including getters and setters)
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. 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.
604 532
605 \LMHash{}
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. 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.
607 534
608 \LMHash{}
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}). 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}).
610 536
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}])$}. 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}])$}.
612 538
613 %\Q{We need to cover library getters as well.} 539 %\Q{We need to cover library getters as well.}
614 540
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 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
616 %requirement in the case of closures. See bug 315. 542 %requirement in the case of closures. See bug 315.
617 %} 543 %}
618 544
619 %\commentary{ 545 %\commentary{
620 %Some obvious conclusions: 546 %Some obvious conclusions:
621 547
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$}. 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$}.
623 549
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$;\}}. 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$;\}}.
625 %} 551 %}
626 552
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}\})$}. 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}\})$}.
628 554
629 \LMHash{}
630 It is a compile-time error to preface a function declaration with the built-in i dentifier \STATIC{}. 555 It is a compile-time error to preface a function declaration with the built-in i dentifier \STATIC{}.
631 556
632 \LMHash{}
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. 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.
634 558
635 559
636 \subsection{Formal Parameters} 560 \subsection{Formal Parameters}
637 \LMLabel{formalParameters} 561 \label{formalParameters}
638 562
639 \LMHash{}
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. 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.
641 564
642 \LMHash{}
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. 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.
644 566
645 \LMHash{}
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$. 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$.
647 568
648 569
649 %The formal parameter scope of a function maps the name of each formal parameter $p$ to the value $p$ is bound to. 570 %The formal parameter scope of a function maps the name of each formal parameter $p$ to the value $p$ is bound to.
650 571
651 % The formal parameters of a function are processed in the enclosing scope of th e function. 572 % The formal parameters of a function are processed in the enclosing scope of th e function.
652 % \commentary{this means that the parameters themselves may not be referenced wi thin the formal parameter list.} 573 % \commentary{this means that the parameters themselves may not be referenced wi thin the formal parameter list.}
653 574
654 \LMHash{}
655 It is a compile-time error if a formal parameter is declared as a constant varia ble (\ref{variables}). 575 It is a compile-time error if a formal parameter is declared as a constant varia ble (\ref{variables}).
656 576
657 \begin{grammar} 577 \begin{grammar}
658 {\bf formalParameterList:}`(' `)'; 578 {\bf formalParameterList:}`(' `)';
659 `(' normalFormalParameters ( `,' optionalFormalParameters)? `)'; 579 `(' normalFormalParameters ( `,' optionalFormalParameters)? `)';
660 `(' optionalFormalParameters `)' 580 `(' optionalFormalParameters `)'
661 . 581 .
662 %\end{grammar} 582 %\end{grammar}
663 %} 583 %}
664 584
(...skipping 19 matching lines...) Expand all
684 `\{' defaultNamedParameter (`,' defaultNamedParameter)* `\}' 604 `\{' defaultNamedParameter (`,' defaultNamedParameter)* `\}'
685 . 605 .
686 \end{grammar} 606 \end{grammar}
687 607
688 %Formal parameters are always \FINAL{}. 608 %Formal parameters are always \FINAL{}.
689 %\Q{We're awaiting some data on whether enforcing this would cause widespread pa in.} 609 %\Q{We're awaiting some data on whether enforcing this would cause widespread pa in.}
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.} 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.}
691 611
692 612
693 \subsubsection{Required Formals} 613 \subsubsection{Required Formals}
694 \LMLabel{requiredFormals} 614 \label{requiredFormals}
695 615
696 \LMHash{}
697 A {\em required formal parameter} may be specified in one of three ways: 616 A {\em required formal parameter} may be specified in one of three ways:
698 \begin{itemize} 617 \begin{itemize}
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? 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?
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? 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?
701 \item Via an ordinary variable declaration (\ref{variables}). 620 \item Via an ordinary variable declaration (\ref{variables}).
702 \end{itemize} 621 \end{itemize}
703 622
704 \begin{grammar} 623 \begin{grammar}
705 {\bf normalFormalParameter:}functionSignature; 624 {\bf normalFormalParameter:}functionSignature;
706 fieldFormalParameter; 625 fieldFormalParameter;
(...skipping 12 matching lines...) Expand all
719 %\subsubsection{Rest Formals} 638 %\subsubsection{Rest Formals}
720 639
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[]$. 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[]$.
722 641
723 %\begin{grammar} 642 %\begin{grammar}
724 %restFormalParameter: 643 %restFormalParameter:
725 % finalConstVarOrType? '{\escapegrammar ...}' identifier 644 % finalConstVarOrType? '{\escapegrammar ...}' identifier
726 %\end{grammar} 645 %\end{grammar}
727 646
728 \subsubsection{Optional Formals} 647 \subsubsection{Optional Formals}
729 \LMLabel{optionalFormals} 648 \label{optionalFormals}
730 649
731 \LMHash{}
732 Optional parameters may be specified and provided with default values. 650 Optional parameters may be specified and provided with default values.
733 651
734 \begin{grammar} 652 \begin{grammar}
735 {\bf defaultFormalParameter:} 653 {\bf defaultFormalParameter:}
736 normalFormalParameter ('=' expression)? 654 normalFormalParameter ('=' expression)?
737 . 655 .
738 656
739 {\bf defaultNamedParameter:} 657 {\bf defaultNamedParameter:}
740 normalFormalParameter ( `{\escapegrammar :}' expression)? 658 normalFormalParameter ( `{\escapegrammar :}' expression)?
741 . 659 .
742 \end{grammar} 660 \end{grammar}
743 661
744 \LMHash{}
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. 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.
746 663
747 \LMHash{}
748 It is a compile-time error if the name of a named optional parameter begins with an `\_' character. 664 It is a compile-time error if the name of a named optional parameter begins with an `\_' character.
749 665
750 \rationale{ 666 \rationale{
751 The need for this restriction is a direct consequence of the fact that naming a nd privacy are not orthogonal. 667 The need for this restriction is a direct consequence of the fact that naming a nd privacy are not orthogonal.
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. 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.
753 } 669 }
754 670
755 \subsection{Type of a Function} 671 \subsection{Type of a Function}
756 \LMLabel{typeOfAFunction} 672 \label{typeOfAFunction}
757 673
758 \LMHash{}
759 If a function does not declare a return type explicitly, its return type is \DYN AMIC{} (\ref{typeDynamic}). 674 If a function does not declare a return type explicitly, its return type is \DYN AMIC{} (\ref{typeDynamic}).
760 675
761 \LMHash{}
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$. 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$.
763 677
764 \LMHash{}
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$. 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$.
766 679
767 \LMHash{}
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$. 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$.
769 681
770 \LMHash{}
771 The run time type of a function object always implements the class \cd{Function} . 682 The run time type of a function object always implements the class \cd{Function} .
772 683
773 \commentary{ 684 \commentary{
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. 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.
775 } 686 }
776 687
777 \rationale{ 688 \rationale{
778 It is up to the implementation to choose an appropriate representation for funct ions. 689 It is up to the implementation to choose an appropriate representation for funct ions.
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}. 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}.
780 691
781 } 692 }
782 693
783 \subsection{External Functions} 694 \subsection{External Functions}
784 \LMLabel{externalFunctions} 695 \label{externalFunctions}
785 696
786 \LMHash{}
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. 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.
788 698
789 \rationale{ 699 \rationale{
790 External functions allow us to introduce type information for code that is not statically known to the Dart compiler. 700 External functions allow us to introduce type information for code that is not statically known to the Dart compiler.
791 } 701 }
792 702
793 \commentary{ 703 \commentary{
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. 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.
795 } 705 }
796 706
797 \LMHash{}
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. 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.
799 708
800 \LMHash{}
801 The actual syntax is given in sections \ref{classes} and \ref{librariesAndScript s} below. 709 The actual syntax is given in sections \ref{classes} and \ref{librariesAndScript s} below.
802 710
803 \section{Classes} 711 \section{Classes}
804 \LMLabel{classes} 712 \label{classes}
805 713
806 \LMHash{}
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}). 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}).
808 715
809 \begin{grammar} 716 \begin{grammar}
810 {\bf classDefinition:} 717 {\bf classDefinition:}
811 metadata \ABSTRACT{}? \CLASS{} identifier typeParameters? (superclass mixins?)? interfaces? \\ 718 metadata \ABSTRACT{}? \CLASS{} identifier typeParameters? (superclass mixins?)? interfaces? \\
812 `\{' (metadata classMemberDefinition)* `\}'; 719 `\{' (metadata classMemberDefinition)* `\}';
813 720
814 metadata \ABSTRACT{}? \CLASS{} mixinApplicationClass 721 metadata \ABSTRACT{}? \CLASS{} mixinApplicationClass
815 . 722 .
816 723
(...skipping 30 matching lines...) Expand all
847 {\bf staticFinalDeclarationList:} 754 {\bf staticFinalDeclarationList:}
848 staticFinalDeclaration (`,' staticFinalDeclaration)* 755 staticFinalDeclaration (`,' staticFinalDeclaration)*
849 . 756 .
850 757
851 {\bf staticFinalDeclaration:} 758 {\bf staticFinalDeclaration:}
852 identifier `=' expression 759 identifier `=' expression
853 . 760 .
854 761
855 \end{grammar} 762 \end{grammar}
856 763
857 \LMHash{}
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. 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.
859 765
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. 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.
861 %The enclosing scope of a class' instance scope is the class' static scope. 767 %The enclosing scope of a class' instance scope is the class' static scope.
862 768
863 %The enclosing scope of an instance member declaration is the instance scope of the class in which it is declared. 769 %The enclosing scope of an instance member declaration is the instance scope of the class in which it is declared.
864 770
865 %The enclosing scope of a static member declaration is the static scope of the c lass in which it is declared. 771 %The enclosing scope of a static member declaration is the static scope of the c lass in which it is declared.
866 772
867 773
868 \LMHash{}
869 Every class has a single superclass except class \code{Object} which has no sup erclass. A class may implement a number of interfaces 774 Every class has a single superclass except class \code{Object} which has no sup erclass. A class may implement a number of interfaces
870 %, either 775 %, either
871 by declaring them in its implements clause (\ref{superinterfaces}). 776 by declaring them in its implements clause (\ref{superinterfaces}).
872 % or via interface injection declarations (\ref{interfaceInjection}) outside the class declaration 777 % or via interface injection declarations (\ref{interfaceInjection}) outside the class declaration
873 778
874 779
875 \LMHash{}
876 An {\em abstract class} is 780 An {\em abstract class} is
877 %either 781 %either
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. 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.
879 %, or a class that declares at least one abstract method (\ref{abstractInstance Members}). 783 %, or a class that declares at least one abstract method (\ref{abstractInstance Members}).
880 784
881 \rationale{ 785 \rationale{
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 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
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. 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.
884 } 788 }
885 789
886 \LMHash{}
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. 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.
888 791
889 % making an exception for the setters generated for final fields is tempting but problematic. 792 % making an exception for the setters generated for final fields is tempting but problematic.
890 % If a super type defines a setter, it will be overridden yet have no impact on the interface. 793 % If a super type defines a setter, it will be overridden yet have no impact on the interface.
891 % Maybe the final field hides the setter in scope? 794 % Maybe the final field hides the setter in scope?
892 % I think the original rules were best. 795 % I think the original rules were best.
893 796
894 \LMHash{}
895 It is a compile-time error if a class declares two members of the same name. 797 It is a compile-time error if a class declares two members of the same name.
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. 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.
897 It is a compile-time error if a class has an instance member and a static member with the same name. 799 It is a compile-time error if a class has an instance member and a static member with the same name.
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. 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.
899 801
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. 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.
901 } 803 }
902 804
903 \begin{dartCode} 805 \begin{dartCode}
904 \CLASS{} A \{ 806 \CLASS{} A \{
905 \VAR{} i = 0; 807 \VAR{} i = 0;
906 \VAR{} j; 808 \VAR{} j;
907 f(x) =$>$ 3; 809 f(x) =$>$ 3;
908 \} 810 \}
909 811
910 \CLASS{} B \EXTENDS{} A \{ 812 \CLASS{} B \EXTENDS{} A \{
911 int i = 1; // getter i and setter i= override versions from A 813 int i = 1; // getter i and setter i= override versions from A
912 \STATIC{} j; // compile-time error: static getter \& setter conflict with 814 \STATIC{} j; // compile-time error: static getter \& setter conflict with
913 //instance getter \& setter 815 //instance getter \& setter
914 816
915 /* compile-time error: static method conflicts with instance method */ 817 /* compile-time error: static method conflicts with instance method */
916 \STATIC{} f(x) =$>$ 3; 818 \STATIC{} f(x) =$>$ 3;
917 \} 819 \}
918 \end{dartCode} 820 \end{dartCode}
919 821
920 \LMHash{}
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. 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.
922 823
923 \subsection{Instance Methods} 824 \subsection{Instance Methods}
924 \LMLabel{instanceMethods} 825 \label{instanceMethods}
925 826
926 \LMHash{}
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. 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.
928 828
929 %make these warnings if possible 829 %make these warnings if possible
930 830
931 \LMHash{}
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$. 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$.
933 832
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. 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.
935 834
936 \LMHash{}
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$. 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$.
938 836
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. 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.
940 838
941 839
942 \subsubsection{Operators} 840 \subsubsection{Operators}
943 \LMLabel{operators} 841 \label{operators}
944 842
945 \LMHash{}
946 {\em Operators} are instance methods with special names. 843 {\em Operators} are instance methods with special names.
947 844
948 \begin{grammar} 845 \begin{grammar}
949 {\bf operatorSignature:} 846 {\bf operatorSignature:}
950 returnType? \OPERATOR{} operator formalParameterList 847 returnType? \OPERATOR{} operator formalParameterList
951 . 848 .
952 849
953 {\bf operator:}`\~{}'; 850 {\bf operator:}`\~{}';
954 binaryOperator; 851 binaryOperator;
955 `[' `]' ; 852 `[' `]' ;
956 `[' `]' `=' 853 `[' `]' `='
957 . 854 .
958 855
959 {\bf binaryOperator:}multiplicativeOperator; 856 {\bf binaryOperator:}multiplicativeOperator;
960 additiveOperator; 857 additiveOperator;
961 shiftOperator; 858 shiftOperator;
962 relationalOperator; 859 relationalOperator;
963 `=='; 860 `==';
964 bitwiseOperator 861 bitwiseOperator
965 . 862 .
966 \end{grammar} 863 \end{grammar}
967 864
968 \LMHash{}
969 An operator declaration is identified using the built-in identifier (\ref{identi fierReference}) \OPERATOR{}. 865 An operator declaration is identified using the built-in identifier (\ref{identi fierReference}) \OPERATOR{}.
970 866
971 \LMHash{}
972 The following names are allowed for user-defined operators: \code{$<$, $>$, $<$= , $>$=, ==, -, +, /, \~{}/, *, \%, $|$, \^{}, \&, $<<$, $>>$, []=, [], \~{}.} 867 The following names are allowed for user-defined operators: \code{$<$, $>$, $<$= , $>$=, ==, -, +, /, \~{}/, *, \%, $|$, \^{}, \&, $<<$, $>>$, []=, [], \~{}.}
973 868
974 869
975 \LMHash{}
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. 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.
977 871
978 \commentary{ 872 \commentary{
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. 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.
980 } 874 }
981 875
982 \LMHash{}
983 The name of the unary operator \code{-} is \code{unary-}. 876 The name of the unary operator \code{-} is \code{unary-}.
984 877
985 \rationale{ 878 \rationale{
986 This device allows the two methods to be distinguished for purposes of method lo okup, override and reflection. 879 This device allows the two methods to be distinguished for purposes of method lo okup, override and reflection.
987 } 880 }
988 881
989 \LMHash{}
990 It is a compile-time error if the arity of the user-declared operator \code{ \~ {}} is not 0. 882 It is a compile-time error if the arity of the user-declared operator \code{ \~ {}} is not 0.
991 883
992 \LMHash{}
993 It is a compile-time error to declare an optional parameter in an operator. 884 It is a compile-time error to declare an optional parameter in an operator.
994 885
995 \LMHash{}
996 It is a static warning if the return type of the user-declared operator \code{[] =} is explicitly declared and not \VOID{}. 886 It is a static warning if the return type of the user-declared operator \code{[] =} is explicitly declared and not \VOID{}.
997 887
998 888
999 \subsection{Getters} 889 \subsection{Getters}
1000 \LMLabel{getters} 890 \label{getters}
1001 891
1002 \LMHash{}
1003 Getters are functions (\ref{functions}) that are used to retrieve the values of object properties. 892 Getters are functions (\ref{functions}) that are used to retrieve the values of object properties.
1004 893
1005 \begin{grammar} 894 \begin{grammar}
1006 {\bf getterSignature:} 895 {\bf getterSignature:}
1007 returnType? \GET{} identifier 896 returnType? \GET{} identifier
1008 . 897 .
1009 \end{grammar} 898 \end{grammar}
1010 899
1011 %\Q{Why does a getter have a formal parameter list at all?} 900 %\Q{Why does a getter have a formal parameter list at all?}
1012 901
1013 \LMHash{}
1014 If no return type is specified, the return type of the getter is \DYNAMIC{}. 902 If no return type is specified, the return type of the getter is \DYNAMIC{}.
1015 903
1016 \LMHash{}
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. 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.
1018 905
1019 %It is a compile-time error if a getter`s formal parameter list is not empty. 906 %It is a compile-time error if a getter`s formal parameter list is not empty.
1020 907
1021 \LMHash{}
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$. 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$.
1023 909
1024 \LMHash{}
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. 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.
1026 911
1027 \commentary{ 912 \commentary{
1028 This implies that a getter can never override a method, and a method can never o verride a getter or field. 913 This implies that a getter can never override a method, and a method can never o verride a getter or field.
1029 } 914 }
1030 915
1031 \LMHash{}
1032 It is a static warning if the return type of a getter is \VOID. 916 It is a static warning if the return type of a getter is \VOID.
1033 It is a static warning if a getter $m_1$ overrides (\ref{inheritanceAndOverridi ng}) a getter 917 It is a static warning if a getter $m_1$ overrides (\ref{inheritanceAndOverridi ng}) a getter
1034 $m_2$ and the type of $m_1$ is not a subtype of the type of $m_2$. 918 $m_2$ and the type of $m_1$ is not a subtype of the type of $m_2$.
1035 919
1036 \LMHash{}
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. 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.
1038 921
1039 \subsection{Setters} 922 \subsection{Setters}
1040 \LMLabel{setters} 923 \label{setters}
1041 924
1042 \LMHash{}
1043 Setters are functions (\ref{functions}) that are used to set the values of objec t properties. 925 Setters are functions (\ref{functions}) that are used to set the values of objec t properties.
1044 926
1045 % what about top level ones? Same for getters 927 % what about top level ones? Same for getters
1046 928
1047 \begin{grammar} 929 \begin{grammar}
1048 {\bf setterSignature:} 930 {\bf setterSignature:}
1049 returnType? \SET{} identifier formalParameterList 931 returnType? \SET{} identifier formalParameterList
1050 . 932 .
1051 \end{grammar} 933 \end{grammar}
1052 934
1053 \LMHash{}
1054 If no return type is specified, the return type of the setter is \DYNAMIC{}. 935 If no return type is specified, the return type of the setter is \DYNAMIC{}.
1055 936
1056 \LMHash{}
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. 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.
1058 938
1059 \commentary{Hence, a setter name can never conflict with, override or be overrid den by a getter or method.} 939 \commentary{Hence, a setter name can never conflict with, override or be overrid den by a getter or method.}
1060 940
1061 \LMHash{}
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$. 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$.
1063 942
1064 \LMHash{}
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.} 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.}
1066 944
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. 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.
1068 946
1069 \LMHash{}
1070 It is a static warning if a setter declares a return type other than \VOID{}. 947 It is a static warning if a setter declares a return type other than \VOID{}.
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 $. 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 $.
1072 949
1073 \LMHash{}
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$. 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$.
1075 951
1076 \LMHash{}
1077 These warnings must be issued regardless of whether the getters or setters are d eclared explicitly or implicitly. 952 These warnings must be issued regardless of whether the getters or setters are d eclared explicitly or implicitly.
1078 953
1079 \subsection{Abstract Instance Members} 954 \subsection{Abstract Instance Members}
1080 \LMLabel{abstractInstanceMembers} 955 \label{abstractInstanceMembers}
1081 956
1082 \LMHash{}
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. 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.
1084 %The declaration of an abstract method is prefixed by the built-in identifier (\ ref{identifierReference}) \ABSTRACT{}. 958 %The declaration of an abstract method is prefixed by the built-in identifier (\ ref{identifierReference}) \ABSTRACT{}.
1085 959
1086 \rationale{ 960 \rationale{
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. 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.
1088 962
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. 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.
1090 964
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. 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.
1092 } 966 }
1093 967
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. 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.
1095 } 969 }
1096 970
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. 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.
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. 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.
1099 % But if we do override, method lookup rules break down. So several things need revisiting. 973 % But if we do override, method lookup rules break down. So several things need revisiting.
1100 974
1101 \rationale{ 975 \rationale{
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. 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.
1103 } 977 }
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}. 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}.
1105 979
1106 \LMHash{}
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. 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.
1108 981
1109 \rationale { 982 \rationale {
1110 We wish to warn if one declares a concrete class with abstract members. However, code like the following should work without warnings: 983 We wish to warn if one declares a concrete class with abstract members. However, code like the following should work without warnings:
1111 } 984 }
1112 985
1113 \begin{dartCode} 986 \begin{dartCode}
1114 class Base \{ 987 class Base \{
1115 int get one =$>$ 1; 988 int get one =$>$ 1;
1116 \} 989 \}
1117 990
1118 abstract class Mix \{ 991 abstract class Mix \{
1119 int get one; 992 int get one;
1120 int get two =$>$ one + one; 993 int get two =$>$ one + one;
1121 \} 994 \}
1122 995
1123 class C extends Base with Mix \{ 996 class C extends Base with Mix \{
1124 \} 997 \}
1125 \} 998 \}
1126 \end{dartCode} 999 \end{dartCode}
1127 1000
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. } 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. }
1129 1002
1130 \subsection{Instance Variables} 1003 \subsection{Instance Variables}
1131 \LMLabel{instanceVariables} 1004 \label{instanceVariables}
1132 1005
1133 \LMHash{}
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. 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.
1135 1007
1136 \LMHash{}
1137 It is a compile-time error if an instance variable is declared to be constant. 1008 It is a compile-time error if an instance variable is declared to be constant.
1138 1009
1139 \rationale{ 1010 \rationale{
1140 The notion of a constant instance variable is subtle and confusing to programmer s. 1011 The notion of a constant instance variable is subtle and confusing to programmer s.
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. 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.
1142 1013
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. 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.
1144 1015
1145 Given that the value does not depend on the instance, it is better to use a sta tic class variable. 1016 Given that the value does not depend on the instance, it is better to use a sta tic class variable.
1146 An instance getter for it can always be defined manually if desired. 1017 An instance getter for it can always be defined manually if desired.
(...skipping 23 matching lines...) Expand all
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 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
1171 1042
1172 %\SET{} $v=(x)$ 1043 %\SET{} $v=(x)$
1173 1044
1174 %whose execution sets the value of $v$ to the incoming argument $x$. 1045 %whose execution sets the value of $v$ to the incoming argument $x$.
1175 1046
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=$. 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=$.
1177 1048
1178 1049
1179 \subsection{Constructors} 1050 \subsection{Constructors}
1180 \LMLabel{constructors} 1051 \label{constructors}
1181 1052
1182 \LMHash{}
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}). 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}).
1184 1054
1185 \LMHash{}
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. 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.
1187 1056
1188 1057
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. 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.
1190 1059
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?) 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?)
1192 1061
1193 \LMHash{}
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}. 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}.
1195 1063
1196 \subsubsection{Generative Constructors} 1064 \subsubsection{Generative Constructors}
1197 \LMLabel{generativeConstructors} 1065 \label{generativeConstructors}
1198 1066
1199 \LMHash{}
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. 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.
1201 1068
1202 \begin{grammar} 1069 \begin{grammar}
1203 {\bf constructorSignature:} 1070 {\bf constructorSignature:}
1204 identifier (`{\escapegrammar .}' identifier)? formalParameterList 1071 identifier (`{\escapegrammar .}' identifier)? formalParameterList
1205 . 1072 .
1206 \end{grammar} 1073 \end{grammar}
1207 1074
1208 \LMHash{}
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. 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.
1210 1076
1211 \LMHash{}
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}$. 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}$.
1213 1078
1214 \LMHash{}
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. 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.
1216 1080
1217 \LMHash{}
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. 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.
1219 1082
1220 1083
1221 \commentary{ 1084 \commentary{
1222 The above rule allows initializing formals to be used as optional parameters: 1085 The above rule allows initializing formals to be used as optional parameters:
1223 } 1086 }
1224 1087
1225 \begin{dartCode} 1088 \begin{dartCode}
1226 class A \{ 1089 class A \{
1227 int x; 1090 int x;
1228 A([this.x]); 1091 A([this.x]);
1229 \} 1092 \}
1230 \end{dartCode} 1093 \end{dartCode}
1231 1094
1232 \commentary{is legal, and has the same effect as} 1095 \commentary{is legal, and has the same effect as}
1233 1096
1234 \begin{dartCode} 1097 \begin{dartCode}
1235 class A \{ 1098 class A \{
1236 int x; 1099 int x;
1237 A([int x]): this.x = x; 1100 A([int x]): this.x = x;
1238 \} 1101 \}
1239 \end{dartCode} 1102 \end{dartCode}
1240 1103
1241 \LMHash{}
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. 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.
1243 1105
1244 \commentary{ 1106 \commentary{
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}). 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}).
1246 } 1108 }
1247 1109
1248 \LMHash{}
1249 If a generative constructor $c$ is not a redirecting constructor and no body is provided, then $c$ implicitly has an empty body \code{\{\}}. 1110 If a generative constructor $c$ is not a redirecting constructor and no body is provided, then $c$ implicitly has an empty body \code{\{\}}.
1250 1111
1251 1112
1252 \paragraph{Redirecting Constructors} 1113 \paragraph{Redirecting Constructors}
1253 \LMLabel{redirectingConstructors} 1114 \label{redirectingConstructors}
1254 1115
1255 \LMHash{}
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. 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.
1257 1117
1258 \begin{grammar} 1118 \begin{grammar}
1259 {\bf redirection:} 1119 {\bf redirection:}
1260 `{\escapegrammar :}' \THIS{} (`{\escapegrammar .}' identifier)? arguments 1120 `{\escapegrammar :}' \THIS{} (`{\escapegrammar .}' identifier)? arguments
1261 . 1121 .
1262 \end{grammar} 1122 \end{grammar}
1263 1123
1264 % Need to specify exactly how executing a redirecting constructor works 1124 % Need to specify exactly how executing a redirecting constructor works
1265 1125
1266 1126
1267 %\Q{We now have generative constructors with no bodies as well.} 1127 %\Q{We now have generative constructors with no bodies as well.}
1268 1128
1269 \paragraph{Initializer Lists} 1129 \paragraph{Initializer Lists}
1270 1130
1271 \LMHash{}
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. 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.
1273 \begin{itemize} 1132 \begin{itemize}
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. 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.
1275 1134
1276 \item An {\em instance variable initializer} assigns a value to an individual in stance variable. 1135 \item An {\em instance variable initializer} assigns a value to an individual in stance variable.
1277 \end{itemize} 1136 \end{itemize}
1278 1137
1279 \begin{grammar} 1138 \begin{grammar}
1280 {\bf initializers:} 1139 {\bf initializers:}
1281 `{\escapegrammar :}' superCallOrFieldInitializer (`,' superCallOrFieldInit ializer)* 1140 `{\escapegrammar :}' superCallOrFieldInitializer (`,' superCallOrFieldInit ializer)*
1282 . 1141 .
1283 1142
1284 1143
1285 {\bf superCallOrFieldInitializer:}\SUPER{} arguments; 1144 {\bf superCallOrFieldInitializer:}\SUPER{} arguments;
1286 \SUPER{} `{\escapegrammar .}' identifier arguments; 1145 \SUPER{} `{\escapegrammar .}' identifier arguments;
1287 fieldInitializer 1146 fieldInitializer
1288 . 1147 .
1289 1148
1290 {\bf fieldInitializer:} 1149 {\bf fieldInitializer:}
1291 (\THIS{} `{\escapegrammar .}')? identifier `=' conditionalExpression casca deSection* 1150 (\THIS{} `{\escapegrammar .}')? identifier `=' conditionalExpression casca deSection*
1292 . 1151 .
1293 1152
1294 \end{grammar} 1153 \end{grammar}
1295 1154
1296 \LMHash{}
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. 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.
1298 1156
1299 \LMHash{}
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: 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:
1301 \begin{itemize} 1158 \begin{itemize}
1302 \item Initialization at the declaration of $f$. 1159 \item Initialization at the declaration of $f$.
1303 \item Initialization by means of an initializing formal of $k$. 1160 \item Initialization by means of an initializing formal of $k$.
1304 \end{itemize} 1161 \end{itemize}
1305 1162
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. 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.
1307 1164
1308 1165
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. 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.
1310 } 1167 }
1311 1168
1312 \LMHash{}
1313 It is a compile-time error if a generative constructor of class \code{Object} includes a superinitializer. 1169 It is a compile-time error if a generative constructor of class \code{Object} includes a superinitializer.
1314 1170
1315 \LMHash{}
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$. 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$.
1317 1172
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,. 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,.
1319 } 1174 }
1320 1175
1321 \LMHash{}
1322 If $k$ is redirecting then its redirect clause has the form 1176 If $k$ is redirecting then its redirect clause has the form
1323 1177
1324 \THIS{}$.g(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 1178 \THIS{}$.g(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
1325 1179
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$. 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$.
1327 1181
1328 \LMHash{}
1329 Otherwise, execution proceeds as follows: 1182 Otherwise, execution proceeds as follows:
1330 1183
1331 \LMHash{}
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). 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).
1333 %Next, a 1185 %Next, a
1334 Any initializing formals declared in $k$'s parameter list are executed in the or der they appear in the program text. 1186 Any initializing formals declared in $k$'s parameter list are executed in the or der they appear in the program text.
1335 % In fact, this order is unobservable; this could be done any time prior to runn ing the body, since 1187 % In fact, this order is unobservable; this could be done any time prior to runn ing the body, since
1336 % these only effect \THIS{}. 1188 % these only effect \THIS{}.
1337 Then, $k$'s initializers are executed in the order they appear in the program. 1189 Then, $k$'s initializers are executed in the order they appear in the program.
1338 1190
1339 \rationale {We could observe the order by side effecting external routines call ed. So we need to specify the order.} 1191 \rationale {We could observe the order by side effecting external routines call ed. So we need to specify the order.}
1340 1192
1341 \LMHash{}
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$. 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$.
1343 1194
1344 \rationale{ 1195 \rationale{
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. 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.
1346 } 1197 }
1347 1198
1348 \LMHash{}
1349 Execution of an initializer of the form \code{\THIS{}.$v$ = $e$} proceeds as fol lows: 1199 Execution of an initializer of the form \code{\THIS{}.$v$ = $e$} proceeds as fol lows:
1350 1200
1351 \LMHash{}
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$. 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$.
1353 1202
1354 \LMHash{}
1355 An initializer of the form \code{$v$ = $e$} is equivalent to an initializer of t he form \code{\THIS{}.$v$ = $e$}. 1203 An initializer of the form \code{$v$ = $e$} is equivalent to an initializer of t he form \code{\THIS{}.$v$ = $e$}.
1356 1204
1357 \LMHash{}
1358 Execution of a superinitializer of the form 1205 Execution of a superinitializer of the form
1359 1206
1360 \SUPER{}$(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$ 1207 \SUPER{}$(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$
1361 1208
1362 (respectively \SUPER{}$.id(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$ 1209 (respectively \SUPER{}$.id(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$
1363 1210
1364 proceeds as follows: 1211 proceeds as follows:
1365 1212
1366 \LMHash{}
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. 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.
1368 1214
1369 \LMHash{}
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$. 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$.
1371 1216
1372 \LMHash{}
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$. 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$.
1374 1218
1375 \LMHash{}
1376 It is a compile-time error if class $S$ does not declare a generative constructo r named $S$ (respectively $S.id$). 1219 It is a compile-time error if class $S$ does not declare a generative constructo r named $S$ (respectively $S.id$).
1377 1220
1378 \subsubsection{Factories} 1221 \subsubsection{Factories}
1379 \LMLabel{factories} 1222 \label{factories}
1380 1223
1381 \LMHash{}
1382 A {\em factory} is a constructor prefaced by the built-in identifier (\ref{iden tifierReference}) \FACTORY{}. 1224 A {\em factory} is a constructor prefaced by the built-in identifier (\ref{iden tifierReference}) \FACTORY{}.
1383 1225
1384 \begin{grammar} 1226 \begin{grammar}
1385 {\bf factoryConstructorSignature:} 1227 {\bf factoryConstructorSignature:}
1386 \FACTORY{} identifier (`{\escapegrammar .}' identifier)? formalParameter List 1228 \FACTORY{} identifier (`{\escapegrammar .}' identifier)? formalParameter List
1387 . 1229 .
1388 \end{grammar} 1230 \end{grammar}
1389 1231
1390 1232
1391 %The enclosing scope of a factory constructor is the static scope \ref{} of the class in which it is declared. 1233 %The enclosing scope of a factory constructor is the static scope \ref{} of the class in which it is declared.
1392 1234
1393 \LMHash{}
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 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
1395 1236
1396 \LMHash{}
1397 It is a compile-time error if $M$ is not the name of the immediately enclosing c lass. 1237 It is a compile-time error if $M$ is not the name of the immediately enclosing c lass.
1398 1238
1399 \LMHash{}
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. 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.
1401 1240
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.} 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.}
1403 1242
1404 \rationale{Factories address classic weaknesses associated with constructors in other languages. 1243 \rationale{Factories address classic weaknesses associated with constructors in other languages.
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. 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.
1406 1245
1407 } 1246 }
1408 1247
1409 \paragraph{Redirecting Factory Constructors} 1248 \paragraph{Redirecting Factory Constructors}
1410 \LMLabel{redirectingFactoryConstructors} 1249 \label{redirectingFactoryConstructors}
1411 1250
1412 \LMHash{}
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. 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.
1414 1252
1415 \begin{grammar} 1253 \begin{grammar}
1416 {\bf redirectingFactoryConstructorSignature:} 1254 {\bf redirectingFactoryConstructorSignature:}
1417 \CONST{}? \FACTORY{} identifier (`{\escapegrammar .}' identifier)? formalP arameterList `=' type (`{\escapegrammar .}' identifier)? 1255 \CONST{}? \FACTORY{} identifier (`{\escapegrammar .}' identifier)? formalP arameterList `=' type (`{\escapegrammar .}' identifier)?
1418 . 1256 .
1419 \end{grammar} 1257 \end{grammar}
1420 1258
1421 \LMHash{}
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}). 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}).
1423 1260
1424 \commentary{ 1261 \commentary{
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$. 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$.
1426 } 1263 }
1427 1264
1428 \LMHash{}
1429 It is a compile-time error if $k$ explicitly specifies a default value for an op tional parameter.\commentary{ 1265 It is a compile-time error if $k$ explicitly specifies a default value for an op tional parameter.\commentary{
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. 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.
1431 } 1267 }
1432 1268
1433 \LMHash{}
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. 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.
1435 1270
1436 % Make this a runtime error so deferred loading works 1271 % Make this a runtime error so deferred loading works
1437 1272
1438 \rationale{ 1273 \rationale{
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. 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.
1440 } 1275 }
1441 1276
1442 1277
1443 \LMHash{}
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$. 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$.
1445 1279
1446 \commentary{ 1280 \commentary{
1447 Note that it is not possible to modify the arguments being passed to $k'$. 1281 Note that it is not possible to modify the arguments being passed to $k'$.
1448 } 1282 }
1449 % but we have the same issue with other redirecting constructors, no?) 1283 % but we have the same issue with other redirecting constructors, no?)
1450 \rationale{ 1284 \rationale{
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: 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:
1452 \begin{itemize} 1286 \begin{itemize}
1453 \item An abstract class may provide a constant constructor that utilizes the con stant constructor of another class. 1287 \item An abstract class may provide a constant constructor that utilizes the con stant constructor of another class.
(...skipping 21 matching lines...) Expand all
1475 1309
1476 %\CLASS{} A$<$T$>${ 1310 %\CLASS{} A$<$T$>${
1477 % \FACTORY{} A.idw(w) $=>$ F$<$T$>$.idw(w); 1311 % \FACTORY{} A.idw(w) $=>$ F$<$T$>$.idw(w);
1478 %// illegal - cannot pass type parameter to static method 1312 %// illegal - cannot pass type parameter to static method
1479 % \FACTORY{} A.idx(x) $=> \NEW{} $F$<$T$>$.idx(x); // works, but allocates a gr atuitous instance of F 1313 % \FACTORY{} A.idx(x) $=> \NEW{} $F$<$T$>$.idx(x); // works, but allocates a gr atuitous instance of F
1480 % \FACTORY{} A.idy(y) = Y$<$T$>$; // works 1314 % \FACTORY{} A.idy(y) = Y$<$T$>$; // works
1481 % \FACTORY{} A.idz(z) $=>$ F.idz(z); // wrong - returns Z$<$Dynamic$>$; no way to pass type argument 1315 % \FACTORY{} A.idz(z) $=>$ F.idz(z); // wrong - returns Z$<$Dynamic$>$; no way to pass type argument
1482 } 1316 }
1483 %\end{dartCode} 1317 %\end{dartCode}
1484 1318
1485 \LMHash{}
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}). 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}).
1487 1320
1488 \LMHash{}
1489 It is a static warning if the function type of $k^\prime$ is not a subtype of th e type of $k$. 1321 It is a static warning if the function type of $k^\prime$ is not a subtype of th e type of $k$.
1490 1322
1491 \commentary{ 1323 \commentary{
1492 This implies that the resulting object conforms to the interface of the immedia tely enclosing class of $k$. 1324 This implies that the resulting object conforms to the interface of the immedia tely enclosing class of $k$.
1493 } 1325 }
1494 1326
1495 \LMHash{}
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$. 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$.
1497 1328
1498 1329
1499 \subsubsection{Constant Constructors} 1330 \subsubsection{Constant Constructors}
1500 \LMLabel{constantConstructors} 1331 \label{constantConstructors}
1501 1332
1502 \LMHash{}
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{}. 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{}.
1504 1334
1505 \begin{grammar} 1335 \begin{grammar}
1506 {\bf constantConstructorSignature:} 1336 {\bf constantConstructorSignature:}
1507 \CONST{} qualified formalParameterList 1337 \CONST{} qualified formalParameterList
1508 . 1338 .
1509 \end{grammar} 1339 \end{grammar}
1510 1340
1511 1341
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.} 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.}
1513 1343
1514 % \Q{How to specify?} 1344 % \Q{How to specify?}
1515 1345
1516 \commentary{All the work of a constant constructor must be handled via its initi alizers.} 1346 \commentary{All the work of a constant constructor must be handled via its initi alizers.}
1517 1347
1518 \LMHash{}
1519 It is a compile-time error if a constant constructor is declared by a class that has a non-final instance variable. 1348 It is a compile-time error if a constant constructor is declared by a class that has a non-final instance variable.
1520 1349
1521 \commentary{ 1350 \commentary{
1522 The above refers to both locally declared and inherited instance variables. 1351 The above refers to both locally declared and inherited instance variables.
1523 } 1352 }
1524 1353
1525 \LMHash{}
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. 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.
1527 1355
1528 \commentary { 1356 \commentary {
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). 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).
1530 } 1358 }
1531 1359
1532 \LMHash{}
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. 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.
1534 1361
1535 \LMHash{}
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. 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.
1537 1363
1538 \LMHash{}
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. 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.
1540 1365
1541 \commentary{ 1366 \commentary{
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} 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}
1543 1368
1544 \begin{dartCode} 1369 \begin{dartCode}
1545 \CLASS{} A \{ 1370 \CLASS{} A \{
1546 \FINAL{} m; 1371 \FINAL{} m;
1547 \CONST{} A(this.m); 1372 \CONST{} A(this.m);
1548 \} 1373 \}
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 \commentary{ 1417 \commentary{
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. 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.
1594 } 1419 }
1595 1420
1596 \rationale{ 1421 \rationale{
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{}. 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{}.
1598 1423
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}). 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}).
1600 } 1425 }
1601 1426
1602 \LMHash{}
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. 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.
1604 1428
1605 %Discuss External Constructors in ne subsubsection here 1429 %Discuss External Constructors in ne subsubsection here
1606 1430
1607 \subsection{Static Methods} 1431 \subsection{Static Methods}
1608 \LMLabel{staticMethods} 1432 \label{staticMethods}
1609 1433
1610 \LMHash{}
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$. 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$.
1612 1435
1613 \LMHash{}
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. 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.
1615 1437
1616 \rationale{ 1438 \rationale{
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. 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.
1618 1440
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. 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.
1620 } 1442 }
1621 1443
1622 \LMHash{}
1623 It is a static warning if a class $C$ declares a static method named $n$ and has a setter named $n=$. 1444 It is a static warning if a class $C$ declares a static method named $n$ and has a setter named $n=$.
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. 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.
1625 1446
1626 %\rationale{ 1447 %\rationale{
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. 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.
1628 %} 1449 %}
1629 %\commentary{ 1450 %\commentary{
1630 %There is no hiding of static methods, or of static variables. 1451 %There is no hiding of static methods, or of static variables.
1631 %} 1452 %}
1632 1453
1633 1454
1634 \subsection{Static Variables} 1455 \subsection{Static Variables}
1635 \LMLabel{staticVariables} 1456 \label{staticVariables}
1636 1457
1637 \LMHash{}
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$. 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$.
1639 1459
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 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
1641 1461
1642 %\STATIC{} $T$ \GET{} $v$ 1462 %\STATIC{} $T$ \GET{} $v$
1643 1463
1644 %whose invocation evaluates as described below (\ref{evaluationOfStaticVariableG etters}).%to the value stored in $v$. 1464 %whose invocation evaluates as described below (\ref{evaluationOfStaticVariableG etters}).%to the value stored in $v$.
1645 1465
1646 1466
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 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
(...skipping 10 matching lines...) Expand all
1658 1478
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 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
1660 1480
1661 %\STATIC{} \SET{} $v=(x)$ 1481 %\STATIC{} \SET{} $v=(x)$
1662 1482
1663 %whose execution sets the value of $v$ to the incoming argument $x$. 1483 %whose execution sets the value of $v$ to the incoming argument $x$.
1664 1484
1665 %Extrernal static functions, getters, setters 1485 %Extrernal static functions, getters, setters
1666 1486
1667 %\subsubsection{Evaluation of Implicit Static Variable Getters} 1487 %\subsubsection{Evaluation of Implicit Static Variable Getters}
1668 %\LMLabel{evaluationOfStaticVariableGetters} 1488 %\label{evaluationOfStaticVariableGetters}
1669 1489
1670 %Let $d$ be the declaration of a static variable $v$. The implicit getter method of $v$ executes as follows: 1490 %Let $d$ be the declaration of a static variable $v$. The implicit getter method of $v$ executes as follows:
1671 %\begin{itemize} 1491 %\begin{itemize}
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$. 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$.
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$. 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$.
1674 %Otherwise 1494 %Otherwise
1675 %\item The result of executing the getter method is the value stored in $v$. 1495 %\item The result of executing the getter method is the value stored in $v$.
1676 %\end{itemize} 1496 %\end{itemize}
1677 1497
1678 1498
1679 1499
1680 \subsection{Superclasses} 1500 \subsection{Superclasses}
1681 \LMLabel{superclasses} 1501 \label{superclasses}
1682 1502
1683 \LMHash{}
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: 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:
1685 \begin{itemize} 1504 \begin{itemize}
1686 \item $C$ is \code{Object}, which has no superclass. OR 1505 \item $C$ is \code{Object}, which has no superclass. OR
1687 \item Class $C$ is deemed to have an \EXTENDS{} clause of the form \code{\EXTEN DS{} Object}, and the rules above apply. 1506 \item Class $C$ is deemed to have an \EXTENDS{} clause of the form \code{\EXTEN DS{} Object}, and the rules above apply.
1688 \end{itemize} 1507 \end{itemize}
1689 1508
1690 \LMHash{}
1691 It is a compile-time error to specify an \EXTENDS{} clause for class \code{Objec t}. 1509 It is a compile-time error to specify an \EXTENDS{} clause for class \code{Objec t}.
1692 1510
1693 \begin{grammar} 1511 \begin{grammar}
1694 {\bf superclass:} 1512 {\bf superclass:}
1695 \EXTENDS{} type 1513 \EXTENDS{} type
1696 . 1514 .
1697 \end{grammar} 1515 \end{grammar}
1698 1516
1699 %The superclass clause of a class C is processed within the enclosing scope of t he static scope of C. 1517 %The superclass clause of a class C is processed within the enclosing scope of t he static scope of C.
1700 %\commentary{ 1518 %\commentary{
1701 %This means that in a generic class, the type parameters of the generic are avai lable in the superclass clause. 1519 %This means that in a generic class, the type parameters of the generic are avai lable in the superclass clause.
1702 %} 1520 %}
1703 1521
1704 \LMHash{}
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$. 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$.
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. 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.
1707 % too strict? Do we e want extends List<Undeclared> to work as List<dynamic>? 1524 % too strict? Do we e want extends List<Undeclared> to work as List<dynamic>?
1708 1525
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: 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:
1710 } 1527 }
1711 1528
1712 \begin{dartCode} 1529 \begin{dartCode}
1713 class T \{\} 1530 class T \{\}
1714 1531
1715 /* Compilation error: Attempt to subclass a type parameter */ 1532 /* Compilation error: Attempt to subclass a type parameter */
1716 class G$<$T$>$ extends T \{\} 1533 class G$<$T$>$ extends T \{\}
1717 1534
1718 \end{dartCode} 1535 \end{dartCode}
1719 1536
1720 1537
1721 \LMHash{}
1722 A class $S$ is {\em a superclass} of a class $C$ iff either: 1538 A class $S$ is {\em a superclass} of a class $C$ iff either:
1723 \begin{itemize} 1539 \begin{itemize}
1724 \item $S$ is the superclass of $C$, or 1540 \item $S$ is the superclass of $C$, or
1725 \item $S$ is a superclass of a class $S^{\prime}$ and $S^{\prime}$ is a supercla ss of $C$. 1541 \item $S$ is a superclass of a class $S^{\prime}$ and $S^{\prime}$ is a supercla ss of $C$.
1726 \end{itemize} 1542 \end{itemize}
1727 1543
1728 \LMHash{}
1729 It is a compile-time error if a class $C$ is a superclass of itself. 1544 It is a compile-time error if a class $C$ is a superclass of itself.
1730 1545
1731 1546
1732 1547
1733 1548
1734 \subsubsection{Inheritance and Overriding} 1549 \subsubsection{Inheritance and Overriding}
1735 \LMLabel{inheritanceAndOverriding} 1550 \label{inheritanceAndOverriding}
1736 1551
1737 1552
1738 %A class $C$ {\em inherits} any accessible instance members of its superclass t hat are not overridden by members declared in $C$. 1553 %A class $C$ {\em inherits} any accessible instance members of its superclass t hat are not overridden by members declared in $C$.
1739 1554
1740 \LMHash{}
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$. 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$.
1742 1556
1743 \rationale { 1557 \rationale {
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 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
1745 to the library $L_1$ of $C$, whereas $S$ comes from a different library $L_2$, b ut 1559 to the library $L_1$ of $C$, whereas $S$ comes from a different library $L_2$, b ut
1746 the superclass chain of $S$ includes a class declared in $L_1$. 1560 the superclass chain of $S$ includes a class declared in $L_1$.
1747 } 1561 }
1748 1562
1749 \LMHash{}
1750 A class may override instance members that would otherwise have been inherited f rom its superclass. 1563 A class may override instance members that would otherwise have been inherited f rom its superclass.
1751 1564
1752 \LMHash{}
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. 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.
1754 1566
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. 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.
1756 1568
1757 \commentary{Fields never override each other. The getters and setters induced by fields do.} 1569 \commentary{Fields never override each other. The getters and setters induced by fields do.}
1758 1570
1759 \rationale{Again, a local definition of overriding would be preferable, but fail s to account for library privacy. 1571 \rationale{Again, a local definition of overriding would be preferable, but fail s to account for library privacy.
1760 } 1572 }
1761 1573
1762 \LMHash{}
1763 Whether an override is legal or not is described elsewhere in this specification (see \ref{instanceMethods}, \ref{getters} and \ref{setters}). 1574 Whether an override is legal or not is described elsewhere in this specification (see \ref{instanceMethods}, \ref{getters} and \ref{setters}).
1764 1575
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. 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.
1766 } 1577 }
1767 1578
1768 \rationale{ 1579 \rationale{
1769 It is nevertheless convenient to define the override relation between members in this way, so that we can concisely describe the illegal cases. 1580 It is nevertheless convenient to define the override relation between members in this way, so that we can concisely describe the illegal cases.
1770 } 1581 }
1771 1582
1772 \commentary{ 1583 \commentary{
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. 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.
1774 } 1585 }
1775 1586
1776 \LMHash{}
1777 It is a static warning if a non-abstract class inherits an abstract method. 1587 It is a static warning if a non-abstract class inherits an abstract method.
1778 1588
1779 \commentary { 1589 \commentary {
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. 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.
1781 1591
1782 \begin{enumerate} 1592 \begin{enumerate}
1783 1593
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}). 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}).
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}). 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}).
1786 \item Static members are never inherited. 1596 \item Static members are never inherited.
(...skipping 27 matching lines...) Expand all
1814 \item Rule \ref{typeSigAssignable} applies to interfaces as well as classes (\ ref{interfaceInheritanceAndOverriding}). 1624 \item Rule \ref{typeSigAssignable} applies to interfaces as well as classes (\ ref{interfaceInheritanceAndOverriding}).
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}). 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}).
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}) . 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}) .
1817 \end{enumerate} 1627 \end{enumerate}
1818 } 1628 }
1819 1629
1820 1630
1821 %Can we have abstract getters and setters? 1631 %Can we have abstract getters and setters?
1822 1632
1823 \subsection{ Superinterfaces} 1633 \subsection{ Superinterfaces}
1824 \LMLabel{superinterfaces} 1634 \label{superinterfaces}
1825 % what about rules about classes that fail to implement their interfaces? 1635 % what about rules about classes that fail to implement their interfaces?
1826 1636
1827 \LMHash{}
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. 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.
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?} 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?}
1830 1639
1831 \begin{grammar} 1640 \begin{grammar}
1832 {\bf interfaces:} 1641 {\bf interfaces:}
1833 \IMPLEMENTS{} typeList 1642 \IMPLEMENTS{} typeList
1834 . 1643 .
1835 \end{grammar} 1644 \end{grammar}
1836 1645
1837 \LMHash{}
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. 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.
1839 It is a compile-time error if the superclass of a class $C$ is specified as a su perinterface of $C$. 1647 It is a compile-time error if the superclass of a class $C$ is specified as a su perinterface of $C$.
1840 1648
1841 \rationale{ 1649 \rationale{
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. 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.
1843 } 1651 }
1844 1652
1845 \LMHash{}
1846 It is a compile-time error if the interface of a class $C$ is a superinterface o f itself. 1653 It is a compile-time error if the interface of a class $C$ is a superinterface o f itself.
1847 1654
1848 \LMHash{}
1849 Let $C$ be a concrete class that does not declare its own \code{noSuchMethod()} method. 1655 Let $C$ be a concrete class that does not declare its own \code{noSuchMethod()} method.
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$. 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$.
1851 1657
1852 \commentary{A class does not inherit members from its superinterfaces. However, its implicit interface does. 1658 \commentary{A class does not inherit members from its superinterfaces. However, its implicit interface does.
1853 } 1659 }
1854 1660
1855 1661
1856 \rationale { 1662 \rationale {
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. 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.
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. 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.
1859 1665
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: 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:
1861 } 1667 }
1862 1668
1863 \begin{dartCode} 1669 \begin{dartCode}
1864 noSuchMethod(inv) =$>$ \SUPER.noSuchMethod(inv); 1670 noSuchMethod(inv) =$>$ \SUPER.noSuchMethod(inv);
1865 \end{dartCode} 1671 \end{dartCode}
1866 1672
1867 \LMHash{}
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$. 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$.
1869 1674
1870 \rationale{ 1675 \rationale{
1871 However, if a class does explicitly declare a member that conflicts with its sup erinterface, this always yields a static warning. 1676 However, if a class does explicitly declare a member that conflicts with its sup erinterface, this always yields a static warning.
1872 1677
1873 } 1678 }
1874 %It is a static warning if an imported superinterface of a class $C$ declares pr ivate members. 1679 %It is a static warning if an imported superinterface of a class $C$ declares pr ivate members.
1875 1680
1876 % Should we ignore unimplemented private members? 1681 % Should we ignore unimplemented private members?
1877 1682
(...skipping 14 matching lines...) Expand all
1892 1697
1893 %class C implements I1, I2 {...}; // class declaration 1698 %class C implements I1, I2 {...}; // class declaration
1894 1699
1895 %this should not cause breakage. 1700 %this should not cause breakage.
1896 %} 1701 %}
1897 1702
1898 % \rationale{This avoids the issues with so-called miranda methods etc. } 1703 % \rationale{This avoids the issues with so-called miranda methods etc. }
1899 1704
1900 1705
1901 \section{Interfaces} 1706 \section{Interfaces}
1902 \LMLabel{interfaces} 1707 \label{interfaces}
1903 1708
1904 \LMHash{}
1905 An {\em interface} defines how one may interact with an object. An interface has methods, getters and setters and a set of superinterfaces. 1709 An {\em interface} defines how one may interact with an object. An interface has methods, getters and setters and a set of superinterfaces.
1906 1710
1907 \subsection{Superinterfaces} 1711 \subsection{Superinterfaces}
1908 \LMLabel{interfaceSuperinterfaces} 1712 \label{interfaceSuperinterfaces}
1909 1713
1910 \LMHash{}
1911 An interface has a set of direct superinterfaces. 1714 An interface has a set of direct superinterfaces.
1912 1715
1913 \LMHash{}
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$. 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$.
1915 1717
1916 1718
1917 1719
1918 1720
1919 \subsubsection{Inheritance and Overriding} 1721 \subsubsection{Inheritance and Overriding}
1920 \LMLabel{interfaceInheritanceAndOverriding} 1722 \label{interfaceInheritanceAndOverriding}
1921 1723
1922 \LMHash{}
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: 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:
1924 \begin{itemize} 1725 \begin{itemize}
1925 \item $m$ is accessible to $K$ and 1726 \item $m$ is accessible to $K$ and
1926 \item $A$ is a direct superinterface of $J$ and either 1727 \item $A$ is a direct superinterface of $J$ and either
1927 \begin{itemize} 1728 \begin{itemize}
1928 \item $A$ declares a member $m$ or 1729 \item $A$ declares a member $m$ or
1929 \item $m$ is a member of $inherited(A, K)$. 1730 \item $m$ is a member of $inherited(A, K)$.
1930 \end{itemize} 1731 \end{itemize}
1931 \item $m$ is not overridden by $J$. 1732 \item $m$ is not overridden by $J$.
1932 \end{itemize} 1733 \end{itemize}
1933 1734
1934 \LMHash{}
1935 Furthermore, we define $overrides(J, K)$ to be the set of members $m^\prime$ su ch that all of the following hold: 1735 Furthermore, we define $overrides(J, K)$ to be the set of members $m^\prime$ su ch that all of the following hold:
1936 \begin{itemize} 1736 \begin{itemize}
1937 \item $J$ is the implicit interface of a class $C$. 1737 \item $J$ is the implicit interface of a class $C$.
1938 \item $C$ declares a member $m$. 1738 \item $C$ declares a member $m$.
1939 \item $m^\prime$ has the same name as $m$. 1739 \item $m^\prime$ has the same name as $m$.
1940 \item $m^\prime$ is accessible to $K$. 1740 \item $m^\prime$ is accessible to $K$.
1941 \item $A$ is a direct superinterface of $J$ and either 1741 \item $A$ is a direct superinterface of $J$ and either
1942 \begin{itemize} 1742 \begin{itemize}
1943 \item $A$ declares a member $m^\prime$ or 1743 \item $A$ declares a member $m^\prime$ or
1944 \item $m^\prime$ is a member of $inherited(A, K)$. 1744 \item $m^\prime$ is a member of $inherited(A, K)$.
1945 \end{itemize} 1745 \end{itemize}
1946 \end{itemize} 1746 \end{itemize}
1947 1747
1948 1748
1949 \LMHash{}
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)$. 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)$.
1951 1750
1952 \LMHash{}
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. 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.
1954 1752
1955 \LMHash{}
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. 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.
1957 1754
1958 1755
1959 1756
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$. 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$.
1961 1758
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$. 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$.
1963 1760
1964 % tighten definition? do we need chain as for classes? Definition for interface override? 1761 % tighten definition? do we need chain as for classes? Definition for interface override?
1965 1762
1966 \LMHash{}
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. 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.
1968 1764
1969 \LMHash{}
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. 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.
1971 1766
1972 \LMHash{}
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: 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:
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 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
1975 1769
1976 $h = max(numberOfPositionals(m_i)), $ 1770 $h = max(numberOfPositionals(m_i)), $
1977 1771
1978 $r = min(numberOfRequiredParams(m_i)), i \in 1..k$. 1772 $r = min(numberOfRequiredParams(m_i)), i \in 1..k$.
1979 1773
1980 \LMHash{}
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{}. 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{}.
1982 1775
1983 1776
1984 1777
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. 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.
1986 } 1779 }
1987 1780
1988 \rationale{ 1781 \rationale{
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. 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.
1990 1783
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. 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.
1992 } 1785 }
1993 1786
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. 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.
1995 1788
1996 \section{Mixins} 1789 \section{Mixins}
1997 \LMLabel{mixins} 1790 \label{mixins}
1998 1791
1999 1792
2000 \LMHash{}
2001 A mixin describes the difference between a class and its superclass. A mixin is always derived from an existing class declaration. 1793 A mixin describes the difference between a class and its superclass. A mixin is always derived from an existing class declaration.
2002 1794
2003 \LMHash{}
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}. 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}.
2005 1796
2006 \rationale{ 1797 \rationale{
2007 These restrictions are temporary. We expect to remove them in later versions of Dart. 1798 These restrictions are temporary. We expect to remove them in later versions of Dart.
2008 1799
2009 The restriction on the use of \SUPER{} avoids the problem of rebinding \SUPER{} when the mixin is bound to difference superclasses. 1800 The restriction on the use of \SUPER{} avoids the problem of rebinding \SUPER{} when the mixin is bound to difference superclasses.
2010 1801
2011 The restriction on constructors simplifies the construction of mixin application s because the process of creating instances is simpler. 1802 The restriction on constructors simplifies the construction of mixin application s because the process of creating instances is simpler.
2012 1803
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. 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.
2014 1805
2015 Reasonable answers exist for all these issues, but their implementation is non-t rivial. 1806 Reasonable answers exist for all these issues, but their implementation is non-t rivial.
2016 } 1807 }
2017 1808
2018 \subsection{Mixin Application} 1809 \subsection{Mixin Application}
2019 \LMLabel{mixinApplication} 1810 \label{mixinApplication}
2020 1811
2021 \LMHash{}
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. 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.
2023 1813
2024 1814
2025 \begin{grammar} 1815 \begin{grammar}
2026 {\bf mixinApplicationClass:} 1816 {\bf mixinApplicationClass:}
2027 identifier typeParameters? `=' mixinApplication `{\escapegrammar ;}' . 1817 identifier typeParameters? `=' mixinApplication `{\escapegrammar ;}' .
2028 1818
2029 {\bf mixinApplication:} 1819 {\bf mixinApplication:}
2030 type mixins interfaces? 1820 type mixins interfaces?
2031 . 1821 .
2032 \end{grammar} 1822 \end{grammar}
2033 1823
2034 \LMHash{}
2035 A mixin application of the form \code{$S$ \WITH{} $M$;} defines a class $C$ w ith superclass $S$. 1824 A mixin application of the form \code{$S$ \WITH{} $M$;} defines a class $C$ w ith superclass $S$.
2036 1825
2037 \LMHash{}
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$. 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$.
2039 1827
2040 \LMHash{}
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$. 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$.
2042 1829
2043 \LMHash{}
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 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
2045 $q'_i = [C/S]q_i$ of the form 1831 $q'_i = [C/S]q_i$ of the form
2046 1832
2047 $q'_i(a_{i1}, \ldots , a_{ik_i}):\SUPER(a_{i1}, \ldots , a_{ik_i});$. 1833 $q'_i(a_{i1}, \ldots , a_{ik_i}):\SUPER(a_{i1}, \ldots , a_{ik_i});$.
2048 1834
2049 \LMHash{} 1835 %super.id
1836
2050 If the mixin application declares support for interfaces, the resulting class im plements those interfaces. 1837 If the mixin application declares support for interfaces, the resulting class im plements those interfaces.
2051 1838
2052 \LMHash{}
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$). 1839 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$).
2054 1840
2055 \LMHash{}
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. 1841 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.
2057 1842
2058 \commentary{ 1843 \commentary{
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$. 1844 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$.
2060 1845
2061 } 1846 }
2062 1847
2063 \LMHash{}
2064 The effect of a class definition of the form \code{\CLASS{} $C$ = $M$; } or the form 1848 The effect of a class definition of the form \code{\CLASS{} $C$ = $M$; } or the form
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. 1849 \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.
2066 1850
2067 1851
2068 \subsection{Mixin Composition} 1852 \subsection{Mixin Composition}
2069 \LMLabel{mixinComposition} 1853 \label{mixinComposition}
2070 1854
2071 \rationale{ 1855 \rationale{
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. 1856 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.
2073 } 1857 }
2074 1858
2075 \LMHash{}
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 1859 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
2077 1860
2078 $M_1<T_1 \ldots T_{k_{M_1}}> * M_2<U_1 \ldots U_{k_{M_2}}>$ 1861 $M_1<T_1 \ldots T_{k_{M_1}}> * M_2<U_1 \ldots U_{k_{M_2}}>$
2079 1862
2080 to $S<V_1 \ldots V_{k_S}>$ is equivalent to 1863 to $S<V_1 \ldots V_{k_S}>$ is equivalent to
2081 1864
2082 \begin{dartCode} 1865 \begin{dartCode}
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}> = $ 1866 \ABSTRACT{} \CLASS{} $Id_1<T_1 \ldots T_{k_{M_1}}, U_1 \ldots U_{k_{M_2}}, V_1 \ldots V_{k_S}> = $
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}}>$; 1867 $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}}>$;
2085 \end{dartCode} 1868 \end{dartCode}
2086 1869
2087 where $Id_2$ denotes 1870 where $Id_2$ denotes
2088 1871
2089 \begin{dartCode} 1872 \begin{dartCode}
2090 \ABSTRACT{} \CLASS{} $Id_2<U_1 \ldots U_{k_{M_2}}, V_1 \ldots V_{k_S}> =$ 1873 \ABSTRACT{} \CLASS{} $Id_2<U_1 \ldots U_{k_{M_2}}, V_1 \ldots V_{k_S}> =$
2091 $S<V_1 \ldots V_{k_S}>$ \WITH{} $M_2<U_1 \ldots U_{k_{ M_2}}>$; 1874 $S<V_1 \ldots V_{k_S}>$ \WITH{} $M_2<U_1 \ldots U_{k_{ M_2}}>$;
2092 \end{dartCode} 1875 \end{dartCode}
2093 1876
2094 and $Id_1$ and $Id_2$ are unique identifiers that do not exist anywhere in the p rogram. 1877 and $Id_1$ and $Id_2$ are unique identifiers that do not exist anywhere in the p rogram.
2095 1878
2096 \rationale{ 1879 \rationale{
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. 1880 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.
2098 } 1881 }
2099 1882
2100 \LMHash{}
2101 Mixin composition is associative. 1883 Mixin composition is associative.
2102 1884
2103 1885
2104 \commentary{ 1886 \commentary{
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. 1887 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.
2106 } 1888 }
2107 1889
2108 1890
2109 \section{Enums} 1891 \section{Enums}
2110 \LMLabel{enums} 1892 \label{enums}
2111 1893
2112 \LMHash{}
2113 An {\em enumerated type}, or {\em enum}, is used to represent a fixed number of constant values. 1894 An {\em enumerated type}, or {\em enum}, is used to represent a fixed number of constant values.
2114 1895
2115 \begin{grammar} 1896 \begin{grammar}
2116 {\bf enumType:} 1897 {\bf enumType:}
2117 metadata \ENUM{} id `\{' id [`,' id]* [`,'] `\}' 1898 metadata \ENUM{} id `\{' id [`,' id]* [`,'] `\}'
2118 . 1899 .
2119 \end{grammar} 1900 \end{grammar}
2120 1901
2121 \LMHash{}
2122 The declaration of an enum of the form \code{metadata \ENUM{} E \{ id$_0$, \ldot s id$_{n-1}$\};} 1902 The declaration of an enum of the form \code{metadata \ENUM{} E \{ id$_0$, \ldot s id$_{n-1}$\};}
2123 has the same effect as a class declaration 1903 has the same effect as a class declaration
2124 1904
2125 \begin{dartCode} 1905 \begin{dartCode}
2126 metadata \CLASS{} E \{ 1906 metadata \CLASS{} E \{
2127 \FINAL{} int index; 1907 \FINAL{} int index;
2128 \CONST{} E(\THIS{}.index); 1908 \CONST{} E(\THIS{}.index);
2129 \STATIC{} \CONST{} E id$_0$ = \CONST{} E(0); 1909 \STATIC{} \CONST{} E id$_0$ = \CONST{} E(0);
2130 $\ldots$ 1910 $\ldots$
2131 \STATIC{} \CONST{} E id$_{n-1}$ = const E(n - 1); 1911 \STATIC{} \CONST{} E id$_{n-1}$ = const E(n - 1);
2132 \STATIC{} \CONST{} List$<$E$>$ values = const $<$E$>$[id$_0 \ldots $ id$_{n-1} $]; 1912 \STATIC{} \CONST{} List$<$E$>$ values = const $<$E$>$[id$_0 \ldots $ id$_{n-1} $];
2133 String toString() =$>$ \{ 0: `E.id$_0$', $\ldots$, n-1: `E.id$_{n-1}$'\}[index ] 1913 String toString() =$>$ \{ 0: `E.id$_0$', $\ldots$, n-1: `E.id$_{n-1}$'\}[index ]
2134 \} 1914 \}
2135 \end{dartCode} 1915 \end{dartCode}
2136 1916
2137 \commentary { 1917 \commentary {
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. 1918 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.
2139 } 1919 }
2140 1920
2141 \section{Generics} 1921 \section{Generics}
2142 \LMLabel{generics} 1922 \label{generics}
2143 1923
2144 \LMHash{}
2145 A class declaration (\ref{classes}) or type alias (\ref{typedef}) 1924 A class declaration (\ref{classes}) or type alias (\ref{typedef})
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. 1925 $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.
2147 1926
2148 \begin{grammar} 1927 \begin{grammar}
2149 {\bf typeParameter:} 1928 {\bf typeParameter:}
2150 metadata identifier (\EXTENDS{} type)? 1929 metadata identifier (\EXTENDS{} type)?
2151 . 1930 .
2152 {\bf typeParameters:} 1931 {\bf typeParameters:}
2153 `<' typeParameter (`,' typeParameter)* `>' 1932 `<' typeParameter (`,' typeParameter)* `>'
2154 . 1933 .
2155 \end{grammar} 1934 \end{grammar}
2156 1935
2157 \LMHash{}
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. 1936 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.
2159 1937
2160 \LMHash{}
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. 1938 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.
2162 1939
2163 \rationale{ 1940 \rationale{
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. 1941 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.
2165 } 1942 }
2166 1943
2167 \commentary{ 1944 \commentary{
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: 1945 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:
2169 } 1946 }
2170 1947
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2226 2003
2227 2004
2228 %class T {...} 2005 %class T {...}
2229 2006
2230 %class G<T> extends T; 2007 %class G<T> extends T;
2231 2008
2232 %By current rules, this is illegal. Make sure we preserve this. 2009 %By current rules, this is illegal. Make sure we preserve this.
2233 2010
2234 2011
2235 %\subsection{Interface Injection} 2012 %\subsection{Interface Injection}
2236 %\LMLabel{interfaceInjection} 2013 %\label{interfaceInjection}
2237 2014
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. 2015 %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.
2239 2016
2240 %\begin{grammar} 2017 %\begin{grammar}
2241 %classInterfaceInjection: 2018 %classInterfaceInjection:
2242 %class qualified typeParameters? interfaces '{\escapegrammar ;}' 2019 %class qualified typeParameters? interfaces '{\escapegrammar ;}'
2243 % . 2020 % .
2244 2021
2245 2022
2246 %interfaceInterfaceInjection: 2023 %interfaceInterfaceInjection:
2247 %interface qualified typeParameters? superinterfaces '{\escapegrammar ;}' 2024 %interface qualified typeParameters? superinterfaces '{\escapegrammar ;}'
2248 %. 2025 %.
2249 %\end{grammar} 2026 %\end{grammar}
2250 2027
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. 2028 %\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.
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). 2029 %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).
2253 %} 2030 %}
2254 2031
2255 %\Q{When does an interface injection take effect? When the containing library is loaded? 2032 %\Q{When does an interface injection take effect? When the containing library is loaded?
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. 2033 %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.
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? 2034 %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?
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. 2035 %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.
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. 2036 %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.
2260 %} 2037 %}
2261 2038
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. 2039 %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.
2263 2040
2264 2041
2265 \section{Metadata} 2042 \section{Metadata}
2266 \LMLabel{metadata} 2043 \label{metadata}
2267 2044
2268 \LMHash{}
2269 Dart supports metadata which is used to attach user defined annotations to progr am structures. 2045 Dart supports metadata which is used to attach user defined annotations to progr am structures.
2270 2046
2271 \begin{grammar} 2047 \begin{grammar}
2272 {\bf metadata:} 2048 {\bf metadata:}
2273 (`@' qualified ({\escapegrammar `.'} identifier)? (arguments)?)* 2049 (`@' qualified ({\escapegrammar `.'} identifier)? (arguments)?)*
2274 . 2050 .
2275 \end{grammar} 2051 \end{grammar}
2276 2052
2277 \LMHash{}
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: 2053 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:
2279 \begin{itemize} 2054 \begin{itemize}
2280 \item A reference to a compile-time constant variable. 2055 \item A reference to a compile-time constant variable.
2281 \item A call to a constant constructor. 2056 \item A call to a constant constructor.
2282 \end{itemize} 2057 \end{itemize}
2283 2058
2284 \LMHash{}
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. 2059 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.
2286 2060
2287 \commentary{ 2061 \commentary{
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. 2062 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.
2289 } 2063 }
2290 2064
2291 \rationale{ 2065 \rationale{
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. 2066 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.
2293 } 2067 }
2294 2068
2295 \commentary{ 2069 \commentary{
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. 2070 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.
2297 } 2071 }
2298 2072
2299 \LMHash{}
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. 2073 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.
2301 2074
2302 \LMHash{}
2303 The constant expression given in an annotation is type checked and evaluated in the scope surrounding the declaration being annotated. 2075 The constant expression given in an annotation is type checked and evaluated in the scope surrounding the declaration being annotated.
2304 2076
2305 2077
2306 \section{Expressions} 2078 \section{Expressions}
2307 \LMLabel{expressions} 2079 \label{expressions}
2308 2080
2309 \LMHash{}
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}). 2081 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}).
2311 2082
2312 2083
2313 \begin{grammar} 2084 \begin{grammar}
2314 2085
2315 {\bf expression:}assignableExpression assignmentOperator expression; 2086 {\bf expression:}assignableExpression assignmentOperator expression;
2316 conditionalExpression cascadeSection*; 2087 conditionalExpression cascadeSection*;
2317 throwExpression 2088 throwExpression
2318 . 2089 .
2319 2090
(...skipping 14 matching lines...) Expand all
2334 functionExpression; 2105 functionExpression;
2335 literal; 2106 literal;
2336 identifier; 2107 identifier;
2337 newExpression; 2108 newExpression;
2338 constObjectExpression; 2109 constObjectExpression;
2339 `(' expression `)' 2110 `(' expression `)'
2340 . 2111 .
2341 2112
2342 \end{grammar} 2113 \end{grammar}
2343 2114
2344 \LMHash{}
2345 An expression $e$ may always be enclosed in parentheses, but this never has any semantic effect on $e$. 2115 An expression $e$ may always be enclosed in parentheses, but this never has any semantic effect on $e$.
2346 2116
2347 \commentary{ 2117 \commentary{
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. 2118 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.
2349 } 2119 }
2350 2120
2351 \subsubsection{Object Identity} 2121 \subsubsection{Object Identity}
2352 \LMLabel{objectIdentity} 2122 \label{objectIdentity}
2353 2123
2354 \LMHash{}
2355 The predefined Dart function \cd{identical()} is defined such that \code{identic al($c_1$, $c_2$)} iff: 2124 The predefined Dart function \cd{identical()} is defined such that \code{identic al($c_1$, $c_2$)} iff:
2356 \begin{itemize} 2125 \begin{itemize}
2357 \item $c_1$ evaluates to either \NULL{} or an instance of \code{bool} and \co de{$c_1$ == $c_2$}, OR 2126 \item $c_1$ evaluates to either \NULL{} or an instance of \code{bool} and \co de{$c_1$ == $c_2$}, OR
2358 \item $c_1$ and $c_2$ are instances of \code{int} and \code{$c_1$ == $c_2$}, OR 2127 \item $c_1$ and $c_2$ are instances of \code{int} and \code{$c_1$ == $c_2$}, OR
2359 \item $c_1$ and $c_2$ are constant strings and \code{$c_1$ == $c_2$}, OR 2128 \item $c_1$ and $c_2$ are constant strings and \code{$c_1$ == $c_2$}, OR
2360 \item $c_1$ and $c_2$ are instances of \cd{double} and one of the following holds: 2129 \item $c_1$ and $c_2$ are instances of \cd{double} and one of the following holds:
2361 \begin{itemize} 2130 \begin{itemize}
2362 \item $c_1$ and $c_2$ are non-zero and \code{$c_1$ == $c_2$}. 2131 \item $c_1$ and $c_2$ are non-zero and \code{$c_1$ == $c_2$}.
2363 \item Both $c_1$ and $c_2$ are $+0.0$. 2132 \item Both $c_1$ and $c_2$ are $+0.0$.
2364 \item Both $c_1$ and $c_2$ are $-0.0$. 2133 \item Both $c_1$ and $c_2$ are $-0.0$.
(...skipping 13 matching lines...) Expand all
2378 \rationale{ 2147 \rationale{
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. 2148 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.
2380 2149
2381 The definition of identity is not constrained in the same way. Instead, it assum es that bit-identical doubles are identical. 2150 The definition of identity is not constrained in the same way. Instead, it assum es that bit-identical doubles are identical.
2382 2151
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. 2152 The rules for identity make it impossible for a Dart programmer to observe wheth er a boolean or numerical value is boxed or unboxed.
2384 } 2153 }
2385 2154
2386 2155
2387 \subsection{Constants} 2156 \subsection{Constants}
2388 \LMLabel{constants} 2157 \label{constants}
2389 2158
2390 \LMHash{}
2391 A {\em constant expression} is an expression whose value can never change, and t hat can be evaluated entirely at compile time. 2159 A {\em constant expression} is an expression whose value can never change, and t hat can be evaluated entirely at compile time.
2392 2160
2393 \LMHash{}
2394 A constant expression is one of the following: 2161 A constant expression is one of the following:
2395 \begin{itemize} 2162 \begin{itemize}
2396 \item A literal number (\ref{numbers}). 2163 \item A literal number (\ref{numbers}).
2397 \item A literal boolean (\ref{booleans}). 2164 \item A literal boolean (\ref{booleans}).
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{}. 2165 \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{}.
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.} 2166 \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.}
2400 \item A literal symbol (\ref{symbols}). 2167 \item A literal symbol (\ref{symbols}).
2401 \item \NULL{} (\ref{null}). 2168 \item \NULL{} (\ref{null}).
2402 \item A qualified reference to a static constant variable (\ref{variables}) that is not qualified by a deferred prefix. 2169 \item A qualified reference to a static constant variable (\ref{variables}) that is not qualified by 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. 2170 \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.
2404 } 2171 }
2405 \item An identifier expression that denotes a constant variable. 2172 \item An identifier expression that denotes a constant variable.
2406 \item A qualified reference to a static constant variable (\ref{variables}) that is not qualified by a deferred prefix. 2173 \item A simple or qualified identifier denoting a class or type alias that is no t qualified by a deferred prefix.
2407 \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. 2174 \commentary {For example, If C is a class or typedef, C is a constant, and if C is imported with a prefix p, p.C is a constant unless p is a deferred prefix.
2408 } 2175 }
2409 \item A constant constructor invocation (\ref{const}) that is not qualified by a deferred prefix. 2176 \item A constant constructor invocation (\ref{const}) that is not qualified by a deferred prefix.
2410 \item A constant list literal (\ref{lists}). 2177 \item A constant list literal (\ref{lists}).
2411 \item A constant map literal (\ref{maps}). 2178 \item A constant map literal (\ref{maps}).
2412 \item A simple or qualified identifier denoting a top-level function (\ref{funct ions}) or a static method (\ref{staticMethods}) that is not qualified by a defer red prefix. 2179 \item A simple or qualified identifier denoting a top-level function (\ref{funct ions}) or a static method (\ref{staticMethods}) that is not qualified by a defer red prefix.
2413 \item A parenthesized expression \code{($e$)} where $e$ is a constant expression . 2180 \item A parenthesized expression \code{($e$)} where $e$ is a constant expression .
2414 \item An expression of the form \code{identical($e_1$, $e_2$)} where $e_1$ and $ e_2$ are constant expressions and \code{identical()} is statically bound to the predefined dart function \code{identical()} discussed above (\ref{objectIdent ity}). 2181 \item An expression of the form \code{identical($e_1$, $e_2$)} where $e_1$ and $ e_2$ are constant expressions and \code{identical()} is statically bound to the predefined dart function \code{identical()} discussed above (\ref{objectIdent ity}).
2415 \item An expression of one of the forms \code{$e_1$ == $e_2$} or \code{$e_1$ ! = $e_2$} where $e_1$ and $e_2$ are constant expressions that evaluate to a numer ic, string or boolean value or to \NULL{}. 2182 \item An expression of one of the forms \code{$e_1$ == $e_2$} or \code{$e_1$ ! = $e_2$} where $e_1$ and $e_2$ are constant expressions that evaluate to a numer ic, string or boolean value or to \NULL{}.
2416 \item An expression of one of the forms \code{!$e$}, \code{$e_1$ \&\& $e_2$} or \code{$e_1 || e_2$}, where $e$, $e_1$ and $e_2$ are constant expressions that e valuate to a boolean value. 2183 \item An expression of one of the forms \code{!$e$}, \code{$e_1$ \&\& $e_2$} or \code{$e_1 || e_2$}, where $e$, $e_1$ and $e_2$ are constant expressions that e valuate to a boolean value.
2417 \item An expression of one of the forms \~{}$e$, $e_1$ \^{} $e_2$, \code{$e_1$ \ & $e_2$}, $e_1 | e_2$, $e_1 >> e_2$ or $e_1 << e_2$, where $e$, $e_1$ and $e_2 $ are constant expressions that evaluate to an integer value or to \NULL{}. 2184 \item An expression of one of the forms \~{}$e$, $e_1$ \^{} $e_2$, \code{$e_1$ \ & $e_2$}, $e_1 | e_2$, $e_1 >> e_2$ or $e_1 << e_2$, where $e$, $e_1$ and $e_2 $ are constant expressions that evaluate to an integer 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{}. 2185 \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{}.
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{}. 2186 \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{}.
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. 2187 \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.
2421 \item An expression of the form \code{$e$.length} where $e$ is a constant expres sion that evaluates to a string value. 2188 \item An expression of the form \code{$e$.length} where $e$ is a constant expres sion that evaluates to a string value.
2422 \end{itemize} 2189 \end{itemize}
2423 2190
2424 % null in all the expressions 2191 % null in all the expressions
2425 2192
2426 % designed so constants do not depend on check diode being on or not. 2193 % designed so constants do not depend on check diode being on or not.
2427 2194
2428 \LMHash{}
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. 2195 It is a compile-time error if an expression is required to be a constant express ion but its evaluation would raise an exception.
2430 2196
2431 % so, checked mode? analyzers? editor/development compilers? 2197 % so, checked mode? analyzers? editor/development compilers?
2432 \commentary{ 2198 \commentary{
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. 2199 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.
2434 2200
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. 2201 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.
2436 2202
2437 On the other hand, since implementations are free to compile code late, some com pile-time errors may manifest quite late. 2203 On the other hand, since implementations are free to compile code late, some com pile-time errors may manifest quite late.
2438 } 2204 }
(...skipping 22 matching lines...) Expand all
2461 } 2227 }
2462 2228
2463 \rationale{ 2229 \rationale{
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: 2230 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:
2465 \begin{enumerate} 2231 \begin{enumerate}
2466 \item It is constant. We can evaluate it at compile-time. 2232 \item It is constant. We can evaluate it at compile-time.
2467 \item It seems more useful to give the error stemming from the evaluation explic itly. 2233 \item It seems more useful to give the error stemming from the evaluation explic itly.
2468 \end{enumerate} 2234 \end{enumerate}
2469 } 2235 }
2470 2236
2471 \LMHash{}
2472 It is a compile-time error if the value of a compile-time constant expression de pends on itself. 2237 It is a compile-time error if the value of a compile-time constant expression de pends on itself.
2473 2238
2474 \commentary{ 2239 \commentary{
2475 As an example, consider: 2240 As an example, consider:
2476 } 2241 }
2477 2242
2478 \begin{dartCode} 2243 \begin{dartCode}
2479 \CLASS{} CircularConsts\{ 2244 \CLASS{} CircularConsts\{
2480 // Illegal program - mutually recursive compile-time constants 2245 // Illegal program - mutually recursive compile-time constants
2481 \STATIC{} \CONST{} i = j; // a compile-time constant 2246 \STATIC{} \CONST{} i = j; // a compile-time constant
2482 \STATIC{} \CONST{} j = i; // a compile-time constant 2247 \STATIC{} \CONST{} j = i; // a compile-time constant
2483 \} 2248 \}
2484 \end{dartCode} 2249 \end{dartCode}
2485 2250
2486 2251
2487 \begin{grammar} 2252 \begin{grammar}
2488 {\bf literal:}nullLiteral; 2253 {\bf literal:}nullLiteral;
2489 booleanLiteral; 2254 booleanLiteral;
2490 numericLiteral; 2255 numericLiteral;
2491 stringLiteral; 2256 stringLiteral;
2492 symbolLiteral; 2257 symbolLiteral;
2493 mapLiteral; 2258 mapLiteral;
2494 listLiteral 2259 listLiteral
2495 . 2260 .
2496 \end{grammar} 2261 \end{grammar}
2497 2262
2498 2263
2499 2264
2500 \subsection{Null} 2265 \subsection{Null}
2501 \LMLabel{null} 2266 \label{null}
2502 2267
2503 \LMHash{}
2504 The reserved word \NULL{} denotes the {\em null object}. 2268 The reserved word \NULL{} denotes the {\em null object}.
2505 %\Q{Any methods, such as \code{isNull}?} 2269 %\Q{Any methods, such as \code{isNull}?}
2506 2270
2507 \begin{grammar} 2271 \begin{grammar}
2508 {\bf nullLiteral:} 2272 {\bf nullLiteral:}
2509 \NULL{} 2273 \NULL{}
2510 . 2274 .
2511 \end{grammar} 2275 \end{grammar}
2512 2276
2513 \LMHash{}
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}. 2277 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}.
2515 Invoking a method on \NULL{} yields a \code{NoSuchMethodError} unless the metho d is explicitly implemented by class \code{Null}. 2278 Invoking a method on \NULL{} yields a \code{NoSuchMethodError} unless the metho d is explicitly implemented by class \code{Null}.
2516 2279
2517 \LMHash{}
2518 The static type of \NULL{} is $\bot$. 2280 The static type of \NULL{} is $\bot$.
2519 2281
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. 2282 \rationale{The decision to use $\bot$ instead of \code{Null} allows \NULL{} to b e be assigned everywhere without complaint by the static checker.
2521 } 2283 }
2522 2284
2523 2285
2524 \subsection{Numbers} 2286 \subsection{Numbers}
2525 \LMLabel{numbers} 2287 \label{numbers}
2526 2288
2527 \LMHash{}
2528 A {\em numeric literal} is either a decimal or hexadecimal integer of arbitrary size, or a decimal double. 2289 A {\em numeric literal} is either a decimal or hexadecimal integer of arbitrary size, or a decimal double.
2529 2290
2530 \begin{grammar} 2291 \begin{grammar}
2531 {\bf numericLiteral:}NUMBER; 2292 {\bf numericLiteral:}NUMBER;
2532 HEX\_NUMBER 2293 HEX\_NUMBER
2533 . 2294 .
2534 2295
2535 {\bf NUMBER:} DIGIT+ (`{\escapegrammar.}' DIGIT+)? EXPONENT?; 2296 {\bf NUMBER:} DIGIT+ (`{\escapegrammar.}' DIGIT+)? EXPONENT?;
2536 {`\escapegrammar .}' DIGIT+ EXPONENT? 2297 {`\escapegrammar .}' DIGIT+ EXPONENT?
2537 . 2298 .
2538 2299
2539 {\bf EXPONENT:} 2300 {\bf EXPONENT:}
2540 (`e' $|$ `E') ('+' $|$ `-`)? DIGIT+ 2301 (`e' $|$ `E') ('+' $|$ `-`)? DIGIT+
2541 . 2302 .
2542 2303
2543 {\bf HEX\_NUMBER:}`0x' HEX\_DIGIT+; 2304 {\bf HEX\_NUMBER:}`0x' HEX\_DIGIT+;
2544 `0X' HEX\_DIGIT+ 2305 `0X' HEX\_DIGIT+
2545 . 2306 .
2546 2307
2547 {\bf HEX\_DIGIT:}`a'{\escapegrammar ..}'f'; 2308 {\bf HEX\_DIGIT:}`a'{\escapegrammar ..}'f';
2548 `A'{\escapegrammar ..}'F'; 2309 `A'{\escapegrammar ..}'F';
2549 DIGIT 2310 DIGIT
2550 . 2311 .
2551 \end{grammar} 2312 \end{grammar}
2552 2313
2553 \LMHash{}
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. 2314 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.
2555 2315
2556 \LMHash{}
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. 2316 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.
2558 2317
2559 \commentary{ 2318 \commentary{
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. 2319 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.
2561 } 2320 }
2562 2321
2563 \LMHash{}
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}. 2322 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}.
2565 2323
2566 \LMHash{}
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}. 2324 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}.
2568 2325
2569 \LMHash{}
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}. 2326 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}.
2571 The static type of a literal double is \code{double}. 2327 The static type of a literal double is \code{double}.
2572 2328
2573 \subsection{Booleans} 2329 \subsection{Booleans}
2574 \LMLabel{booleans} 2330 \label{booleans}
2575 2331
2576 \LMHash{}
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}. 2332 The reserved words \TRUE{} and \FALSE{} denote objects that represent the boolea n values true and false respectively. They are the {\em boolean literals}.
2578 2333
2579 \begin{grammar} 2334 \begin{grammar}
2580 {\bf booleanLiteral:}\TRUE{}; 2335 {\bf booleanLiteral:}\TRUE{};
2581 \FALSE{} 2336 \FALSE{}
2582 . 2337 .
2583 \end{grammar} 2338 \end{grammar}
2584 2339
2585 \LMHash{}
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}. 2340 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}.
2587 2341
2588 \commentary{ 2342 \commentary{
2589 It follows that the two boolean literals are the only two instances of \code{boo l}. 2343 It follows that the two boolean literals are the only two instances of \code{boo l}.
2590 } 2344 }
2591 2345
2592 \LMHash{}
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}. 2346 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}.
2594 2347
2595 \subsubsection{Boolean Conversion} 2348 \subsubsection{Boolean Conversion}
2596 \LMLabel{booleanConversion} 2349 \label{booleanConversion}
2597 2350
2598 \LMHash{}
2599 {\em Boolean conversion} maps any object $o$ into a boolean. Boolean conversion is defined by the function application 2351 {\em Boolean conversion} maps any object $o$ into a boolean. Boolean conversion is defined by the function application
2600 2352
2601 \begin{dartCode} 2353 \begin{dartCode}
2602 (bool v)\{ 2354 (bool v)\{
2603 \ASSERT{}(v != \NULL{}); 2355 \ASSERT{}(v != \NULL{});
2604 % \IF{} (\NULL{} == v) \{ \THROW{} \NEW{} AssertionError('null is not a bo ol')\}; 2356 % \IF{} (\NULL{} == v) \{ \THROW{} \NEW{} AssertionError('null is not a bo ol')\};
2605 \RETURN{} identical(v, \TRUE{}); 2357 \RETURN{} identical(v, \TRUE{});
2606 \}(o) 2358 \}(o)
2607 \end{dartCode} 2359 \end{dartCode}
2608 2360
2609 \rationale{ 2361 \rationale{
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. 2362 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.
2611 2363
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. 2364 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.
2613 2365
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). 2366 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).
2615 } 2367 }
2616 2368
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. 2369 \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.
2618 } 2370 }
2619 2371
2620 \subsection{Strings} 2372 \subsection{Strings}
2621 \LMLabel{strings} 2373 \label{strings}
2622 2374
2623 \LMHash{}
2624 A {\em string} is a sequence of UTF-16 code units. 2375 A {\em string} is a sequence of UTF-16 code units.
2625 2376
2626 \rationale{ 2377 \rationale{
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. 2378 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.
2628 } 2379 }
2629 2380
2630 \begin{grammar} 2381 \begin{grammar}
2631 {\bf stringLiteral:}(multilineString $|$ singleLineString)+ 2382 {\bf stringLiteral:}(multilineString $|$ singleLineString)+
2632 . 2383 .
2633 \end{grammar} 2384 \end{grammar}
2634 2385
2635 \LMHash{}
2636 A string can be either a sequence of single line strings or a multiline string. 2386 A string can be either a sequence of single line strings or a multiline string.
2637 2387
2638 \begin{grammar} 2388 \begin{grammar}
2639 {\bf singleLineString:}`{\escapegrammar \code{"}}' stringContentDQ* `{\escapegr ammar \code{"}}'; 2389 {\bf singleLineString:}`{\escapegrammar \code{"}}' stringContentDQ* `{\escapegr ammar \code{"}}';
2640 `{\escapegrammar \code{'}}' stringContentSQ* `{\escapegrammar \code{'}}'; 2390 `{\escapegrammar \code{'}}' stringContentSQ* `{\escapegrammar \code{'}}';
2641 `r' `{\escapegrammar \code{'}}' (\~{}( `{\escapegrammar \code{'}}' $|$ NEW LINE ))* `{\escapegrammar \code{'}}'; 2391 `r' `{\escapegrammar \code{'}}' (\~{}( `{\escapegrammar \code{'}}' $|$ NEW LINE ))* `{\escapegrammar \code{'}}';
2642 `r' `{\escapegrammar \code{"}}' (\~{}( `{\escapegrammar \code{"}}' $|$ NEW LINE ))* `{\escapegrammar \code{"}}' 2392 `r' `{\escapegrammar \code{"}}' (\~{}( `{\escapegrammar \code{"}}' $|$ NEW LINE ))* `{\escapegrammar \code{"}}'
2643 . 2393 .
2644 \end{grammar} 2394 \end{grammar}
2645 2395
2646 \LMHash{}
2647 A single line string is delimited by either matching single quotes or matching d ouble quotes. 2396 A single line string is delimited by either matching single quotes or matching d ouble quotes.
2648 2397
2649 \commentary{ 2398 \commentary{
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''. 2399 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''.
2651 } 2400 }
2652 2401
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. 2402 \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.
2654 } 2403 }
2655 2404
2656 \LMHash{}
2657 Adjacent 2405 Adjacent
2658 %single line 2406 %single line
2659 strings are implicitly concatenated to form a single string literal. 2407 strings are implicitly concatenated to form a single string literal.
2660 %, and so are adjacent multiline strings, but the two forms may not be mixed. 2408 %, and so are adjacent multiline strings, but the two forms may not be mixed.
2661 2409
2662 2410
2663 \commentary{Here is an example} 2411 \commentary{Here is an example}
2664 2412
2665 \begin{dartCode} 2413 \begin{dartCode}
2666 print("A string" "and then another"); // prints: A stringand then another 2414 print("A string" "and then another"); // prints: A stringand then another
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2719 `$\backslash$ u' HEX\_DIGIT HEX\_DIGIT HEX\_DIGIT HEX\_DIGIT; 2467 `$\backslash$ u' HEX\_DIGIT HEX\_DIGIT HEX\_DIGIT HEX\_DIGIT;
2720 `$\backslash$ u\{' HEX\_DIGIT\_SEQUENCE `\}' 2468 `$\backslash$ u\{' HEX\_DIGIT\_SEQUENCE `\}'
2721 . 2469 .
2722 2470
2723 {\bf HEX\_DIGIT\_SEQUENCE:} 2471 {\bf HEX\_DIGIT\_SEQUENCE:}
2724 HEX\_DIGIT HEX\_DIGIT? HEX\_DIGIT? HEX\_DIGIT? HEX\_DIGIT? HEX\_DIGIT? 2472 HEX\_DIGIT HEX\_DIGIT? HEX\_DIGIT? HEX\_DIGIT? HEX\_DIGIT? HEX\_DIGIT?
2725 . 2473 .
2726 2474
2727 \end{grammar} 2475 \end{grammar}
2728 2476
2729 \LMHash{}
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. 2477 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.
2731 2478
2732 2479
2733 \rationale{ 2480 \rationale{
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. 2481 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.
2735 } 2482 }
2736 2483
2737 \LMHash{}
2738 Strings support escape sequences for special characters. The escapes are: 2484 Strings support escape sequences for special characters. The escapes are:
2739 \begin{itemize} 2485 \begin{itemize}
2740 \item $\backslash$n for newline, equivalent to $\backslash$x0A. 2486 \item $\backslash$n for newline, equivalent to $\backslash$x0A.
2741 \item $\backslash$r for carriage return, equivalent to $\backslash$x0D. 2487 \item $\backslash$r for carriage return, equivalent to $\backslash$x0D.
2742 \item $\backslash$f for form feed, equivalent to $\backslash$x0C. 2488 \item $\backslash$f for form feed, equivalent to $\backslash$x0C.
2743 \item $\backslash$b for backspace, equivalent to $\backslash$x08. 2489 \item $\backslash$b for backspace, equivalent to $\backslash$x08.
2744 \item $\backslash$t for tab, equivalent to $\backslash$x09. 2490 \item $\backslash$t for tab, equivalent to $\backslash$x09.
2745 \item $\backslash$v for vertical tab, equivalent to $\backslash$x0B 2491 \item $\backslash$v for vertical tab, equivalent to $\backslash$x0B
2746 \item $\backslash$x $HEX\_DIGIT_1$ $HEX\_DIGIT_2$, equivalent to 2492 \item $\backslash$x $HEX\_DIGIT_1$ $HEX\_DIGIT_2$, equivalent to
2747 2493
2748 $\backslash$u\{$HEX\_DIGIT_1$ $HEX\_DIGIT_2$\}. 2494 $\backslash$u\{$HEX\_DIGIT_1$ $HEX\_DIGIT_2$\}.
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$\}. 2495 \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$\}.
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. 2496 \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.
2751 \item \$ indicating the beginning of an interpolated expression. 2497 \item \$ indicating the beginning of an interpolated expression.
2752 \item Otherwise, $\backslash k$ indicates the character $k$ for any $k$ not in $ \{n, r, f, b, t, v, x, u\}$. 2498 \item Otherwise, $\backslash k$ indicates the character $k$ for any $k$ not in $ \{n, r, f, b, t, v, x, u\}$.
2753 \end{itemize} 2499 \end{itemize}
2754 2500
2755 \LMHash{}
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. 2501 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.
2757 2502
2758 \LMHash{}
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. 2503 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.
2760 2504
2761 2505
2762 2506
2763 \begin{grammar} 2507 \begin{grammar}
2764 {\bf stringContentDQ:}\~{}( `$\backslash$' $|$ `{\escapegrammar \texttt{"}}' $| $ `\$' $|$ NEWLINE ); 2508 {\bf stringContentDQ:}\~{}( `$\backslash$' $|$ `{\escapegrammar \texttt{"}}' $| $ `\$' $|$ NEWLINE );
2765 `$\backslash$' \~{}( NEWLINE ); 2509 `$\backslash$' \~{}( NEWLINE );
2766 stringInterpolation 2510 stringInterpolation
2767 . 2511 .
2768 2512
(...skipping 10 matching lines...) Expand all
2779 {\bf stringContentTSQ:}\~{}( `$\backslash$' $|$ `{\escapegrammar \code{'}\code{ '}\code{'}}' $|$ `\$'); 2523 {\bf stringContentTSQ:}\~{}( `$\backslash$' $|$ `{\escapegrammar \code{'}\code{ '}\code{'}}' $|$ `\$');
2780 stringInterpolation 2524 stringInterpolation
2781 . 2525 .
2782 2526
2783 {\bf NEWLINE:}$\backslash$ n; 2527 {\bf NEWLINE:}$\backslash$ n;
2784 $\backslash$ r 2528 $\backslash$ r
2785 . 2529 .
2786 2530
2787 \end{grammar} 2531 \end{grammar}
2788 2532
2789 \LMHash{}
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}. 2533 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}.
2791 2534
2792 \subsubsection{String Interpolation} 2535 \subsubsection{String Interpolation}
2793 \LMLabel{stringInterpolation} 2536 \label{stringInterpolation}
2794 2537
2795 \LMHash{}
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}. 2538 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}.
2797 2539
2798 \begin{grammar} 2540 \begin{grammar}
2799 {\bf stringInterpolation:}`\$' IDENTIFIER\_NO\_DOLLAR; 2541 {\bf stringInterpolation:}`\$' IDENTIFIER\_NO\_DOLLAR;
2800 `\$' `\{' expression `\}' % could be top level expression, no? 2542 `\$' `\{' expression `\}' % could be top level expression, no?
2801 . 2543 .
2802 \end{grammar} 2544 \end{grammar}
2803 2545
2804 \commentary{The reader will note that the expression inside the interpolation co uld itself include strings, which could again be interpolated recursively. 2546 \commentary{The reader will note that the expression inside the interpolation co uld itself include strings, which could again be interpolated recursively.
2805 } 2547 }
2806 2548
2807 \LMHash{}
2808 An unescaped \$ character in a string signifies the beginning of an interpolated expression. The \$ sign may be followed by either: 2549 An unescaped \$ character in a string signifies the beginning of an interpolated expression. The \$ sign may be followed by either:
2809 \begin{itemize} 2550 \begin{itemize}
2810 \item A single identifier $id$ that must not contain the \$ character. 2551 \item A single identifier $id$ that must not contain the \$ character.
2811 \item An expression $e$ delimited by curly braces. 2552 \item An expression $e$ delimited by curly braces.
2812 \end{itemize} 2553 \end{itemize}
2813 2554
2814 \LMHash{}
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$'' }. 2555 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$'' }.
2816 2556
2817 \subsection{Symbols} 2557 \subsection{Symbols}
2818 \LMLabel{symbols} 2558 \label{symbols}
2819 2559
2820 \LMHash{}
2821 A {\em symbol literal} denotes the name of a declaration in a Dart program. 2560 A {\em symbol literal} denotes the name of a declaration in a Dart program.
2822 2561
2823 \begin{grammar} 2562 \begin{grammar}
2824 {\bf symbolLiteral:} 2563 {\bf symbolLiteral:}
2825 `\#' (operator $|$ (identifier (`{\escapegrammar .}' identifier)*)) . 2564 `\#' (operator $|$ (identifier (`{\escapegrammar .}' identifier)*)) .
2826 \end{grammar} 2565 \end{grammar}
2827 2566
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')}. 2567 A symbol literal \code{\#id} where \code{id} does not begin with an underscore ( '\code{\_}') is equivalent to the expression \code{\CONST{} Symbol('id')}.
2830 2568
2831 \LMHash{} 2569 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.
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.
2833 2570
2834 \rationale{ 2571 \rationale{
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. 2572 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.
2836 2573
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. 2574 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 would fail. Therefore, Dart reflection us es objects of type \code{Symbol} rather than strings. Instances of \code{Symbol } are guaranteed to be stable with repeat to minification. Providing a literal f orm for symbols makes reflective code easier to read and write. The fact that sy mbols are easy to type and can often act as convenient substitutes for enums are secondary benefits.
2838 } 2575 }
2839 2576
2840 \LMHash{}
2841 The static type of a symbol literal is \code{Symbol}. 2577 The static type of a symbol literal is \code{Symbol}.
2842 2578
2843 \subsection{Lists} 2579 \subsection{Lists}
2844 \LMLabel{lists} 2580 \label{lists}
2845 2581
2846 \LMHash{}
2847 A {\em list literal} denotes a list, which is an integer indexed collection of o bjects. 2582 A {\em list literal} denotes a list, which is an integer indexed collection of o bjects.
2848 2583
2849 \begin{grammar} 2584 \begin{grammar}
2850 {\bf listLiteral:} 2585 {\bf listLiteral:}
2851 \CONST{}? typeArguments? `[' (expressionList `,'?)? `]' 2586 \CONST{}? typeArguments? `[' (expressionList `,'?)? `]'
2852 . 2587 .
2853 \end{grammar} 2588 \end{grammar}
2854 2589
2855 \LMHash{}
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. 2590 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.
2857 2591
2858 2592
2859 \LMHash{}
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 2593 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
2861 after they are created. Attempting to mutate a constant list literal will result in a dynamic error. 2594 after they are created. Attempting to mutate a constant list literal will result in a dynamic error.
2862 2595
2863 \LMHash{}
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. 2596 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.
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.} 2597 \rationale{The binding of a type parameter is not known at compile-time, so we c annot use type parameters inside compile-time constants.}
2866 2598
2867 \LMHash{}
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]$. 2599 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]$.
2869 2600
2870 \LMHash{}
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$)}. 2601 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$)}.
2872 2602
2873 \commentary{In other words, constant list literals are canonicalized.} 2603 \commentary{In other words, constant list literals are canonicalized.}
2874 2604
2875 \LMHash{}
2876 A run-time list literal $<E>[e_1 \ldots e_n]$ is evaluated as follows: 2605 A run-time list literal $<E>[e_1 \ldots e_n]$ is evaluated as follows:
2877 \begin{itemize} 2606 \begin{itemize}
2878 \item 2607 \item
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$. 2608 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$.
2880 \item A fresh instance (\ref{generativeConstructors}) $a$, of size $n$, whose class implements the built-in class $List<E>$ is allocated. 2609 \item A fresh instance (\ref{generativeConstructors}) $a$, of size $n$, whose class implements the built-in class $List<E>$ is allocated.
2881 \item 2610 \item
2611
2882 The operator \code{[]=} is invoked on $a$ with first argument $i$ and second a rgument 2612 The operator \code{[]=} is invoked on $a$ with first argument $i$ and second a rgument
2883 %The $i$th element of $a$ is set to 2613 %The $i$th element of $a$ is set to
2884 $o_{i+1}, 0 \le i < n$. 2614 $o_{i+1}, 0 \le i < n$.
2885 \item 2615 \item
2886 The result of the evaluation is $a$. 2616 The result of the evaluation is $a$.
2887 \end{itemize} 2617 \end{itemize}
2888 2618
2889 2619
2890 \commentary{ 2620 \commentary{
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}$. 2621 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}$.
2892 } 2622 }
2893 2623
2894 \LMHash{}
2895 A runtime list literal $[e_1 \ldots e_n]$ is evaluated as $< \DYNAMIC{}>[e_1\l dots e_n]$. 2624 A runtime list literal $[e_1 \ldots e_n]$ is evaluated as $< \DYNAMIC{}>[e_1\l dots e_n]$.
2896 2625
2897 2626
2898 \commentary{ 2627 \commentary{
2899 There is no restriction precluding nesting of list literals. It follows from the rules above that 2628 There is no restriction precluding nesting of list literals. It follows from the rules above that
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{}. 2629 $<List<int>>[[1, 2, 3], [4, 5, 6]]$ is a list with type parameter $List<int>$, c ontaining two lists with type parameter \DYNAMIC{}.
2901 } 2630 }
2902 2631
2903 \LMHash{}
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{}>$. 2632 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{}>$.
2905 2633
2906 \rationale{ 2634 \rationale{
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{}. 2635 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{}.
2908 } 2636 }
2909 2637
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}. 2638 %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}.
2911 % what about generics? 2639 % what about generics?
2912 2640
2913 \subsection{Maps} 2641 \subsection{Maps}
2914 \LMLabel{maps} 2642 \label{maps}
2915 2643
2916 \LMHash{}
2917 A {\em map literal} denotes a map object. 2644 A {\em map literal} denotes a map object.
2918 2645
2919 \begin{grammar} 2646 \begin{grammar}
2920 {\bf mapLiteral:} 2647 {\bf mapLiteral:}
2921 \CONST{}? typeArguments? `\{' (mapLiteralEntry (`,' mapLiteralEntry)* `,' ?)? `\}' 2648 \CONST{}? typeArguments? `\{' (mapLiteralEntry (`,' mapLiteralEntry)* `,' ?)? `\}'
2922 . 2649 .
2923 2650
2924 {\bf mapLiteralEntry:} 2651 {\bf mapLiteralEntry:}
2925 % identifier `{\escapegrammar :}' expression; 2652 % identifier `{\escapegrammar :}' expression;
2926 expression `{\escapegrammar :}' expression 2653 expression `{\escapegrammar :}' expression
2927 . 2654 .
2928 \end{grammar} 2655 \end{grammar}
2929 2656
2930 \LMHash{}
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. 2657 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.
2932 2658
2933 \LMHash{}
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 2659 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
2935 after they are created. Attempting to mutate a constant map literal will result in a dynamic error. 2660 after they are created. Attempting to mutate a constant map literal will result in a dynamic error.
2936 2661
2937 \LMHash{}
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 2662 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
2939 %symbol, 2663 %symbol,
2940 string, an integer, a literal symbol or the result of invoking a constant constr uctor of class \cd{Symbol}. 2664 string, an integer, a literal symbol or the result of invoking a constant constr uctor of class \cd{Symbol}.
2941 It is a compile-time error if the type arguments of a constant map literal inclu de a type parameter. 2665 It is a compile-time error if the type arguments of a constant map literal inclu de a type parameter.
2942 2666
2943 \LMHash{}
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\}$. 2667 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\}$.
2945 2668
2946 \LMHash{}
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$)}. 2669 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$)}.
2948 2670
2949 \commentary{In other words, constant map literals are canonicalized.} 2671 \commentary{In other words, constant map literals are canonicalized.}
2950 2672
2951 \LMHash{}
2952 A runtime map literal $<K, V>\{k_1:e_1\ldots k_n :e_n\}$ is evaluated as follow s: 2673 A runtime map literal $<K, V>\{k_1:e_1\ldots k_n :e_n\}$ is evaluated as follow s:
2953 \begin{itemize} 2674 \begin{itemize}
2954 \item 2675 \item
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$. 2676 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$.
2956 \item A fresh instance (\ref{generativeConstructors}) $m$ whose class implement s the built-in class 2677 \item A fresh instance (\ref{generativeConstructors}) $m$ whose class implement s the built-in class
2957 2678
2958 $Map<K, V>$ is allocated. 2679 $Map<K, V>$ is allocated.
2959 \item 2680 \item
2960 The operator \code{[]=} is invoked on $m$ with first argument $u_i$ and second argument $o_i, i \in 1.. n$. 2681 The operator \code{[]=} is invoked on $m$ with first argument $u_i$ and second argument $o_i, i \in 1.. n$.
2961 \item 2682 \item
2962 The result of the evaluation is $m$. 2683 The result of the evaluation is $m$.
2963 \end{itemize} 2684 \end{itemize}
2964 2685
2965 2686
2966 \LMHash{}
2967 A runtime map literal $\{k_1:e_1\ldots k_n :e_n\}$ is evaluated as 2687 A runtime map literal $\{k_1:e_1\ldots k_n :e_n\}$ is evaluated as
2968 2688
2969 $<\DYNAMIC{}, \DYNAMIC{}>\{k_1:e_1\ldots k_n :e_n\}$. 2689 $<\DYNAMIC{}, \DYNAMIC{}>\{k_1:e_1\ldots k_n :e_n\}$.
2970 2690
2971 \LMHash{}
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. 2691 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.
2973 2692
2974 \LMHash{}
2975 A map literal is ordered: iterating over the keys and/or values of the maps alwa ys happens in the 2693 A map literal is ordered: iterating over the keys and/or values of the maps alwa ys happens in the
2976 order the keys appeared in the source code. 2694 order the keys appeared in the source code.
2977 2695
2978 \commentary{ 2696 \commentary{
2979 Of course, if a key repeats, the order is defined by first occurrence, but the v alue is defined by the last. 2697 Of course, if a key repeats, the order is defined by first occurrence, but the v alue is defined by the last.
2980 } 2698 }
2981 2699
2982 \LMHash{}
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{}>$. 2700 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{}>$.
2984 2701
2985 2702
2986 \subsection{Throw} 2703 \subsection{Throw}
2987 \LMLabel{throw} 2704 \label{throw}
2988 2705
2989 \LMHash{}
2990 The {\em throw expression} is used to raise an exception. 2706 The {\em throw expression} is used to raise an exception.
2991 2707
2992 \begin{grammar} 2708 \begin{grammar}
2993 {\bf throwExpression:} 2709 {\bf throwExpression:}
2994 \THROW{} expression 2710 \THROW{} expression
2995 . 2711 .
2996 2712
2997 {\bf throwExpressionWithoutCascade:} 2713 {\bf throwExpressionWithoutCascade:}
2998 \THROW{} expressionWithoutCascade 2714 \THROW{} expressionWithoutCascade
2999 . 2715 .
3000 2716
3001 \end{grammar} 2717 \end{grammar}
3002 2718
3003 \LMHash{}
3004 The {\em current exception} is the last exception raised and not subsequently c aught at a given moment during runtime. 2719 The {\em current exception} is the last exception raised and not subsequently c aught at a given moment during runtime.
3005 2720
3006 \LMHash{}
3007 Evaluation of a throw expression of the form \code{\THROW{} $e$;} proceeds as follows: 2721 Evaluation of a throw expression of the form \code{\THROW{} $e$;} proceeds as follows:
3008 2722
3009 \LMHash{}
3010 The expression $e$ is evaluated yielding a value $v$. 2723 The expression $e$ is evaluated yielding a value $v$.
3011 2724
3012 \commentary{ 2725 \commentary{
3013 There is no requirement that the expression $e$ evaluate to a special kind of ex ception or error object. 2726 There is no requirement that the expression $e$ evaluate to a special kind of ex ception or error object.
3014 } 2727 }
3015 2728
3016 \LMHash{}
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. 2729 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.
3018 2730
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. 2731 \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.
3020 } 2732 }
3021 2733
3022 \LMHash{}
3023 Let $f$ be the immediately enclosing function. 2734 Let $f$ be the immediately enclosing function.
3024 2735
3025 \LMHash{}
3026 If $f$ is synchronous (\ref{functions}), control is transferred to the nearest d ynamically enclosing exception handler. 2736 If $f$ is synchronous (\ref{functions}), control is transferred to the nearest d ynamically enclosing exception handler.
3027 2737
3028 \commentary{ 2738 \commentary{
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. 2739 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.
3030 } 2740 }
3031 2741
3032 \LMHash{}
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. 2742 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.
3034 2743
3035 \rationale{ 2744 \rationale{
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. 2745 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.
3037 } 2746 }
3038 2747
3039 \LMHash{}
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. 2748 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.
3041 2749
3042 \LMHash{}
3043 The static type of a throw expression is $\bot$. 2750 The static type of a throw expression is $\bot$.
3044 2751
3045 2752
3046 \subsection{ Function Expressions} 2753 \subsection{ Function Expressions}
3047 \LMLabel{functionExpressions} 2754 \label{functionExpressions}
3048 2755
3049 \LMHash{}
3050 A {\em function literal} is an object that encapsulates an executable unit of co de. 2756 A {\em function literal} is an object that encapsulates an executable unit of co de.
3051 2757
3052 \begin{grammar} 2758 \begin{grammar}
3053 {\bf functionExpression:} 2759 {\bf functionExpression:}
3054 formalParameterList functionBody 2760 formalParameterList functionBody
3055 . 2761 .
3056 \end{grammar} 2762 \end{grammar}
3057 2763
3058 \LMHash{}
3059 The class of a function literal implements the built-in class \code{Function}. 2764 The class of a function literal implements the built-in class \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}. 2765 %Invoking the getter \code{runtimeType} on a function literal returns the \code{ Type} object that is the value of the expression \code{Function}.
3061 % not necessarily 2766 % not necessarily
3062 2767
3063 2768
3064 %Q{Can anyone implement it? Then we should define things via call} 2769 %Q{Can anyone implement it? Then we should define things via call}
3065 2770
3066 \LMHash{}
3067 The static type of a function literal of the form 2771 The static type of a function literal of the form
3068 2772
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$ 2773 $(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$
3070 is 2774 is
3071 2775
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$. 2776 $(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$.
3073 2777
3074 \LMHash{}
3075 The static type of a function literal of the form 2778 The static type of a function literal of the form
3076 2779
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$ 2780 $(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$
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$. 2781 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$.
3079 2782
3080 \LMHash{}
3081 The static type of a function literal of the form 2783 The static type of a function literal of the form
3082 2784
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$ 2785 $(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$
3084 is 2786 is
3085 2787
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$. 2788 $(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$.
3087 2789
3088 \LMHash{}
3089 The static type of a function literal of the form 2790 The static type of a function literal of the form
3090 2791
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$ 2792 $(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$
3092 2793
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$. 2794 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$.
3094 2795
3095 \LMHash{}
3096 The static type of a function literal of the form 2796 The static type of a function literal of the form
3097 2797
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\}$ 2798 $(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\}$
3099 2799
3100 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w \DYNAMIC{}$. 2800 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w \DYNAMIC{}$.
3101 2801
3102 \LMHash{}
3103 The static type of a function literal of the form 2802 The static type of a function literal of the form
3104 2803
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\}$ 2804 $(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\}$
3106 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Future$. 2805 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Future$.
3107 2806
3108 \LMHash{}
3109 The static type of a function literal of the form 2807 The static type of a function literal of the form
3110 2808
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\}$ 2809 $(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\}$
3112 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Stream$. 2810 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Stream$.
3113 2811
3114 \LMHash{}
3115 The static type of a function literal of the form 2812 The static type of a function literal of the form
3116 2813
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\}$ 2814 $(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\}$
3118 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Iterable$. 2815 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Iterable$.
3119 2816
3120 2817
3121 \LMHash{}
3122 The static type of a function literal of the form 2818 The static type of a function literal of the form
3123 2819
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\}$ 2820 $(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\}$
3125 2821
3126 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w \DYNAMIC{}$. 2822 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w \DYNAMIC{}$.
3127 2823
3128 2824
3129 \LMHash{}
3130 The static type of a function literal of the form 2825 The static type of a function literal of the form
3131 2826
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\}$ 2827 $(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\}$
3133 2828
3134 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar row Future{}$. 2829 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar row Future{}$.
3135 2830
3136 \LMHash{}
3137 The static type of a function literal of the form 2831 The static type of a function literal of the form
3138 2832
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\}$ 2833 $(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\}$
3140 2834
3141 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar row Stream{}$. 2835 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar row Stream{}$.
3142 2836
3143 \LMHash{}
3144 The static type of a function literal of the form 2837 The static type of a function literal of the form
3145 2838
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\}$ 2839 $(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\}$
3147 2840
3148 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar row Iterable{}$. 2841 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar row Iterable{}$.
3149 2842
3150 \LMHash{}
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{}. 2843 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{}.
3152 2844
3153 2845
3154 \subsection{ This} 2846 \subsection{ This}
3155 \LMLabel{this} 2847 \label{this}
3156 2848
3157 \LMHash{}
3158 The reserved word \THIS{} denotes the target of the current instance member invo cation. 2849 The reserved word \THIS{} denotes the target of the current instance member invo cation.
3159 2850
3160 \begin{grammar} 2851 \begin{grammar}
3161 {\bf thisExpression:} 2852 {\bf thisExpression:}
3162 \THIS{} 2853 \THIS{}
3163 . 2854 .
3164 \end{grammar} 2855 \end{grammar}
3165 2856
3166 \LMHash{}
3167 The static type of \THIS{} is the interface of the immediately enclosing class. 2857 The static type of \THIS{} is the interface of the immediately enclosing class.
3168 2858
3169 \commentary{ 2859 \commentary{
3170 We do not support self-types at this point. 2860 We do not support self-types at this point.
3171 } 2861 }
3172 2862
3173 \LMHash{}
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. 2863 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.
3175 2864
3176 \subsection{ Instance Creation} 2865 \subsection{ Instance Creation}
3177 \LMLabel{instanceCreation} 2866 \label{instanceCreation}
3178 2867
3179 \LMHash{}
3180 Instance creation expressions invoke constructors to produce instances. 2868 Instance creation expressions invoke constructors to produce instances.
3181 2869
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. 2870 %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.
3183 2871
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}). 2872 %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}).
3185 2873
3186 \LMHash{}
3187 It is a static type warning if 2874 It is a static type warning if
3188 the type $T$ in an instance creation expression of one of the forms 2875 the type $T$ in an instance creation expression of one of the forms
3189 2876
3190 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 2877 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
3191 2878
3192 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 2879 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
3193 2880
3194 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 2881 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
3195 2882
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}). 2883 \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}).
3197 2884
3198 \LMHash{}
3199 It is a compile-time error if the type $T$ in an instance creation expression of one of the forms 2885 It is a compile-time error if the type $T$ in an instance creation expression of one of the forms
3200 2886
3201 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 2887 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
3202 2888
3203 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 2889 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
3204 2890
3205 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 2891 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
3206 2892
3207 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 2893 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
3208 2894
3209 is an enumerated type (\ref{enums}). 2895 is an enumerated type (\ref{enums}).
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$. 2896 %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$.
3211 2897
3212 2898
3213 \subsubsection{ New} 2899 \subsubsection{ New}
3214 \LMLabel{new} 2900 \label{new}
3215 2901
3216 \LMHash{}
3217 The {\em new expression} invokes a constructor (\ref{constructors}). 2902 The {\em new expression} invokes a constructor (\ref{constructors}).
3218 2903
3219 \begin{grammar} 2904 \begin{grammar}
3220 {\bf newExpression:} 2905 {\bf newExpression:}
3221 \NEW{} type (`{\escapegrammar .}' identifier)? arguments 2906 \NEW{} type (`{\escapegrammar .}' identifier)? arguments
3222 . 2907 .
3223 \end{grammar} 2908 \end{grammar}
3224 2909
3225 \LMHash{}
3226 Let $e$ be a new expression of the form 2910 Let $e$ be a new expression of the form
3227 2911
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 2912 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ or the form
3229 2913
3230 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. 2914 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$.
3231 2915
3232 %It is a runtime type error if 2916 %It is a runtime type error if
3233 %the type $T$ is malformed. 2917 %the type $T$ is malformed.
3234 %It is a static warning if $T$ is a malformed type. 2918 %It is a static warning if $T$ is a malformed type.
3235 2919
3236 %not a class accessible in the current scope, optionally followed by type argum ents. 2920 %not a class accessible in the current scope, optionally followed by type argum ents.
3237 2921
3238 \LMHash{}
3239 If $T$ is a class or parameterized type accessible in the current scope then: 2922 If $T$ is a class or parameterized type accessible in the current scope then:
3240 \begin{itemize} 2923 \begin{itemize}
3241 \item 2924 \item
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$. 2925 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$.
3243 \end{itemize} 2926 \end{itemize}
3244 2927
3245 \LMHash{}
3246 If $T$ is a parameterized type (\ref{parameterizedTypes}) $S<U_1, \ldots, U_m>$ , let $R = S$. 2928 If $T$ is a parameterized type (\ref{parameterizedTypes}) $S<U_1, \ldots, U_m>$ , let $R = S$.
3247 %It is a 2929 %It is a
3248 %compile-time CHANGED 2930 %compile-time CHANGED
3249 %runtime type 2931 %runtime type
3250 %error if $S$ is not a generic (\ref{generics}) type with $m$ type parameters. 2932 %error if $S$ is not a generic (\ref{generics}) type with $m$ type parameters.
3251 If $T$ is not a parameterized type, let $R = T$. 2933 If $T$ is not a parameterized type, let $R = 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$. 2934 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$.
3253 2935
3254 \LMHash{}
3255 If $R$ is a generic with $l = m$ type parameters then 2936 If $R$ is a generic with $l = m$ type parameters then
3256 \begin{itemize} 2937 \begin{itemize}
3257 \item If $T$ is not a parameterized type, then for $ i \in 1 .. l$, let $V_i = \DYNAMIC{}$. 2938 \item If $T$ is not a parameterized type, then for $ i \in 1 .. l$, let $V_i = \DYNAMIC{}$.
3258 \item If $T$ is a parameterized type then let $V_i = U_i$ for $ i \in 1 .. m$. 2939 \item If $T$ is a parameterized type then let $V_i = U_i$ for $ i \in 1 .. m$.
3259 \end{itemize} 2940 \end{itemize}
3260 2941
3261 \LMHash{}
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$. 2942 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$.
3263 2943
3264 \LMHash{}
3265 Evaluation of $e$ proceeds as follows: 2944 Evaluation of $e$ proceeds as follows:
3266 2945
3267 \LMHash{}
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. 2946 First, the argument list $(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k} : a_{n+k})$ is evaluated.
3269 2947
3270 \LMHash{}
3271 If $T$ is a deferred type with prefix $p$, then if $p$ has not been successfully loaded, a dynamic error occurs. 2948 If $T$ is a deferred type with prefix $p$, then if $p$ has not been successfully loaded, a dynamic error occurs.
3272 2949
3273 \LMHash{}
3274 Then, if $q$ is a non-factory constructor of an abstract class then an \code{Abs tractClassInstantiationError} is thrown. 2950 Then, if $q$ is a non-factory constructor of an abstract class then an \code{Abs tractClassInstantiationError} is thrown.
3275 2951
3276 \LMHash{}
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. 2952 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.
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. 2953 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.
3279 2954
3280 \LMHash{}
3281 Otherwise, if $q$ is a generative constructor (\ref{generativeConstructors}), th en: 2955 Otherwise, if $q$ is a generative constructor (\ref{generativeConstructors}), th en:
3282 2956
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.} 2957 \commentary{Note that it this point we are assured that the number of actual typ e arguments match the number of formal type parameters.}
3284 2958
3285 \LMHash{}
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{}. 2959 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{}.
3287 2960
3288 \commentary{ 2961 \commentary{
3289 Observe that \THIS{} is not in scope in $e_f$. Hence, the initialization cannot depend on other properties of the object being instantiated. 2962 Observe that \THIS{} is not in scope in $e_f$. Hence, the initialization cannot depend on other properties of the object being instantiated.
3290 } 2963 }
3291 2964
3292 \LMHash{}
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$. 2965 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$.
3294 2966
3295 \LMHash{}
3296 Otherwise, $q$ is a factory constructor (\ref{factories}). Then: 2967 Otherwise, $q$ is a factory constructor (\ref{factories}). Then:
3297 2968
3298 \LMHash{}
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 2969 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
3300 2970
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. 2971 $[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.
3302 2972
3303 2973
3304 \LMHash{}
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$. 2974 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$.
3306 2975
3307 \LMHash{}
3308 It is a static warning if $q$ is a constructor of an abstract class and $q$ is n ot a factory constructor. 2976 It is a static warning if $q$ is a constructor of an abstract class and $q$ is n ot a factory constructor.
3309 2977
3310 \commentary{The above gives precise meaning to the idea that instantiating an ab stract class leads to a warning. 2978 \commentary{The above gives precise meaning to the idea that instantiating an ab stract class leads to a warning.
3311 A similar clause applies to constant object creation in the next section. 2979 A similar clause applies to constant object creation in the next section.
3312 } 2980 }
3313 2981
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. 2982 \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.
3315 } 2983 }
3316 2984
3317 \LMHash{}
3318 The static type of an instance creation expression of either the form 2985 The static type of an instance creation expression of either the form
3319 2986
3320 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 2987 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
3321 2988
3322 or the form 2989 or the form
3323 2990
3324 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 2991 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
3325 2992
3326 is $T$. 2993 is $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$). 2994 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$).
3328 2995
3329 2996
3330 2997
3331 \subsubsection{ Const} 2998 \subsubsection{ Const}
3332 \LMLabel{const} 2999 \label{const}
3333 3000
3334 \LMHash{}
3335 A {\em constant object expression} invokes a constant constructor (\ref{constant Constructors}). 3001 A {\em constant object expression} invokes a constant constructor (\ref{constant Constructors}).
3336 3002
3337 \begin{grammar} 3003 \begin{grammar}
3338 {\bf constObjectExpression:} 3004 {\bf constObjectExpression:}
3339 \CONST{} type ('{\escapegrammar .}' identifier)? arguments 3005 \CONST{} type ('{\escapegrammar .}' identifier)? arguments
3340 . 3006 .
3341 \end{grammar} 3007 \end{grammar}
3342 3008
3343 \LMHash{}
3344 Let $e$ be a constant object expression of the form 3009 Let $e$ be a constant object expression of the form
3345 3010
3346 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3011 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
3347 3012
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}). 3013 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}).
3349 3014
3350 \commentary{In particular, $T$ may not be a type variable.} 3015 \commentary{In particular, $T$ may not be a type variable.}
3351 3016
3352 \LMHash{}
3353 If $T$ is a parameterized type, it is a compile-time error if $T$ includes a typ e variable among its type arguments. 3017 If $T$ is a parameterized type, it is a compile-time error if $T$ includes a typ e variable among its type arguments.
3354 3018
3355 \LMHash{}
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$. 3019 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$.
3357 3020
3358 \LMHash{}
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. 3021 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.
3360 3022
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$. 3023 %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$.
3362 %Finally, 3024 %Finally,
3363 % If $T$ is a generic with $l$ retype parameters, then for all $ i \in 1 .. l$, let $V_i = \DYNAMIC{}$. 3025 % If $T$ is a generic with $l$ retype parameters, then for all $ i \in 1 .. l$, let $V_i = \DYNAMIC{}$.
3364 3026
3365 \LMHash{}
3366 Evaluation of $e$ proceeds as follows: 3027 Evaluation of $e$ proceeds as follows:
3367 3028
3368 \LMHash{}
3369 First, if $e$ is of the form 3029 First, if $e$ is of the form
3370 3030
3371 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3031 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
3372 3032
3373 then let $i$ be the value of the expression 3033 then let $i$ be the value of the expression
3374 3034
3375 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. 3035 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$.
3376 3036
3377 \LMHash{}
3378 Otherwise, $e$ must be of the form 3037 Otherwise, $e$ must be of the form
3379 3038
3380 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 3039 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
3381 3040
3382 in which case let $i$ be the result of evaluating 3041 in which case let $i$ be the result of evaluating
3383 3042
3384 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. 3043 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$.
3385 3044
3386 \LMHash{}
3387 Then: 3045 Then:
3388 \begin{itemize} 3046 \begin{itemize}
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: 3047 \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:
3390 \begin{itemize} 3048 \begin{itemize}
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$. 3049 \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$.
3392 \end{itemize} 3050 \end{itemize}
3393 \item Otherwise the value of $e$ is $i$. 3051 \item Otherwise the value of $e$ is $i$.
3394 \end{itemize} 3052 \end{itemize}
3395 3053
3396 \commentary{ 3054 \commentary{
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. 3055 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.
3398 } 3056 }
3399 3057
3400 \LMHash{}
3401 The static type of a constant object expression of either the form 3058 The static type of a constant object expression of either the form
3402 3059
3403 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3060 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
3404 3061
3405 or the form 3062 or the form
3406 3063
3407 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3064 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
3408 3065
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$). 3066 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$).
3410 3067
3411 \LMHash{}
3412 It is a compile-time error if evaluation of a constant object results in an unca ught exception being thrown. 3068 It is a compile-time error if evaluation of a constant object results in an unca ught exception being thrown.
3413 3069
3414 \commentary{ 3070 \commentary{
3415 To see how such situations might arise, consider the following examples: 3071 To see how such situations might arise, consider the following examples:
3416 } 3072 }
3417 3073
3418 \begin{dartCode} 3074 \begin{dartCode}
3419 \CLASS{} A \{ 3075 \CLASS{} A \{
3420 \FINAL{} x; 3076 \FINAL{} x;
3421 \CONST{} A(p): x = p * 10; 3077 \CONST{} A(p): x = p * 10;
(...skipping 11 matching lines...) Expand all
3433 \} 3089 \}
3434 3090
3435 \CONST{} A(\CONST{} IntPair(1,2)); // compile-time error: illegal in a subtler w ay 3091 \CONST{} A(\CONST{} IntPair(1,2)); // compile-time error: illegal in a subtler w ay
3436 \end{dartCode} 3092 \end{dartCode}
3437 3093
3438 \commentary{ 3094 \commentary{
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. 3095 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.
3440 } 3096 }
3441 3097
3442 3098
3443 \LMHash{}
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. 3099 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.
3445 3100
3446 3101
3447 \subsection{ Spawning an Isolate} 3102 \subsection{ Spawning an Isolate}
3448 \LMLabel{spawningAnIsolate} 3103 \label{spawningAnIsolate}
3449 3104
3450 \LMHash{}
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. 3105 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.
3452 3106
3453 \LMHash{}
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. 3107 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.
3455 3108
3456 \commentary{ 3109 \commentary{
3457 As discussed in section \ref{errorsAndWarnings}, the handling of a suspended iso late is the responsibility of the embedder. 3110 As discussed in section \ref{errorsAndWarnings}, the handling of a suspended iso late is the responsibility of the embedder.
3458 } 3111 }
3459 3112
3460 3113
3461 3114
3462 \subsection{ Function Invocation} 3115 \subsection{ Function Invocation}
3463 \LMLabel{functionInvocation} 3116 \label{functionInvocation}
3464 3117
3465 \LMHash{}
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. 3118 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.
3467 3119
3468 \LMHash{}
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. 3120 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.
3470 3121
3471 \LMHash{}
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: 3122 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:
3473 \begin{itemize} 3123 \begin{itemize}
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}). 3124 \item If the current return value is defined then, if $s$ has been canceled then its cancellation future is completed with \NULL{} (\ref{null}).
3475 \item If the current exception $x$ is defined: 3125 \item If the current exception $x$ is defined:
3476 \begin{itemize} 3126 \begin{itemize}
3477 \item $x$ is added to $s$. 3127 \item $x$ is added to $s$.
3478 \item If $s$ has been canceled then its cancellation future is completed with $x$ as an error. 3128 \item If $s$ has been canceled then its cancellation future is completed with $x$ as an error.
3479 \end{itemize} 3129 \end{itemize}
3480 \item $s$ is closed. 3130 \item $s$ is closed.
3481 \end{itemize} 3131 \end{itemize}
3482 3132
3483 \rationale{ 3133 \rationale{
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. 3134 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.
3485 } 3135 }
3486 3136
3487 \LMHash{}
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. 3137 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.
3489 3138
3490 \rationale{Such streams may be left open by for loops that were escaped when an exception was thrown within them for example. 3139 \rationale{Such streams may be left open by for loops that were escaped when an exception was thrown within them for example.
3491 } 3140 }
3492 3141
3493 \LMHash{}
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. 3142 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.
3495 3143
3496 \LMHash{}
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. 3144 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.
3498 3145
3499 3146
3500 \LMHash{}
3501 Execution of $f$ terminates when the first of the following occurs: 3147 Execution of $f$ terminates when the first of the following occurs:
3502 \begin{itemize} 3148 \begin{itemize}
3503 \item An exception is thrown and not caught within the current function activati on. 3149 \item An exception is thrown and not caught within the current function activati on.
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. 3150 \item A return statement (\ref{return}) immediately nested in the body of $f$ is executed and not intercepted in a \FINALLY{} (\ref{try}) clause.
3505 \item The last statement of the body completes execution. 3151 \item The last statement of the body completes execution.
3506 \end{itemize} 3152 \end{itemize}
3507 3153
3508 3154
3509 3155
3510 3156
3511 \subsubsection{ Actual Argument List Evaluation} 3157 \subsubsection{ Actual Argument List Evaluation}
3512 \LMLabel{actualArguments} 3158 \label{actualArguments}
3513 3159
3514 \LMHash{}
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. 3160 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.
3516 3161
3517 \begin{grammar} 3162 \begin{grammar}
3518 {\bf arguments:} 3163 {\bf arguments:}
3519 `(' argumentList? `)' 3164 `(' argumentList? `)'
3520 . 3165 .
3521 3166
3522 {\bf argumentList:}namedArgument (`,' namedArgument)*; 3167 {\bf argumentList:}namedArgument (`,' namedArgument)*;
3523 % expressionList ',' spreadArgument; 3168 % expressionList ',' spreadArgument;
3524 expressionList (`,' namedArgument)* 3169 expressionList (`,' namedArgument)*
3525 % spreadArgument 3170 % spreadArgument
3526 . 3171 .
3527 3172
3528 {\bf namedArgument:} 3173 {\bf namedArgument:}
3529 label expression % could be top level expression? 3174 label expression % could be top level expression?
3530 . 3175 .
3531 \end{grammar} 3176 \end{grammar}
3532 3177
3533 \LMHash{}
3534 Evaluation of an actual argument list of the form 3178 Evaluation of an actual argument list of the form
3535 3179
3536 $(a_1, \ldots, a_m, q_1: a_{m+1}, \ldots, q_l: a_{m+l})$ 3180 $(a_1, \ldots, a_m, q_1: a_{m+1}, \ldots, q_l: a_{m+l})$
3537 3181
3538 proceeds as follows: 3182 proceeds as follows:
3539 3183
3540 \LMHash{}
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}$. 3184 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}$.
3542 3185
3543 \commentary{Simply stated, an argument list consisting of $m$ positional argumen ts and $l$ named arguments is evaluated from left to right. 3186 \commentary{Simply stated, an argument list consisting of $m$ positional argumen ts and $l$ named arguments is evaluated from left to right.
3544 } 3187 }
3545 3188
3546 3189
3547 \subsubsection{ Binding Actuals to Formals} 3190 \subsubsection{ Binding Actuals to Formals}
3548 \LMLabel{bindingActualsToFormals} 3191 \label{bindingActualsToFormals}
3549 3192
3550 \LMHash{}
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$. 3193 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$.
3552 3194
3553 \LMHash{}
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: 3195 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:
3555 3196
3556 \commentary{ 3197 \commentary{
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. 3198 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.
3558 } 3199 }
3559 3200
3560 \commentary{ 3201 \commentary{
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. 3202 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.
3562 } 3203 }
3563 3204
3564 3205
3565 \LMHash{}
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. 3206 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.
3567 3207
3568 \commentary{All of these remaining parameters are necessarily optional and thus have default values.} 3208 \commentary{All of these remaining parameters are necessarily optional and thus have default values.}
3569 3209
3570 \LMHash{}
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$. 3210 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$.
3572 3211
3573 \LMHash{}
3574 It is a compile-time error if $q_i = q_j$ for any $i \ne j$. 3212 It is a compile-time error if $q_i = q_j$ for any $i \ne j$.
3575 3213
3576 \LMHash{}
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$. 3214 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$.
3578 3215
3579 \subsubsection{ Unqualified Invocation} 3216 \subsubsection{ Unqualified Invocation}
3580 \LMLabel{unqualifiedInvocation} 3217 \label{unqualifiedInvocation}
3581 3218
3582 \LMHash{}
3583 An unqualified function invocation $i$ has the form 3219 An unqualified function invocation $i$ has the form
3584 3220
3585 $id(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$, 3221 $id(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$,
3586 3222
3587 where $id$ is an identifier. 3223 where $id$ is an identifier.
3588 3224
3589 \LMHash{}
3590 If there exists a lexically visible declaration named $id$, let $f_{id}$ be the innermost such declaration. Then: 3225 If there exists a lexically visible declaration named $id$, let $f_{id}$ be the innermost such declaration. Then:
3591 \begin{itemize} 3226 \begin{itemize}
3592 \item 3227 \item
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}). 3228 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}).
3594 \item 3229 \item
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}) $. 3230 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}) $.
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}) $. 3231 \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}) $.
3597 \end{itemize} 3232 \end{itemize}
3598 3233
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})$. 3234 %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})$.
3600 3235
3601 %\rationale{ 3236 %\rationale{
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. 3237 %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.
3603 %} 3238 %}
3604 3239
3605 \LMHash{}
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. 3240 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.
3607 3241
3608 \LMHash{}
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})$. 3242 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})$.
3610 3243
3611 % Should also say: 3244 % Should also say:
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. 3245 % 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.
3613 3246
3614 3247
3615 3248
3616 3249
3617 3250
3618 \subsubsection{ Function Expression Invocation} 3251 \subsubsection{ Function Expression Invocation}
3619 \LMLabel{functionExpressionInvocation} 3252 \label{functionExpressionInvocation}
3620 3253
3621 \LMHash{}
3622 A function expression invocation $i$ has the form 3254 A function expression invocation $i$ has the form
3623 3255
3624 $e_f(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 3256 $e_f(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
3625 3257
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}). 3258 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}).
3627 3259
3628 \commentary{ 3260 \commentary{
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. 3261 \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.
3630 } 3262 }
3631 3263
3632 \LMHash{}
3633 Otherwise: 3264 Otherwise:
3634 3265
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})$. 3266 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})$.
3636 3267
3637 \commentary{ 3268 \commentary{
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. 3269 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.
3639 } 3270 }
3640 3271
3641 \LMHash{}
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 3272 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
3643 the static type of $i$ is the declared return type of $F$. 3273 the static type of $i$ is the declared return type of $F$.
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$. 3274 %\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$.
3645 %\end{itemize} 3275 %\end{itemize}
3646 3276
3647 \subsection{ Lookup} 3277 \subsection{ Lookup}
3648 3278
3649 \subsubsection{Method Lookup} 3279 \subsubsection{Method Lookup}
3650 \LMLabel{methodLookup} 3280 \label{methodLookup}
3651 3281
3652 \LMHash{}
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$. 3282 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$.
3654 3283
3655 \LMHash{}
3656 The result of a lookup of method $m$ in class $C$ with respect to library $L$ i s: 3284 The result of a lookup of method $m$ in class $C$ with respect to library $L$ i s:
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. 3285 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.
3658 3286
3659 \rationale { 3287 \rationale {
3660 The motivation for skipping abstract members during lookup is largely to allow s moother mixin composition. 3288 The motivation for skipping abstract members during lookup is largely to allow s moother mixin composition.
3661 } 3289 }
3662 3290
3663 3291
3664 \subsubsection{ Getter and Setter Lookup} 3292 \subsubsection{ Getter and Setter Lookup}
3665 \LMLabel{getterAndSetterLookup} 3293 \label{getterAndSetterLookup}
3666 3294
3667 \LMHash{}
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$. 3295 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$.
3669 3296
3670 \LMHash{}
3671 The result of a lookup of a getter (respectively setter) $m$ in class $C$ with respect to library $L$ is: 3297 The result of a lookup of a getter (respectively setter) $m$ in class $C$ with respect to library $L$ is:
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. 3298 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.
3673 3299
3674 \rationale { 3300 \rationale {
3675 The motivation for skipping abstract members during lookup is largely to allow s moother mixin composition. 3301 The motivation for skipping abstract members during lookup is largely to allow s moother mixin composition.
3676 } 3302 }
3677 3303
3678 3304
3679 \subsection{ Top level Getter Invocation} 3305 \subsection{ Top level Getter Invocation}
3680 \LMLabel{topLevelGetterInvocation} 3306 \label{topLevelGetterInvocation}
3681 3307
3682 \LMHash{}
3683 Evaluation of a top-level getter invocation $i$ of the form $m$, where $m$ is an identifier, proceeds as follows: 3308 Evaluation of a top-level getter invocation $i$ of the form $m$, where $m$ is an identifier, proceeds as follows:
3684 3309
3685 \LMHash{}
3686 The getter function $m$ is invoked. The value of $i$ is the result returned by t he call to the getter function. 3310 The getter function $m$ is invoked. The value of $i$ is the result returned by t he call to the getter function.
3687 \commentary{ 3311 \commentary{
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. 3312 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.
3689 } 3313 }
3690 3314
3691 \LMHash{}
3692 The static type of $i$ is the declared return type of $m$. 3315 The static type of $i$ is the declared return type of $m$.
3693 3316
3694 \subsection{ Method Invocation} 3317 \subsection{ Method Invocation}
3695 \LMLabel{methodInvocation} 3318 \label{methodInvocation}
3696 3319
3697 \LMHash{}
3698 Method invocation can take several forms as specified below. 3320 Method invocation can take several forms as specified below.
3699 3321
3700 \subsubsection{Ordinary Invocation} 3322 \subsubsection{Ordinary Invocation}
3701 \LMLabel{ordinaryInvocation} 3323 \label{ordinaryInvocation}
3702 3324
3703 \LMHash{}
3704 An ordinary method invocation $i$ has the form 3325 An ordinary method invocation $i$ has the form
3705 3326
3706 $o.m(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. 3327 $o.m(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$.
3707 3328
3708 \LMHash{}
3709 Evaluation of an ordinary method invocation $i$ of the form 3329 Evaluation of an ordinary method invocation $i$ of the form
3710 3330
3711 $o.m(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3331 $o.m(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
3712 3332
3713 proceeds as follows: 3333 proceeds as follows:
3714 3334
3715 \LMHash{}
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$. 3335 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$.
3717 3336
3718 \LMHash{}
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$. 3337 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$.
3720 3338
3721 \commentary{ 3339 \commentary{
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. 3340 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.
3723 } 3341 }
3724 3342
3725 \LMHash{}
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. 3343 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.
3727 3344
3728 \LMHash{}
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. 3345 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.
3730 3346
3731 \LMHash{}
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$. 3347 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$.
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. 3348 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.
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 3349 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
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}\}$. 3350 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}\}$.
3736 3351
3737 \LMHash{}
3738 If getter lookup has also failed, then a new instance $im$ of the predefined c lass \code{Invocation} is created, such that : 3352 If getter lookup has also failed, then a new instance $im$ of the predefined c lass \code{Invocation} is created, such that :
3739 \begin{itemize} 3353 \begin{itemize}
3740 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 3354 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
3741 \item \code{im.memberName} evaluates to \code{'m'}. 3355 \item \code{im.memberName} evaluates to \code{'m'}.
3742 \item \code{im.positionalArguments} evaluates to an immutable list with the same values as \code{[$o_1, \ldots, o_n$]}. 3356 \item \code{im.positionalArguments} evaluates to an immutable list with the same values as \code{[$o_1, \ldots, o_n$]}.
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}$\}}. 3357 \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}$\}}.
3744 \end{itemize} 3358 \end{itemize}
3745 3359
3746 \LMHash{}
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 : 3360 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 :
3748 \begin{itemize} 3361 \begin{itemize}
3749 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 3362 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
3750 \item \code{im.memberName} evaluates to \code{noSuchMethod'}. 3363 \item \code{im.memberName} evaluates to \code{noSuchMethod'}.
3751 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$. 3364 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$.
3752 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 3365 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3753 \end{itemize} 3366 \end{itemize}
3754 3367
3755 and the result of the latter invocation is the result of evaluating $i$. 3368 and the result of the latter invocation is the result of evaluating $i$.
3756 3369
3757 \rationale { 3370 \rationale {
3758 It is possible to bring about such a situation by overriding \code{noSuchMethod( )} with the wrong number of arguments:} 3371 It is possible to bring about such a situation by overriding \code{noSuchMethod( )} with the wrong number of arguments:}
3759 3372
3760 \begin{code} 3373 \begin{code}
3761 \CLASS{} Perverse \{ 3374 \CLASS{} Perverse \{
3762 noSuchMethod(x,y) =$>$ x + y; 3375 noSuchMethod(x,y) =$>$ x + y;
3763 \} 3376 \}
3764 3377
3765 \NEW{} Perverse.unknownMethod(); 3378 \NEW{} Perverse.unknownMethod();
3766 \end{code} 3379 \end{code}
3767 3380
3768 \commentary{Notice that the wording carefully avoids re-evaluating the receiver $o$ and the arguments $a_i$. } 3381 \commentary{Notice that the wording carefully avoids re-evaluating the receiver $o$ and the arguments $a_i$. }
3769 3382
3770 \LMHash{}
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: 3383 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:
3772 \begin{itemize} 3384 \begin{itemize}
3773 \item 3385 \item
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 3386 $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
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$. 3387 \item $T$ is \code{Type}, $e$ is a constant type literal and the class correspo nding to $e$ has a static getter named $m$.
3776 \end{itemize} 3388 \end{itemize}
3777 3389
3778 \LMHash{}
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$. 3390 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$.
3780 3391
3781 \LMHash{}
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 `.'. 3392 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 `.'.
3783 3393
3784 3394
3785 \subsubsection{Cascaded Invocations} 3395 \subsubsection{Cascaded Invocations}
3786 \LMLabel{cascadedInvocations} 3396 \label{cascadedInvocations}
3787 3397
3788 \LMHash{}
3789 A {\em cascaded method invocation} has the form {\em e..suffix} 3398 A {\em cascaded method invocation} has the form {\em e..suffix}
3790 where $e$ is an expression and {\em suffix} is a sequence of operator, method, g etter or setter invocations. 3399 where $e$ is an expression and {\em suffix} is a sequence of operator, method, g etter or setter invocations.
3791 3400
3792 \begin{grammar} 3401 \begin{grammar}
3793 {\bf cascadeSection:} 3402 {\bf cascadeSection:}
3794 `{\escapegrammar ..}' (cascadeSelector arguments*) (assignableSelector arg uments*)* (assignmentOperator expressionWithoutCascade)? 3403 `{\escapegrammar ..}' (cascadeSelector arguments*) (assignableSelector arg uments*)* (assignmentOperator expressionWithoutCascade)?
3795 . 3404 .
3796 3405
3797 {\bf cascadeSelector:}`[' expression `]'; 3406 {\bf cascadeSelector:}`[' expression `]';
3798 identifier 3407 identifier
3799 . 3408 .
3800 \end{grammar} 3409 \end{grammar}
3801 3410
3802 \LMHash{}
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$)}. 3411 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$)}.
3804 3412
3805 \subsubsection{Super Invocation} 3413 \subsubsection{Super Invocation}
3806 \LMLabel{superInvocation} 3414 \label{superInvocation}
3807 3415
3808 \LMHash{}
3809 A super method invocation $i$ has the form 3416 A super method invocation $i$ has the form
3810 3417
3811 $\SUPER{}.m(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. 3418 $\SUPER{}.m(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$.
3812 3419
3813 \LMHash{}
3814 Evaluation of $i$ proceeds as follows: 3420 Evaluation of $i$ proceeds as follows:
3815 3421
3816 \LMHash{}
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$. 3422 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$.
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$. 3423 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$.
3819 3424
3820 \LMHash{}
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. 3425 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.
3822 3426
3823 \LMHash{}
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. 3427 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.
3825 3428
3826 \LMHash{}
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 3429 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
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}\}$. 3430 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}\}$.
3829 3431
3830 \LMHash{}
3831 If getter lookup has also failed, then a new instance $im$ of the predefined c lass \code{Invocation} is created, such that : 3432 If getter lookup has also failed, then a new instance $im$ of the predefined c lass \code{Invocation} is created, such that :
3832 \begin{itemize} 3433 \begin{itemize}
3833 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 3434 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
3834 \item \code{im.memberName} evaluates to \code{'m'}. 3435 \item \code{im.memberName} evaluates to \code{'m'}.
3835 \item \code{im.positionalArguments} evaluates to an immutable list with the same values as \code{[$o_1, \ldots, o_n$]}. 3436 \item \code{im.positionalArguments} evaluates to an immutable list with the same values as \code{[$o_1, \ldots, o_n$]}.
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}$\}}. 3437 \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}$\}}.
3837 \end{itemize} 3438 \end{itemize}
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 : 3439 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 :
3839 \begin{itemize} 3440 \begin{itemize}
3840 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 3441 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
3841 \item \code{im.memberName} evaluates to \code{noSuchMethod}. 3442 \item \code{im.memberName} evaluates to \code{noSuchMethod}.
3842 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$. 3443 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$.
3843 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 3444 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3844 \end{itemize} 3445 \end{itemize}
3845 3446
3846 and the result of this latter invocation is the result of evaluating $i$. 3447 and the result of this latter invocation is the result of evaluating $i$.
3847 3448
3848 3449
3849 \LMHash{}
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. 3450 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.
3851 3451
3852 \LMHash{}
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$. 3452 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$.
3854 % The following is not needed because it is specified in 'Binding Actuals to For mals" 3453 % The following is not needed because it is specified in 'Binding Actuals to For mals"
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$. 3454 %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$.
3856 3455
3857 3456
3858 3457
3859 3458
3860 \subsubsection{Sending Messages} 3459 \subsubsection{Sending Messages}
3861 \LMLabel{sendingMessages}
3862 3460
3863 \LMHash{} 3461 \label{sendingMessages}
3462
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. 3463 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.
3865 3464
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. 3465 \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.
3867 } 3466 }
3868 3467
3869 3468
3870 3469
3871 \subsection{ Property Extraction} 3470 \subsection{ Property Extraction}
3872 \LMLabel{propertyExtraction} 3471 \label{propertyExtraction}
3873 3472
3874 \LMHash{}
3875 {\em Property extraction} allows for a member of an object to be concisely extra cted from the object. 3473 {\em Property extraction} allows for a member of an object to be concisely extra cted from the object.
3876 A property extraction can be either: 3474 A property extraction can be either:
3877 \begin{enumerate} 3475 \begin{enumerate}
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 3476 \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
3879 \item A {\em getter invocation} which returns the result of invoking of a getter method. 3477 \item A {\em getter invocation} which returns the result of invoking of a getter method.
3880 \end{enumerate} 3478 \end{enumerate}
3881 3479
3882 \LMHash{}
3883 Evaluation of a property extraction $i$ of the form $e.m$ proceeds as follows: 3480 Evaluation of a property extraction $i$ of the form $e.m$ proceeds as follows:
3884 3481
3885 \LMHash{}
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$. 3482 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$.
3887 3483
3888 \LMHash{}
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. 3484 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.
3890 3485
3891 \LMHash{}
3892 If the getter lookup has failed, then a new instance $im$ of the predefined cla ss \code{Invocation} is created, such that : 3486 If the getter lookup has failed, then a new instance $im$ of the predefined cla ss \code{Invocation} is created, such that :
3893 \begin{itemize} 3487 \begin{itemize}
3894 \item \code{im.isGetter} evaluates to \code{\TRUE{}}. 3488 \item \code{im.isGetter} evaluates to \code{\TRUE{}}.
3895 \item \code{im.memberName} evaluates to \code{'m'}. 3489 \item \code{im.memberName} evaluates to \code{'m'}.
3896 \item \code{im.positionalArguments} evaluates to the value of \code{\CONST{} []} . 3490 \item \code{im.positionalArguments} evaluates to the value of \code{\CONST{} []} .
3897 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 3491 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3898 \end{itemize} 3492 \end{itemize}
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 : 3493 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 :
3900 \begin{itemize} 3494 \begin{itemize}
3901 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 3495 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
3902 \item \code{im.memberName} evaluates to \code{noSuchMethod}. 3496 \item \code{im.memberName} evaluates to \code{noSuchMethod}.
3903 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$. 3497 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$.
3904 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 3498 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3905 \end{itemize} 3499 \end{itemize}
3906 3500
3907 and the result of this latter invocation is the result of evaluating $i$. 3501 and the result of this latter invocation is the result of evaluating $i$.
3908 3502
3909 \LMHash{}
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. 3503 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.
3911 3504
3912 \commentary { 3505 \commentary {
3913 This precludes \code{int.toString} but not \code{(int).toString} because in the latter case, $e$ is a parenthesized expression. 3506 This precludes \code{int.toString} but not \code{(int).toString} because in the latter case, $e$ is a parenthesized expression.
3914 } 3507 }
3915 3508
3916 \LMHash{}
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: 3509 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:
3918 \begin{itemize} 3510 \begin{itemize}
3919 \item 3511 \item
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 3512 $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
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$. 3513 \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$.
3922 \end{itemize} 3514 \end{itemize}
3923 3515
3924 \LMHash{}
3925 If $i$ is a getter invocation, the static type of $i$ is: 3516 If $i$ is a getter invocation, the static type of $i$ is:
3926 \begin{itemize} 3517 \begin{itemize}
3927 \item The declared return type of $T.m$, if $T.m$ exists. 3518 \item The declared return type of $T.m$, if $T.m$ exists.
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$. 3519 \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$.
3929 \item The type \DYNAMIC{} otherwise. 3520 \item The type \DYNAMIC{} otherwise.
3930 \end{itemize} 3521 \end{itemize}
3931 3522
3932 \LMHash{}
3933 If $i$ is a closurization, its static type is as described in section \ref{closu rization}. 3523 If $i$ is a closurization, its static type is as described in section \ref{closu rization}.
3934 3524
3935 \LMHash{}
3936 Evaluation of a property extraction $i$ of the form $\SUPER.m$ proceeds as follo ws: 3525 Evaluation of a property extraction $i$ of the form $\SUPER.m$ proceeds as follo ws:
3937 3526
3938 \LMHash{}
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}). 3527 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}).
3940 3528
3941 \LMHash{}
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. 3529 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.
3943 3530
3944 \LMHash{}
3945 If the getter lookup has failed, then a new instance $im$ of the predefined cla ss \code{Invocation} is created, such that : 3531 If the getter lookup has failed, then a new instance $im$ of the predefined cla ss \code{Invocation} is created, such that :
3946 \begin{itemize} 3532 \begin{itemize}
3947 \item \code{im.isGetter} evaluates to \code{\TRUE{}}. 3533 \item \code{im.isGetter} evaluates to \code{\TRUE{}}.
3948 \item \code{im.memberName} evaluates to \code{'m'}. 3534 \item \code{im.memberName} evaluates to \code{'m'}.
3949 \item \code{im.positionalArguments} evaluates to the value of \code{\CONST{} []} . 3535 \item \code{im.positionalArguments} evaluates to the value of \code{\CONST{} []} .
3950 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 3536 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3951 \end{itemize} 3537 \end{itemize}
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 : 3538 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 :
3953 \begin{itemize} 3539 \begin{itemize}
3954 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 3540 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
3955 \item \code{im.memberName} evaluates to \code{noSuchMethod}. 3541 \item \code{im.memberName} evaluates to \code{noSuchMethod}.
3956 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$. 3542 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$.
3957 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 3543 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3958 \end{itemize} 3544 \end{itemize}
3959 3545
3960 and the result of this latter invocation is the result of evaluating $i$. 3546 and the result of this latter invocation is the result of evaluating $i$.
3961 3547
3962 \LMHash{}
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}. 3548 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}.
3964 3549
3965 3550
3966 \subsubsection{Closurization} 3551 \subsubsection{Closurization}
3967 \LMLabel{closurization} 3552 \label{closurization}
3968 3553
3969 \LMHash{}
3970 The {\em closurization of $o.m$} is defined to be equivalent to: 3554 The {\em closurization of $o.m$} is defined to be equivalent to:
3971 3555
3972 \begin{itemize} 3556 \begin{itemize}
3973 3557
3974 \item 3558 \item
3975 \begin{dartCode} 3559 \begin{dartCode}
3976 $(r_1, \ldots, r_n, \{p_1 : d_1, \ldots , p_k : d_k\})$ \{ 3560 $(r_1, \ldots, r_n, \{p_1 : d_1, \ldots , p_k : d_k\})$ \{
3977 \RETURN{} $ u.m(r_1, \ldots, r_n, p_1: p_1, \ldots, p_k: p_k);$ 3561 \RETURN{} $ u.m(r_1, \ldots, r_n, p_1: p_1, \ldots, p_k: p_k);$
3978 \} 3562 \}
3979 \end{dartCode} 3563 \end{dartCode}
(...skipping 29 matching lines...) Expand all
4009 3593
4010 \commentary{Observations: 3594 \commentary{Observations:
4011 \begin{enumerate} 3595 \begin{enumerate}
4012 \item One cannot closurize a getter or a setter. 3596 \item One cannot closurize a getter or a setter.
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. 3597 \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.
4014 \end{enumerate} 3598 \end{enumerate}
4015 } 3599 }
4016 3600
4017 3601
4018 3602
4019 \LMHash{}
4020 The closurization of $\SUPER{}.m$ with respect to superclass $S$ is defined to b e equivalent to: 3603 The closurization of $\SUPER{}.m$ with respect to superclass $S$ is defined to b e equivalent to:
4021 3604
4022 \begin{itemize} 3605 \begin{itemize}
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$. 3606 %\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$.
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$. 3607 %\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$.
4025 %\item 3608 %\item
4026 \item 3609 \item
4027 \begin{dartCode} 3610 \begin{dartCode}
4028 $(r_1, \ldots, r_n, \{p_1 : d_1, \ldots , p_k : d_k\})$\{ 3611 $(r_1, \ldots, r_n, \{p_1 : d_1, \ldots , p_k : d_k\})$\{
4029 \RETURN{} \SUPER{}$.m(r_1, \ldots, r_n, p_1: p_1, \ldots, p_k: p_k)$; 3612 \RETURN{} \SUPER{}$.m(r_1, \ldots, r_n, p_1: p_1, \ldots, p_k: p_k)$;
4030 \} 3613 \}
4031 \end{dartCode} 3614 \end{dartCode}
4032 3615
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$. 3616 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$.
4034 \item 3617 \item
4035 \begin{dartCode} 3618 \begin{dartCode}
4036 $(r_1, \ldots, r_n, [p_1 = d_1, \ldots , p_k = d_k])$\{ 3619 $(r_1, \ldots, r_n, [p_1 = d_1, \ldots , p_k = d_k])$\{
4037 \RETURN{} \SUPER{}$.m(r_1, \ldots, r_n, p_1, \ldots, p_k)$; 3620 \RETURN{} \SUPER{}$.m(r_1, \ldots, r_n, p_1, \ldots, p_k)$;
4038 \} 3621 \}
4039 \end{dartCode} 3622 \end{dartCode}
4040 3623
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$. 3624 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$.
4042 \end{itemize} 3625 \end{itemize}
4043 3626
4044 \LMHash{}
4045 Except that: 3627 Except that:
4046 \begin{enumerate} 3628 \begin{enumerate}
4047 \item iff \code{identical($o_1, o_2$)} then \cd{$o_1.m$ == $o_2.m$}. 3629 \item iff \code{identical($o_1, o_2$)} then \cd{$o_1.m$ == $o_2.m$}.
4048 \item 3630 \item
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{} . 3631 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{} .
4050 \end{enumerate} 3632 \end{enumerate}
4051 3633
4052 3634
4053 \subsection{ Assignment} 3635 \subsection{ Assignment}
4054 \LMLabel{assignment} 3636 \label{assignment}
4055 3637
4056 \LMHash{}
4057 An assignment changes the value associated with a mutable variable or property. 3638 An assignment changes the value associated with a mutable variable or property.
4058 3639
4059 \begin{grammar} 3640 \begin{grammar}
4060 {\bf assignmentOperator:}`=' ; 3641 {\bf assignmentOperator:}`=' ;
4061 compoundAssignmentOperator 3642 compoundAssignmentOperator
4062 . 3643 .
4063 \end{grammar} 3644 \end{grammar}
4064 3645
4065 \LMHash{}
4066 Evaluation of an assignment $a$ of the form $v$ \code{=} $e$ proceeds as follows : 3646 Evaluation of an assignment $a$ of the form $v$ \code{=} $e$ proceeds as follows :
4067 3647
4068 3648
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: 3649 %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:
4070 %\begin{itemize} 3650 %\begin{itemize}
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. 3651 % \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.
4072 % \item Otherwise, the assignment is equivalent to the assignment \code{ \THIS{} .$v$ = $e$}. 3652 % \item Otherwise, the assignment is equivalent to the assignment \code{ \THIS{} .$v$ = $e$}.
4073 % \end{itemize} 3653 % \end{itemize}
4074 3654
4075 %Otherwise, 3655 %Otherwise,
4076 3656
4077 \LMHash{}
4078 Let $d$ be the innermost declaration whose name is $v$ or $v=$, if it exists. 3657 Let $d$ be the innermost declaration whose name is $v$ or $v=$, if it exists.
4079 3658
4080 \LMHash{}
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. 3659 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.
4082 If no error occurs, the value of the assignment expression is $o$. 3660 If no error occurs, the value of the assignment expression is $o$.
4083 3661
4084 \LMHash{}
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$. 3662 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$.
4086 3663
4087 \LMHash{}
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$}. 3664 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$}.
4089 3665
4090 \LMHash{}
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. 3666 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.
4092 3667
4093 \LMHash{}
4094 Otherwise, the assignment is equivalent to the assignment \code{ \THIS{}.$v$ = $ e$}. 3668 Otherwise, the assignment is equivalent to the assignment \code{ \THIS{}.$v$ = $ e$}.
4095 3669
4096 \LMHash{}
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$. 3670 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$.
4098 3671
4099 \LMHash{}
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$. 3672 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$.
4101 3673
4102 \LMHash{}
4103 Evaluation of an assignment of the form $e_1.v$ \code{=} $e_2$ proceeds as follo ws: 3674 Evaluation of an assignment of the form $e_1.v$ \code{=} $e_2$ proceeds as follo ws:
4104 3675
4105 \LMHash{}
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$. 3676 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$.
4107 3677
4108 \LMHash{}
4109 If the setter lookup has failed, then a new instance $im$ of the predefined cla ss \code{Invocation} is created, such that : 3678 If the setter lookup has failed, then a new instance $im$ of the predefined cla ss \code{Invocation} is created, such that :
4110 \begin{itemize} 3679 \begin{itemize}
4111 \item \code{im.isSetter} evaluates to \code{\TRUE{}}. 3680 \item \code{im.isSetter} evaluates to \code{\TRUE{}}.
4112 \item \code{im.memberName} evaluates to \code{'v='}. 3681 \item \code{im.memberName} evaluates to \code{'v='}.
4113 \item \code{im.positionalArguments} evaluates to an immutable list with the same values as \code{[$o_2$]}. 3682 \item \code{im.positionalArguments} evaluates to an immutable list with the same values as \code{[$o_2$]}.
4114 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 3683 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
4115 \end{itemize} 3684 \end{itemize}
4116 3685
4117 \LMHash{}
4118 Then the method \code{noSuchMethod()} is looked up in $o_1$ and invoked with ar gument $im$. 3686 Then the method \code{noSuchMethod()} is looked up in $o_1$ and invoked with ar gument $im$.
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 : 3687 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 :
4120 \begin{itemize} 3688 \begin{itemize}
4121 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 3689 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
4122 \item \code{im.memberName} evaluates to \code{noSuchMethod}. 3690 \item \code{im.memberName} evaluates to \code{noSuchMethod}.
4123 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$. 3691 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$.
4124 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 3692 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
4125 \end{itemize} 3693 \end{itemize}
4126 3694
4127 \LMHash{}
4128 The value of the assignment expression is $o_2$ irrespective of whether setter l ookup has failed or succeeded. 3695 The value of the assignment expression is $o_2$ irrespective of whether setter l ookup has failed or succeeded.
4129 3696
4130 \LMHash{}
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$. 3697 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$.
4132 3698
4133 \LMHash{}
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: 3699 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:
4135 \begin{itemize} 3700 \begin{itemize}
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 3701 \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
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=$. 3702 \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=$.
4138 \end{itemize} 3703 \end{itemize}
4139 3704
4140 3705
4141 3706
4142 \LMHash{}
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$. 3707 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$.
4144 3708
4145 \LMHash{}
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$. 3709 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$.
4147 3710
4148 % Should we add: It is a dynamic error if $e_1$ evaluates to an constant list o r map. 3711 % Should we add: It is a dynamic error if $e_1$ evaluates to an constant list o r map.
4149 3712
4150 \LMHash{}
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. 3713 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.
4152 3714
4153 \LMHash{}
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 `.'. 3715 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 `.'.
4155 3716
4156 3717
4157 3718
4158 \subsubsection{Compound Assignment} 3719 \subsubsection{Compound Assignment}
4159 \LMLabel{compoundAssignment} 3720 \label{compoundAssignment}
4160 3721
4161 \LMHash{}
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 3722 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
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$. 3723 \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$.
4164 3724
4165 3725
4166 \begin{grammar} 3726 \begin{grammar}
4167 {\bf compoundAssignmentOperator:}`*='; 3727 {\bf compoundAssignmentOperator:}`*=';
4168 `/='; 3728 `/=';
4169 `\~{}/='; 3729 `\~{}/=';
4170 `\%='; 3730 `\%=';
4171 `+='; 3731 `+=';
4172 `-='; 3732 `-=';
4173 `{\escapegrammar \lt \lt}='; 3733 `{\escapegrammar \lt \lt}=';
4174 `{\escapegrammar \gt \gt}='; 3734 `{\escapegrammar \gt \gt}=';
4175 `\&='; 3735 `\&=';
4176 `\^{}='; 3736 `\^{}=';
4177 `$|$=' 3737 `$|$='
4178 . 3738 .
4179 \end{grammar} 3739 \end{grammar}
4180 3740
4181 3741
4182 \subsection{ Conditional} 3742 \subsection{ Conditional}
4183 \LMLabel{conditional} 3743 \label{conditional}
4184 3744
4185 \LMHash{}
4186 A {\em conditional expression} evaluates one of two expressions based on a boole an condition. 3745 A {\em conditional expression} evaluates one of two expressions based on a boole an condition.
4187 3746
4188 \begin{grammar} 3747 \begin{grammar}
4189 {\bf conditionalExpression:} 3748 {\bf conditionalExpression:}
4190 logicalOrExpression (`?' expressionWithoutCascade `{\escapegrammar :}' expr essionWithoutCascade)? 3749 logicalOrExpression (`?' expressionWithoutCascade `{\escapegrammar :}' expr essionWithoutCascade)?
4191 . % the first branches could top level expressions, it seems, but certainl y NOT the second 3750 . % the first branches could top level expressions, it seems, but certainl y NOT the second
4192 \end{grammar} 3751 \end{grammar}
4193 3752
4194 \LMHash{}
4195 Evaluation of a conditional expression $c$ of the form $e_1 ? e_2 : e_3$ proceed s as follows: 3753 Evaluation of a conditional expression $c$ of the form $e_1 ? e_2 : e_3$ proceed s as follows:
4196 3754
4197 \LMHash{}
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$. 3755 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$.
4199 3756
4200 \LMHash{}
4201 If all of the following hold: 3757 If all of the following hold:
4202 \begin{itemize} 3758 \begin{itemize}
4203 \item $e_1$ shows that a variable $v$ has type $T$. 3759 \item $e_1$ shows that a variable $v$ has type $T$.
4204 \item $v$ is not potentially mutated in $e_2$ or within a closure. 3760 \item $v$ is not potentially mutated in $e_2$ or within a closure.
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$. 3761 \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$.
4206 \end{itemize} 3762 \end{itemize}
4207 3763
4208 then the type of $v$ is known to be $T$ in $e_2$. 3764 then the type of $v$ is known to be $T$ in $e_2$.
4209 3765
4210 3766
4211 \LMHash{}
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$. 3767 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$.
4213 3768
4214 3769
4215 \subsection{ Logical Boolean Expressions} 3770 \subsection{ Logical Boolean Expressions}
4216 \LMLabel{logicalBooleanExpressions} 3771 \label{logicalBooleanExpressions}
4217 3772
4218 \LMHash{}
4219 The logical boolean expressions combine boolean objects using the boolean conjun ction and disjunction operators. 3773 The logical boolean expressions combine boolean objects using the boolean conjun ction and disjunction operators.
4220 3774
4221 \begin{grammar} 3775 \begin{grammar}
4222 {\bf logicalOrExpression:} 3776 {\bf logicalOrExpression:}
4223 logicalAndExpression (`$||$' logicalAndExpression)* 3777 logicalAndExpression (`$||$' logicalAndExpression)*
4224 . 3778 .
4225 3779
4226 3780
4227 {\bf logicalAndExpression:} 3781 {\bf logicalAndExpression:}
4228 equalityExpression (`\&\&' equalityExpression)* 3782 equalityExpression (`\&\&' equalityExpression)*
4229 % bitwiseOrExpression (`\&\&' bitwiseOrExpression)* 3783 % bitwiseOrExpression (`\&\&' bitwiseOrExpression)*
4230 . 3784 .
4231 \end{grammar} 3785 \end{grammar}
4232 3786
4233 \LMHash{}
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$. 3787 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$.
4235 3788
4236 \LMHash{}
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$. 3789 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$.
4238 3790
4239 \LMHash{}
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$. 3791 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$.
4241 3792
4242 \LMHash{}
4243 A logical boolean expression $b$ of the form $e_1 \&\& e_2$ shows that a variabl e $v$ has type 3793 A logical boolean expression $b$ of the form $e_1 \&\& e_2$ shows that a variabl e $v$ has type
4244 $T$ if all of the following conditions hold: 3794 $T$ if all of the following conditions hold:
4245 \begin{itemize} 3795 \begin{itemize}
4246 \item Either $e_1$ shows that $v$ has type $T$ or $e_2$ shows that $v$ has type $T$. 3796 \item Either $e_1$ shows that $v$ has type $T$ or $e_2$ shows that $v$ has type $T$.
4247 \item $v$ is a local variable or formal parameter. 3797 \item $v$ is a local variable or formal parameter.
4248 \item The variable $v$ is not mutated in $e_2$ or within a closure. 3798 \item The variable $v$ is not mutated in $e_2$ or within a closure.
4249 \end{itemize} 3799 \end{itemize}
4250 3800
4251 \LMHash{}
4252 Furthermore, if all of the following hold: 3801 Furthermore, if all of the following hold:
4253 \begin{itemize} 3802 \begin{itemize}
4254 \item $e_1$ shows that $v$ has type $T$. 3803 \item $e_1$ shows that $v$ has type $T$.
4255 \item $v$ is not mutated in either $e_1$, $e_2$ or within a closure. 3804 \item $v$ is not mutated in either $e_1$, $e_2$ or within a closure.
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$. 3805 \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$.
4257 \end{itemize} 3806 \end{itemize}
4258 then the type of $v$ is known to be $T$ in $e_2$. 3807 then the type of $v$ is known to be $T$ in $e_2$.
4259 3808
4260 \LMHash{}
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}. 3809 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}.
4262 3810
4263 3811
4264 \subsection{ Equality} 3812 \subsection{ Equality}
4265 \LMLabel{equality} 3813 \label{equality}
4266 3814
4267 \LMHash{}
4268 Equality expressions test objects for equality. 3815 Equality expressions test objects for equality.
4269 3816
4270 \begin{grammar} 3817 \begin{grammar}
4271 {\bf equalityExpression:}relationalExpression (equalityOperator relationalExpres sion)?; 3818 {\bf equalityExpression:}relationalExpression (equalityOperator relationalExpres sion)?;
4272 \SUPER{} equalityOperator relationalExpression 3819 \SUPER{} equalityOperator relationalExpression
4273 . 3820 .
4274 3821
4275 {\bf equalityOperator:}`=='; 3822 {\bf equalityOperator:}`==';
4276 `!=' 3823 `!='
4277 . 3824 .
4278 \end{grammar} 3825 \end{grammar}
4279 3826
4280 \LMHash{}
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$. 3827 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$.
4282 3828
4283 3829
4284 \LMHash{}
4285 Evaluation of an equality expression $ee$ of the form \code{$e_1$ == $e_2$} proc eeds as follows: 3830 Evaluation of an equality expression $ee$ of the form \code{$e_1$ == $e_2$} proc eeds as follows:
4286 \begin{itemize} 3831 \begin{itemize}
4287 \item The expression $e_1$ is evaluated to an object $o_1$. 3832 \item The expression $e_1$ is evaluated to an object $o_1$.
4288 \item The expression $e_2$ is evaluated to an object $o_2$. 3833 \item The expression $e_2$ is evaluated to an object $o_2$.
4289 \item If either $o_1$ or $o_2$ is \NULL{}, then $ee$ evaluates to \code{identica l($o_1$, $o_2$)}. Otherwise, 3834 \item If either $o_1$ or $o_2$ is \NULL{}, then $ee$ evaluates to \code{identica l($o_1$, $o_2$)}. Otherwise,
4290 \item $ee$ is equivalent to the method invocation \code{$o_1$.==($o_2$)}. 3835 \item $ee$ is equivalent to the method invocation \code{$o_1$.==($o_2$)}.
4291 \end{itemize} 3836 \end{itemize}
4292 3837
4293 3838
4294 \LMHash{}
4295 Evaluation of an equality expression $ee$ of the form \code{\SUPER{} == $e$} pro ceeds as follows: 3839 Evaluation of an equality expression $ee$ of the form \code{\SUPER{} == $e$} pro ceeds as follows:
4296 \begin{itemize} 3840 \begin{itemize}
4297 \item The expression $e$ is evaluated to an object $o$. 3841 \item The expression $e$ is evaluated to an object $o$.
4298 \item If either \THIS{} or $o$ is \NULL{}, then $ee$ evaluates to \code{identica l(\THIS{}, $o$)}. Otherwise, 3842 \item If either \THIS{} or $o$ is \NULL{}, then $ee$ evaluates to \code{identica l(\THIS{}, $o$)}. Otherwise,
4299 \item $ee$ is equivalent to the method invocation \code{\SUPER{}.==($o$)}. 3843 \item $ee$ is equivalent to the method invocation \code{\SUPER{}.==($o$)}.
4300 \end{itemize} 3844 \end{itemize}
4301 3845
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: 3846 \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:
4303 3847
4304 \code{if (identical(\NULL{}, arg)) return \FALSE{};} 3848 \code{if (identical(\NULL{}, arg)) return \FALSE{};}
4305 3849
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{}. 3850 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{}.
4307 } 3851 }
4308 3852
4309 \LMHash{}
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$)}. 3853 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$)}.
4311 3854
4312 3855
4313 3856
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{}. 3857 %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{}.
4315 3858
4316 3859
4317 \LMHash{}
4318 The static type of an equality expression is \code{bool}. 3860 The static type of an equality expression is \code{bool}.
4319 3861
4320 3862
4321 \subsection{ Relational Expressions} 3863 \subsection{ Relational Expressions}
4322 \LMLabel{relationalExpressions} 3864 \label{relationalExpressions}
4323 3865
4324 \LMHash{}
4325 Relational expressions invoke the relational operators on objects. 3866 Relational expressions invoke the relational operators on objects.
4326 3867
4327 \begin{grammar} 3868 \begin{grammar}
4328 {\bf relationalExpression:}bitwiseOrExpression (typeTest $|$ typeCast $|$ relat ionalOperator bitwiseOrExpression)?; 3869 {\bf relationalExpression:}bitwiseOrExpression (typeTest $|$ typeCast $|$ relat ionalOperator bitwiseOrExpression)?;
4329 \SUPER{} relationalOperator bitwiseOrExpression 3870 \SUPER{} relationalOperator bitwiseOrExpression
4330 . 3871 .
4331 3872
4332 3873
4333 {\bf relationalOperator:}`{\escapegrammar \gt=}'; 3874 {\bf relationalOperator:}`{\escapegrammar \gt=}';
4334 `{\escapegrammar \gt}'; 3875 `{\escapegrammar \gt}';
4335 `{\escapegrammar \lt}='; 3876 `{\escapegrammar \lt}=';
4336 `{\escapegrammar \lt}' 3877 `{\escapegrammar \lt}'
4337 . 3878 .
4338 \end{grammar} 3879 \end{grammar}
4339 3880
4340 \LMHash{}
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$. 3881 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$.
4342 3882
4343 \LMHash{}
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$ )}. 3883 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$ )}.
4345 3884
4346 \subsection{ Bitwise Expressions} 3885 \subsection{ Bitwise Expressions}
4347 \LMLabel{bitwiseExpressions} 3886 \label{bitwiseExpressions}
4348 3887
4349 \LMHash{}
4350 Bitwise expressions invoke the bitwise operators on objects. 3888 Bitwise expressions invoke the bitwise operators on objects.
4351 3889
4352 \begin{grammar} 3890 \begin{grammar}
4353 {\bf bitwiseOrExpression:}bitwiseXorExpression (`$|$' bitwiseXorExpression)*; 3891 {\bf bitwiseOrExpression:}bitwiseXorExpression (`$|$' bitwiseXorExpression)*;
4354 \SUPER{} (`$|$' bitwiseXorExpression)+ 3892 \SUPER{} (`$|$' bitwiseXorExpression)+
4355 . 3893 .
4356 3894
4357 {\bf bitwiseXorExpression:}bitwiseAndExpression (`\^{}' bitwiseAndExpression)*; 3895 {\bf bitwiseXorExpression:}bitwiseAndExpression (`\^{}' bitwiseAndExpression)*;
4358 \SUPER{} (`\^{}' bitwiseAndExpression)+ 3896 \SUPER{} (`\^{}' bitwiseAndExpression)+
4359 . 3897 .
4360 3898
4361 {\bf bitwiseAndExpression:}shiftExpression (`\&' shiftExpression)*; 3899 {\bf bitwiseAndExpression:}shiftExpression (`\&' shiftExpression)*;
4362 \SUPER{} (`\&' shiftExpression)+ 3900 \SUPER{} (`\&' shiftExpression)+
4363 . 3901 .
4364 3902
4365 {\bf bitwiseOperator:}`\&'; 3903 {\bf bitwiseOperator:}`\&';
4366 `\^{}'; 3904 `\^{}';
4367 `$|$' 3905 `$|$'
4368 . 3906 .
4369 \end{grammar} 3907 \end{grammar}
4370 3908
4371 \LMHash{}
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$. 3909 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$.
4373 3910
4374 \LMHash{}
4375 A bitwise expression of the form $e_1$ $op$ $e_2$ is equivalent to the method invocation $e_1.op(e_2)$. 3911 A bitwise expression of the form $e_1$ $op$ $e_2$ is equivalent to the method invocation $e_1.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$)}. 3912 A bitwise expression of the form \code{\SUPER{} $op$ $e_2$} is equivalent to th e method invocation \code{\SUPER{}.op($e_2$)}.
4377 3913
4378 \commentary{ 3914 \commentary{
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. 3915 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.
4380 } 3916 }
4381 3917
4382 3918
4383 \subsection{ Shift} 3919 \subsection{ Shift}
4384 \LMLabel{shift} 3920 \label{shift}
4385 3921
4386 \LMHash{}
4387 Shift expressions invoke the shift operators on objects. 3922 Shift expressions invoke the shift operators on objects.
4388 3923
4389 \begin{grammar} 3924 \begin{grammar}
4390 {\bf shiftExpression:}additiveExpression (shiftOperator additiveExpression)*; 3925 {\bf shiftExpression:}additiveExpression (shiftOperator additiveExpression)*;
4391 \SUPER{} (shiftOperator additiveExpression)+ 3926 \SUPER{} (shiftOperator additiveExpression)+
4392 . 3927 .
4393 3928
4394 {\bf shiftOperator:}`{\escapegrammar \lt\lt'}; 3929 {\bf shiftOperator:}`{\escapegrammar \lt\lt'};
4395 `{\escapegrammar \gt \gt}' 3930 `{\escapegrammar \gt \gt}'
4396 . 3931 .
4397 \end{grammar} 3932 \end{grammar}
4398 3933
4399 \LMHash{}
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$. 3934 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$.
4401 3935
4402 \LMHash{}
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$)}. 3936 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$)}.
4404 3937
4405 \commentary{ 3938 \commentary{
4406 Note that this definition implies left-to-right evaluation order among shift exp ressions: 3939 Note that this definition implies left-to-right evaluation order among shift exp ressions:
4407 3940
4408 $e_1 << e_2 << e_3$ 3941 $e_1 << e_2 << e_3$
4409 3942
4410 is evaluated as $(e_1 << e_2 ).<< (e_3)$ which is equivalent to $(e_1 << e_2) << e_3$. 3943 is evaluated as $(e_1 << e_2 ).<< (e_3)$ which is equivalent to $(e_1 << e_2) << e_3$.
4411 The same holds for additive and multiplicative expressions. 3944 The same holds for additive and multiplicative expressions.
4412 } 3945 }
4413 3946
4414 \subsection{ Additive Expressions} 3947 \subsection{ Additive Expressions}
4415 \LMLabel{additiveExpressions} 3948 \label{additiveExpressions}
4416 3949
4417 \LMHash{}
4418 Additive expressions invoke the addition operators on objects. 3950 Additive expressions invoke the addition operators on objects.
4419 3951
4420 \begin{grammar} 3952 \begin{grammar}
4421 {\bf additiveExpression:}multiplicativeExpression (additiveOperator multiplicati veExpression)*; 3953 {\bf additiveExpression:}multiplicativeExpression (additiveOperator multiplicati veExpression)*;
4422 \SUPER{} (additiveOperator multiplicativeExpression)+ 3954 \SUPER{} (additiveOperator multiplicativeExpression)+
4423 . 3955 .
4424 3956
4425 {\bf additiveOperator:}`+'; 3957 {\bf additiveOperator:}`+';
4426 `-' 3958 `-'
4427 . 3959 .
4428 \end{grammar} 3960 \end{grammar}
4429 3961
4430 \LMHash{}
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$. 3962 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$.
4432 3963
4433 \LMHash{}
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$)} . 3964 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$)} .
4435 3965
4436 \LMHash{}
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}. 3966 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}.
4438 3967
4439 3968
4440 \subsection{ Multiplicative Expressions} 3969 \subsection{ Multiplicative Expressions}
4441 \LMLabel{multiplicativeExpressions} 3970 \label{multiplicativeExpressions}
4442 3971
4443 \LMHash{}
4444 Multiplicative expressions invoke the multiplication operators on objects. 3972 Multiplicative expressions invoke the multiplication operators on objects.
4445 3973
4446 \begin{grammar} 3974 \begin{grammar}
4447 {\bf multiplicativeExpression:}unaryExpression (multiplicativeOperator unaryExpr ession)*; 3975 {\bf multiplicativeExpression:}unaryExpression (multiplicativeOperator unaryExpr ession)*;
4448 \SUPER{} (multiplicativeOperator unaryExpression)+ 3976 \SUPER{} (multiplicativeOperator unaryExpression)+
4449 . 3977 .
4450 3978
4451 {\bf multiplicativeOperator:}`*'; 3979 {\bf multiplicativeOperator:}`*';
4452 `/'; 3980 `/';
4453 `\%'; 3981 `\%';
4454 `\~{}/' 3982 `\~{}/'
4455 . 3983 .
4456 3984
4457 \end{grammar} 3985 \end{grammar}
4458 3986
4459 \LMHash{}
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$. 3987 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$.
4461 3988
4462 \LMHash{}
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$)}. 3989 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$)}.
4464 3990
4465 \LMHash{}
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} . 3991 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} .
4467 3992
4468 \subsection{ Unary Expressions} 3993 \subsection{ Unary Expressions}
4469 \LMLabel{unaryExpressions} 3994 \label{unaryExpressions}
4470 3995
4471 \LMHash{}
4472 Unary expressions invoke unary operators on objects. 3996 Unary expressions invoke unary operators on objects.
4473 3997
4474 \begin{grammar} 3998 \begin{grammar}
4475 {\bf unaryExpression:}prefixOperator unaryExpression; 3999 {\bf unaryExpression:}prefixOperator unaryExpression;
4476 awaitExpression; 4000 awaitExpression;
4477 postfixExpression; 4001 postfixExpression;
4478 (minusOperator $|$ tildeOperator) \SUPER{}; 4002 (minusOperator $|$ tildeOperator) \SUPER{};
4479 incrementOperator assignableExpression 4003 incrementOperator assignableExpression
4480 . 4004 .
4481 4005
4482 {\bf prefixOperator:}minusOperator; 4006 {\bf prefixOperator:}minusOperator;
4483 negationOperator; 4007 negationOperator;
4484 tildeOperator 4008 tildeOperator
4485 . 4009 .
4486 4010
4487 4011
4488 {\bf minusOperator:}`-'; . 4012 {\bf minusOperator:}`-'; .
4489 4013
4490 4014
4491 {\bf negationOperator:}`!' ; 4015 {\bf negationOperator:}`!' ;
4492 . 4016 .
4493 4017
4494 {\bf tildeOperator:} `\~{}' 4018 {\bf tildeOperator:} `\~{}'
4495 . 4019 .
4496 4020
4497 4021
4498 \end{grammar} 4022 \end{grammar}
4499 4023
4500 \LMHash{}
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$. 4024 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$.
4502 4025
4503 \LMHash{}
4504 The expression $!e$ is equivalent to the expression $e?$ $ \FALSE{} :\TRUE{}$. 4026 The expression $!e$ is equivalent to the expression $e?$ $ \FALSE{} :\TRUE{}$.
4505 4027
4506 \LMHash{}
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}. 4028 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}.
4508 4029
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{}.-()}. 4030 %The expression $-e$ is equivalent to the method invocation \code{$e$.-()}. The expression \code{-\SUPER{}} is equivalent to the method invocation \code{\SUPE R{}.-()}.
4510 4031
4511 \LMHash{}
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()$}. 4032 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()$}.
4513 4033
4514 \subsection{ Await Expressions} 4034 \subsection{ Await Expressions}
4515 \LMLabel{awaitExpressions} 4035 \label{awaitExpressions}
4516 4036
4517 \LMHash{}
4518 An {\em await expression} allows code to yield control until an asynchronous ope ration (\ref{functions}) completes. 4037 An {\em await expression} allows code to yield control until an asynchronous ope ration (\ref{functions}) completes.
4519 4038
4520 \begin{grammar} 4039 \begin{grammar}
4521 {\bf awaitExpression:} 4040 {\bf awaitExpression:}
4522 \AWAIT{} unaryExpression 4041 \AWAIT{} unaryExpression
4523 \end{grammar} 4042 \end{grammar}
4524 4043
4525 \LMHash{}
4526 Evaluation of an await expression $a$ of the form \AWAIT{} $e$ proceeds as follo ws: 4044 Evaluation of an await expression $a$ of the form \AWAIT{} $e$ proceeds as follo ws:
4527 First, the expression $e$ is evaluated. Next: 4045 First, the expression $e$ is evaluated. Next:
4528 4046
4529 \LMHash{}
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$. 4047 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$.
4531 4048
4532 \LMHash{}
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$. 4049 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$.
4534 4050
4535 %Otherwise, the value of $a$ is the value of $e$. If evaluation of $e$ raises an exception $x$, $a$ raises $x$. 4051 %Otherwise, the value of $a$ is the value of $e$. If evaluation of $e$ raises an exception $x$, $a$ raises $x$.
4536 4052
4537 \commentary{ 4053 \commentary{
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. 4054 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.
4539 } 4055 }
4540 4056
4541 \rationale{ 4057 \rationale{
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. 4058 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.
4543 } 4059 }
4544 4060
4545 \commentary{ 4061 \commentary{
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. 4062 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.
4547 } 4063 }
4548 4064
4549 \LMHash{}
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$. 4065 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$.
4551 4066
4552 \rationale{ 4067 \rationale{
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}. 4068 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}.
4554 } 4069 }
4555 4070
4556 4071
4557 4072
4558 4073
4559 \subsection{ Postfix Expressions} 4074 \subsection{ Postfix Expressions}
4560 \LMLabel{postfixExpressions} 4075 \label{postfixExpressions}
4561 4076
4562 \LMHash{}
4563 Postfix expressions invoke the postfix operators on objects. 4077 Postfix expressions invoke the postfix operators on objects.
4564 4078
4565 \begin{grammar} 4079 \begin{grammar}
4566 {\bf postfixExpression:}assignableExpression postfixOperator; 4080 {\bf postfixExpression:}assignableExpression postfixOperator;
4567 primary selector* 4081 primary selector*
4568 . 4082 .
4569 4083
4570 {\bf postfixOperator:} 4084 {\bf postfixOperator:}
4571 incrementOperator 4085 incrementOperator
4572 . 4086 .
4573 4087
4574 {\bf selector:}assignableSelector; 4088 {\bf selector:}assignableSelector;
4575 arguments 4089 arguments
4576 . 4090 .
4577 4091
4578 {\bf incrementOperator:}`++'; 4092 {\bf incrementOperator:}`++';
4579 `-{}-' 4093 `-{}-'
4580 . 4094 .
4581 4095
4582 \end{grammar} 4096 \end{grammar}
4583 4097
4584 \LMHash{}
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$ . 4098 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$ .
4586 4099
4587 \LMHash{}
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\}()}. 4100 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\}()}.
4589 4101
4590 \rationale{The above ensures that if $v$ is a field, the getter gets called exac tly once. Likewise in the cases below. 4102 \rationale{The above ensures that if $v$ is a field, the getter gets called exac tly once. Likewise in the cases below.
4591 } 4103 }
4592 4104
4593 \LMHash{}
4594 A postfix expression of the form \code{$C.v$ ++} is equivalent to 4105 A postfix expression of the form \code{$C.v$ ++} is equivalent to
4595 4106
4596 \code{()\{var r = $C.v$; $C.v$ = r + 1; return r\}()}. 4107 \code{()\{var r = $C.v$; $C.v$ = r + 1; return r\}()}.
4597 4108
4598 \LMHash{}
4599 A postfix expression of the form \code{$e_1.v$++} is equivalent to 4109 A postfix expression of the form \code{$e_1.v$++} is equivalent to
4600 4110
4601 \code{(x)\{var r = x.v; x.v = r + 1; \RETURN{} r\}($e_1$)}. 4111 \code{(x)\{var r = x.v; x.v = r + 1; \RETURN{} r\}($e_1$)}.
4602 4112
4603 \LMHash{}
4604 A postfix expression of the form \code{$e_1[e_2]$++}, is equivalent to 4113 A postfix expression of the form \code{$e_1[e_2]$++}, is equivalent to
4605 4114
4606 \code{(a, i)\{var r = a[i]; a[i] = r + 1; return r\}($e_1$, $e_2$)}. 4115 \code{(a, i)\{var r = a[i]; a[i] = r + 1; return r\}($e_1$, $e_2$)}.
4607 4116
4608 \LMHash{}
4609 A postfix expression of the form \code{$v$-{}-}, where $v$ is an identifier, is equivalent to 4117 A postfix expression of the form \code{$v$-{}-}, where $v$ is an identifier, is equivalent to
4610 4118
4611 \code{()\{var r = $v$; $v$ = r - 1; return r\}()}. 4119 \code{()\{var r = $v$; $v$ = r - 1; return r\}()}.
4612 4120
4613 \LMHash{}
4614 A postfix expression of the form \code{$C.v$-{}-} is equivalent to 4121 A postfix expression of the form \code{$C.v$-{}-} is equivalent to
4615 4122
4616 \code{()\{var r = $C.v$; $C.v$ = r - 1; return r\}()}. 4123 \code{()\{var r = $C.v$; $C.v$ = r - 1; return r\}()}.
4617 4124
4618 \LMHash{}
4619 A postfix expression of the form \code{$e_1.v$-{}-} is equivalent to 4125 A postfix expression of the form \code{$e_1.v$-{}-} is equivalent to
4620 4126
4621 \code{(x)\{var r = x.v; x.v = r - 1; \RETURN{} r\}($e_1$)}. 4127 \code{(x)\{var r = x.v; x.v = r - 1; \RETURN{} r\}($e_1$)}.
4622 4128
4623 \LMHash{}
4624 A postfix expression of the form \code{$e_1[e_2]$-{}-}, is equivalent to 4129 A postfix expression of the form \code{$e_1[e_2]$-{}-}, is equivalent to
4625 4130
4626 \code{(a, i)\{var r = a[i]; a[i] = r - 1; return r\}($e_1$, $e_2$)}. 4131 \code{(a, i)\{var r = a[i]; a[i] = r - 1; return r\}($e_1$, $e_2$)}.
4627 4132
4628 4133
4629 \subsection{ Assignable Expressions} 4134 \subsection{ Assignable Expressions}
4630 \LMLabel{assignableExpressions} 4135 \label{assignableExpressions}
4631 4136
4632 \LMHash{}
4633 Assignable expressions are expressions that can appear on the left hand side of an assignment. 4137 Assignable expressions are expressions that can appear on the 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. 4138 This section describes how to evaluate these expressions when they do not consti tute the complete left hand side of an assignment.
4635 4139
4636 \rationale{ 4140 \rationale{
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. 4141 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.
4638 } 4142 }
4639 4143
4640 4144
4641 4145
4642 \begin{grammar} 4146 \begin{grammar}
4643 4147
4644 {\bf assignableExpression:}primary (argument* assignableSelector)+; 4148 {\bf assignableExpression:}primary (argument* assignableSelector)+;
4645 \SUPER{} assignableSelector; 4149 \SUPER{} assignableSelector;
4646 identifier 4150 identifier
4647 . 4151 .
4648 4152
4649 {\bf assignableSelector:}`[' expression `]'; % again, could be top level 4153 {\bf assignableSelector:}`[' expression `]'; % again, could be top level
4650 `{\escapegrammar .}' identifier 4154 `{\escapegrammar .}' identifier
4651 . 4155 .
4652 4156
4653 \end{grammar} 4157 \end{grammar}
4654 4158
4655 \LMHash{}
4656 An {\em assignable expression} is either: 4159 An {\em assignable expression} is either:
4657 \begin{itemize} 4160 \begin{itemize}
4658 \item An identifier. 4161 \item An identifier.
4659 \item An invocation of a getter (\ref{getters}) or list access operator on an ex pression $e$. 4162 \item An invocation of a getter (\ref{getters}) or list access operator on an ex pression $e$.
4660 \item An invocation of a getter or list access operator on \SUPER{}. 4163 \item An invocation of a getter or list access operator on \SUPER{}.
4661 \end{itemize} 4164 \end{itemize}
4662 4165
4663 4166
4664 \LMHash{}
4665 An assignable expression of the form $id$ is evaluated as an identifier expressi on (\ref{identifierReference}). 4167 An assignable expression of the form $id$ is evaluated as an identifier expressi on (\ref{identifierReference}).
4666 4168
4667 %An assignable expression of the form $e.id(a_1, \ldots, a_n)$ is evaluated as a method invocation (\ref{methodInvocation}). 4169 %An assignable expression of the form $e.id(a_1, \ldots, a_n)$ is evaluated as a method invocation (\ref{methodInvocation}).
4668 4170
4669 \LMHash{}
4670 An assignable expression of the form $e.id$ is evaluated as a property extractio n (\ref{propertyExtraction}). 4171 An assignable expression of the form $e.id$ is evaluated as a property extractio n (\ref{propertyExtraction}).
4671 4172
4672 \LMHash{}
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$. 4173 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$.
4674 4174
4675 \LMHash{}
4676 An assignable expression of the form \code{\SUPER{}.id} is evaluated as a prope rty extraction. 4175 An assignable expression of the form \code{\SUPER{}.id} is evaluated as a prope rty extraction.
4677 4176
4678 \LMHash{}
4679 An assignable expression of the form \code{\SUPER{}[$e_2$]} is equivalent to the method invocation \code{\SUPER{}.[]($e_2$)}. 4177 An assignable expression of the form \code{\SUPER{}[$e_2$]} is equivalent to the method invocation \code{\SUPER{}.[]($e_2$)}.
4680 4178
4681 \subsection{ Identifier Reference} 4179 \subsection{ Identifier Reference}
4682 \LMLabel{identifierReference} 4180 \label{identifierReference}
4683 4181
4684 \LMHash{}
4685 An {\em identifier expression} consists of a single identifier; it provides acce ss to an object via an unqualified name. 4182 An {\em identifier expression} consists of a single identifier; it provides acce ss to an object via an unqualified name.
4686 4183
4687 \begin{grammar} 4184 \begin{grammar}
4688 {\bf identifier:} 4185 {\bf identifier:}
4689 IDENTIFIER 4186 IDENTIFIER
4690 . 4187 .
4691 4188
4692 4189
4693 {\bf IDENTIFIER\_NO\_DOLLAR:} 4190 {\bf IDENTIFIER\_NO\_DOLLAR:}
4694 IDENTIFIER\_START\_NO\_DOLLAR IDENTIFIER\_PART\_NO\_DOLLAR* 4191 IDENTIFIER\_START\_NO\_DOLLAR IDENTIFIER\_PART\_NO\_DOLLAR*
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
4733 DIGIT 4230 DIGIT
4734 . 4231 .
4735 4232
4736 4233
4737 4234
4738 {\bf qualified:} 4235 {\bf qualified:}
4739 identifier (`{\escapegrammar .}' identifier)? 4236 identifier (`{\escapegrammar .}' identifier)?
4740 . 4237 .
4741 \end{grammar} 4238 \end{grammar}
4742 4239
4743 \LMHash{}
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. 4240 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.
4745 4241
4746 \rationale{ 4242 \rationale{
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. 4243 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.
4748 } 4244 }
4749 4245
4750 \LMHash{}
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*. 4246 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*.
4752 4247
4753 \rationale{ 4248 \rationale{
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. 4249 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.
4755 } 4250 }
4756 4251
4757 \LMHash{}
4758 Evaluation of an identifier expression $e$ of the form $id$ proceeds as follows: 4252 Evaluation of an identifier expression $e$ of the form $id$ proceeds as follows:
4759 4253
4760 4254
4761 \LMHash{}
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. 4255 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.
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. 4256 %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.
4764 4257
4765 \begin{itemize} 4258 \begin{itemize}
4766 \item if $d$ is a prefix $p$, a compile-time error occurs unless the token immed iately following $d$ is \code{'.'}. 4259 \item if $d$ is a prefix $p$, a compile-time error occurs unless the token immed iately following $d$ is \code{'.'}.
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$. 4260 \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$.
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. 4261 \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.
4769 4262
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}.)} 4263 %\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}.)}
4771 %\item If $d$ is a library variable then: 4264 %\item If $d$ is a library variable then:
4772 % \begin{itemize} 4265 % \begin{itemize}
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$. 4266 % \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$.
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$. 4267 \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$.
4775 % Otherwise 4268 % Otherwise
4776 % \item $e$ evaluates to the current binding of $id$. 4269 % \item $e$ evaluates to the current binding of $id$.
4777 % \end{itemize} 4270 % \end{itemize}
4778 \item If $d$ is a local variable or formal parameter then $e$ evaluates to the c urrent binding of $id$. 4271 \item If $d$ is a local variable or formal parameter then $e$ evaluates to the c urrent binding of $id$.
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.} 4272 %\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.}
4780 \item If $d$ is a static method, top-level function or local function then $e$ e valuates to the function defined by $d$. 4273 \item If $d$ is a static method, top-level function or local function then $e$ e valuates to the function defined by $d$.
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$. 4274 \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$.
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$. 4275 \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$.
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. 4276 \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.
4784 \item Otherwise, $e$ is equivalent to the property extraction (\ref{propertyExtr action}) \THIS{}.$id$. 4277 \item Otherwise, $e$ is equivalent to the property extraction (\ref{propertyExtr action}) \THIS{}.$id$.
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? 4278 % 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?
4786 \end{itemize} 4279 \end{itemize}
4787 4280
4788 \LMHash{}
4789 The static type of $e$ is determined as follows: 4281 The static type of $e$ is determined as follows:
4790 4282
4791 \begin{itemize} 4283 \begin{itemize}
4792 \item If $d$ is a class, type alias or type parameter the static type of $e$ is \code{Type}. 4284 \item If $d$ is a class, type alias or type parameter the static type of $e$ is \code{Type}.
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$. 4285 \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$.
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$. 4286 \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$.
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$. 4287 \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$.
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$. 4288 \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$.
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{}. 4289 \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{}.
4798 \item Otherwise, the static type of $e$ is the type of the property extraction ( \ref{propertyExtraction}) \THIS{}.$id$. 4290 \item Otherwise, the static type of $e$ is the type of the property extraction ( \ref{propertyExtraction}) \THIS{}.$id$.
4799 \end{itemize} 4291 \end{itemize}
4800 4292
4801 \commentary{Note that if one declares a setter, we bind to the corresponding ge tter even if it does not exist.} 4293 \commentary{Note that if one declares a setter, we bind to the corresponding ge tter even if it does not exist.}
4802 4294
4803 \rationale{ 4295 \rationale{
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. 4296 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.
4805 } 4297 }
4806 4298
4807 \LMHash{}
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. 4299 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.
4809 4300
4810 \subsection{ Type Test} 4301 \subsection{ Type Test}
4811 \LMLabel{typeTest} 4302 \label{typeTest}
4812 4303
4813 \LMHash{}
4814 The {\em is-expression} tests if an object is a member of a type. 4304 The {\em is-expression} tests if an object is a member of a type.
4815 4305
4816 \begin{grammar} 4306 \begin{grammar}
4817 {\bf typeTest:} 4307 {\bf typeTest:}
4818 isOperator type 4308 isOperator type
4819 . 4309 .
4820 4310
4821 4311
4822 {\bf isOperator:} 4312 {\bf isOperator:}
4823 \IS{} `!'? 4313 \IS{} `!'?
4824 . 4314 .
4825 \end{grammar} 4315 \end{grammar}
4826 4316
4827 \LMHash{}
4828 Evaluation of the is-expression \code{$e$ \IS{} $T$} proceeds as follows: 4317 Evaluation of the is-expression \code{$e$ \IS{} $T$} proceeds as follows:
4829 4318
4830 \LMHash{}
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. 4319 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.
4832 4320
4833 \commentary{It follows that \code{$e$ \IS{} Object} is always true. This makes s ense in a language where everything is an object. 4321 \commentary{It follows that \code{$e$ \IS{} Object} is always true. This makes s ense in a language where everything is an object.
4834 4322
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. 4323 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.
4836 } 4324 }
4837 4325
4838 \LMHash{}
4839 The is-expression \code{$e$ \IS{}! $T$} is equivalent to \code{!($e$ \IS{} $T$)} . 4326 The is-expression \code{$e$ \IS{}! $T$} is equivalent to \code{!($e$ \IS{} $T$)} .
4840 4327
4841 % Add flow dependent types 4328 % Add flow dependent types
4842 4329
4843 4330
4844 \LMHash{}
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{}$. 4331 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{}$.
4846 4332
4847 \rationale{ 4333 \rationale{
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. 4334 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.
4849 4335
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. 4336 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.
4851 4337
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). 4338 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).
4853 4339
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$. 4340 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$.
4855 } 4341 }
4856 4342
4857 \LMHash{}
4858 The static type of an is-expression is \code{bool}. 4343 The static type of an is-expression is \code{bool}.
4859 4344
4860 4345
4861 \subsection{ Type Cast} 4346 \subsection{ Type Cast}
4862 \LMLabel{typeCast} 4347 \label{typeCast}
4863 4348
4864 \LMHash{}
4865 The {\em cast expression} ensures that an object is a member of a type. 4349 The {\em cast expression} ensures that an object is a member of a type.
4866 4350
4867 \begin{grammar} 4351 \begin{grammar}
4868 {\bf typeCast:} 4352 {\bf typeCast:}
4869 asOperator type 4353 asOperator type
4870 . 4354 .
4871 4355
4872 4356
4873 {\bf asOperator:} 4357 {\bf asOperator:}
4874 \AS{} 4358 \AS{}
4875 . 4359 .
4876 \end{grammar} 4360 \end{grammar}
4877 4361
4878 \LMHash{}
4879 Evaluation of the cast expression \code{$e$ \AS{} $T$} proceeds as follows: 4362 Evaluation of the cast expression \code{$e$ \AS{} $T$} proceeds as follows:
4880 4363
4881 \LMHash{}
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$. 4364 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$.
4883 In all other cases, a \code{CastError} is thrown. 4365 In all other cases, a \code{CastError} is thrown.
4884 4366
4885 \LMHash{}
4886 The static type of a cast expression \code{$e$ \AS{} $T$} is $T$. 4367 The static type of a cast expression \code{$e$ \AS{} $T$} is $T$.
4887 4368
4888 4369
4889 \section{Statements} 4370 \section{Statements}
4890 \LMLabel{statements} 4371 \label{statements}
4891 4372
4892 \begin{grammar} 4373 \begin{grammar}
4893 {\bf statements:} 4374 {\bf statements:}
4894 statement* 4375 statement*
4895 . 4376 .
4896 4377
4897 4378
4898 {\bf statement:} 4379 {\bf statement:}
4899 label* nonLabelledStatement 4380 label* nonLabelledStatement
4900 . 4381 .
(...skipping 12 matching lines...) Expand all
4913 returnStatement; 4394 returnStatement;
4914 yieldStatement; 4395 yieldStatement;
4915 yieldEachStatement; 4396 yieldEachStatement;
4916 expressionStatement; 4397 expressionStatement;
4917 assertStatement; 4398 assertStatement;
4918 localFunctionDeclaration 4399 localFunctionDeclaration
4919 . 4400 .
4920 \end{grammar} 4401 \end{grammar}
4921 4402
4922 \subsection{Blocks} 4403 \subsection{Blocks}
4923 \LMLabel{blocks} 4404 \label{blocks}
4924 4405
4925 \LMHash{}
4926 A {\em block statement} supports sequencing of code. 4406 A {\em block statement} supports sequencing of code.
4927 4407
4928 \LMHash{}
4929 Execution of a block statement $\{s_1, \ldots, s_n\}$ proceeds as follows: 4408 Execution of a block statement $\{s_1, \ldots, s_n\}$ proceeds as follows:
4930 4409
4931 \LMHash{}
4932 For $i \in 1 .. n, s_i$ is executed. 4410 For $i \in 1 .. n, s_i$ is executed.
4933 4411
4934 \LMHash{}
4935 A block statement introduces a new scope, which is nested in the lexically enclo sing scope in which the block statement appears. 4412 A block statement introduces a new scope, which is nested in the lexically enclo sing scope in which the block statement appears.
4936 4413
4937 4414
4938 4415
4939 \subsection{Expression Statements} 4416 \subsection{Expression Statements}
4940 \LMLabel{expressionStatements} 4417 \label{expressionStatements}
4941 4418
4942 \LMHash{}
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. 4419 An {\em expression statement} consists of an expression other than a non-constan t map literal (\ref{maps}) that has no explicit type arguments.
4944 4420
4945 \rationale{ 4421 \rationale{
4946 The restriction on maps is designed to resolve an ambiguity in the grammar, whe n a statement begins with \{. 4422 The restriction on maps is designed to resolve an ambiguity in the grammar, whe n a statement begins with \{.
4947 } 4423 }
4948 4424
4949 \begin{grammar} 4425 \begin{grammar}
4950 {\bf expressionStatement:} 4426 {\bf expressionStatement:}
4951 expression? `{\escapegrammar ;}' 4427 expression? `{\escapegrammar ;}'
4952 . 4428 .
4953 \end{grammar} 4429 \end{grammar}
4954 4430
4955 \LMHash{}
4956 Execution of an expression statement \code{$e$;} proceeds by evaluating $e$. 4431 Execution of an expression statement \code{$e$;} proceeds by evaluating $e$.
4957 4432
4958 \LMHash{}
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. 4433 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.
4960 4434
4961 \subsection{Local Variable Declaration} 4435 \subsection{Local Variable Declaration}
4962 \LMLabel{localVariableDeclaration} 4436 \label{localVariableDeclaration}
4963 4437
4964 4438
4965 \LMHash{}
4966 A {\em variable declaration statement }declares a new local variable. 4439 A {\em variable declaration statement }declares a new local variable.
4967 4440
4968 \begin{grammar} 4441 \begin{grammar}
4969 {\bf localVariableDeclaration:} 4442 {\bf localVariableDeclaration:}
4970 initializedVariableDeclaration {\escapegrammar';'} 4443 initializedVariableDeclaration {\escapegrammar';'}
4971 . 4444 .
4972 \end{grammar} 4445 \end{grammar}
4973 4446
4974 \LMHash{}
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: 4447 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:
4976 4448
4977 \LMHash{}
4978 The expression $e$ is evaluated to an object $o$. Then, the variable $v$ is set to $o$. 4449 The expression $e$ is evaluated to an object $o$. Then, the variable $v$ is set to $o$.
4979 4450
4980 \LMHash{}
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{};$. 4451 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{};$.
4982 4452
4983 \commentary{ 4453 \commentary{
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;}. 4454 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;}.
4985 } 4455 }
4986 4456
4987 \rationale{ 4457 \rationale{
4988 To do otherwise would undermine the optionally typed nature of Dart, causing typ e annotations to modify program behavior. 4458 To do otherwise would undermine the optionally typed nature of Dart, causing typ e annotations to modify program behavior.
4989 } 4459 }
4990 4460
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$. 4461 %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$.
4992 4462
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$. 4463 %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$.
4994 4464
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$. 4465 %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$.
4996 4466
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$. 4467 %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$.
4998 4468
4999 %\rationale{ 4469 %\rationale{
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. 4470 %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.
5001 %} 4471 %}
5002 4472
5003 4473
5004 \subsection{Local Function Declaration} 4474 \subsection{Local Function Declaration}
5005 \LMLabel{localFunctionDeclaration}
5006 4475
5007 \LMHash{} 4476 \label{localFunctionDeclaration}
4477
5008 A function declaration statement declares a new local function (\ref{functionDec larations}). 4478 A function declaration statement declares a new local function (\ref{functionDec larations}).
5009 4479
5010 \begin{grammar} 4480 \begin{grammar}
5011 {\bf localFunctionDeclaration:} 4481 {\bf localFunctionDeclaration:}
5012 functionSignature functionBody 4482 functionSignature functionBody
5013 . 4483 .
5014 \end{grammar} 4484 \end{grammar}
5015 4485
5016 \LMHash{}
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. 4486 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.
5018 4487
5019 4488
5020 \commentary{ This implies that local functions can be directly recursive, but no t mutually recursive. Consider these examples: 4489 \commentary{ This implies that local functions can be directly recursive, but no t mutually recursive. Consider these examples:
5021 } 4490 }
5022 4491
5023 \begin{dartCode} 4492 \begin{dartCode}
5024 f(x) =$>$ x++; // a top level function 4493 f(x) =$>$ x++; // a top level function
5025 top() \{ // another top level function 4494 top() \{ // another top level function
5026 f(3); // illegal 4495 f(3); // illegal
(...skipping 23 matching lines...) Expand all
5050 \} 4519 \}
5051 \end{dartCode} 4520 \end{dartCode}
5052 4521
5053 \rationale{ 4522 \rationale{
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. 4523 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.
5055 } 4524 }
5056 4525
5057 % elaborate on function identity and equality, runtime type. Likewsie in functio n expressions (closures) and declarations 4526 % elaborate on function identity and equality, runtime type. Likewsie in functio n expressions (closures) and declarations
5058 4527
5059 \subsection{If} 4528 \subsection{If}
5060 \LMLabel{if} 4529 \label{if}
5061 4530
5062 \LMHash{}
5063 The {\em if statement} allows for conditional execution of statements. 4531 The {\em if statement} allows for conditional execution of statements.
5064 4532
5065 \begin{grammar} 4533 \begin{grammar}
5066 {\bf ifStatement:} 4534 {\bf ifStatement:}
5067 \IF{} `(' expression `)' statement ( \ELSE{} statement)? % we could allow top level expression 4535 \IF{} `(' expression `)' statement ( \ELSE{} statement)? % we could allow top level expression
5068 . 4536 .
5069 \end{grammar} 4537 \end{grammar}
5070 4538
5071 Execution of an if statement of the form \code {\IF{} (}$b$\code{)}$s_1$ \code{ \ELSE{} } $s_2$ proceeds as follows: 4539 Execution of an if statement of the form \code {\IF{} (}$b$\code{)}$s_1$ \code{ \ELSE{} } $s_2$ proceeds as follows:
5072 4540
5073 \LMHash{}
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. 4541 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.
5075 4542
5076 4543
5077 \commentary { 4544 \commentary {
5078 Put another way, \code {\IF{} (}$b$\code{)}$s_1$ \code{\ELSE{} } $s_2$ is equiv alent to 4545 Put another way, \code {\IF{} (}$b$\code{)}$s_1$ \code{\ELSE{} } $s_2$ is equiv alent to
5079 \code {\IF{} (}$b$\code{)}$\{s_1\}$ \code{\ELSE{} } $\{s_2\}$ 4546 \code {\IF{} (}$b$\code{)}$\{s_1\}$ \code{\ELSE{} } $\{s_2\}$
5080 } 4547 }
5081 4548
5082 \rationale { 4549 \rationale {
5083 The reason for this equivalence is to catch errors such as 4550 The reason for this equivalence is to catch errors such as
5084 } 4551 }
5085 \begin{dartCode} 4552 \begin{dartCode}
5086 \VOID{} main() \{ 4553 \VOID{} main() \{
5087 \IF{} (somePredicate) 4554 \IF{} (somePredicate)
5088 \VAR{} v = 2; 4555 \VAR{} v = 2;
5089 print(v); 4556 print(v);
5090 \} 4557 \}
5091 \end{dartCode} 4558 \end{dartCode}
5092 4559
5093 \rationale { 4560 \rationale {
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. 4561 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.
5095 } 4562 }
5096 4563
5097 \LMHash{}
5098 It is a static type warning if the type of the expression $b$ may not be assig ned to \code{bool}. 4564 It is a static type warning if the type of the expression $b$ may not be assig ned to \code{bool}.
5099 4565
5100 \LMHash{}
5101 If: 4566 If:
5102 \begin{itemize} 4567 \begin{itemize}
5103 \item $b$ shows that a variable $v$ has type $T$. 4568 \item $b$ shows that a variable $v$ has type $T$.
5104 \item $v$ is not potentially mutated in $s_1$ or within a closure. 4569 \item $v$ is not potentially mutated in $s_1$ or within a closure.
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$. 4570 \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$.
5106 \end{itemize} 4571 \end{itemize}
5107 then the type of $v$ is known to be $T$ in $s_1$. 4572 then the type of $v$ is known to be $T$ in $s_1$.
5108 4573
5109 \LMHash{}
5110 An if statement of the form \code {\IF{} (}$b$\code{)}$s_1$ is equivalent to t he if statement 4574 An if statement of the form \code {\IF{} (}$b$\code{)}$s_1$ is equivalent to t he if statement
5111 4575
5112 \code {\IF{} (}$b$\code{)}$s_1$ \code{\ELSE{} \{\}}. 4576 \code {\IF{} (}$b$\code{)}$s_1$ \code{\ELSE{} \{\}}.
5113 4577
5114 4578
5115 4579
5116 \subsection{For} 4580 \subsection{For}
5117 \LMLabel{for} 4581 \label{for}
5118 4582
5119 \LMHash{}
5120 The {\em for statement} supports iteration. 4583 The {\em for statement} supports iteration.
5121 4584
5122 \begin{grammar} 4585 \begin{grammar}
5123 {\bf forStatement:} 4586 {\bf forStatement:}
5124 \AWAIT? \FOR{} `(' forLoopParts `)' statement 4587 \AWAIT? \FOR{} `(' forLoopParts `)' statement
5125 . 4588 .
5126 4589
5127 {\bf forLoopParts:}forInitializerStatement expression? `{\escapegrammar ;}' expr essionList?; 4590 {\bf forLoopParts:}forInitializerStatement expression? `{\escapegrammar ;}' expr essionList?;
5128 declaredIdentifier \IN{} expression; 4591 declaredIdentifier \IN{} expression;
5129 identifier \IN{} expression 4592 identifier \IN{} expression
5130 . 4593 .
5131 4594
5132 {\bf forInitializerStatement:}localVariableDeclaration `{\escapegrammar ;}'; 4595 {\bf forInitializerStatement:}localVariableDeclaration `{\escapegrammar ;}';
5133 expression? `{\escapegrammar ;}' 4596 expression? `{\escapegrammar ;}'
5134 . 4597 .
5135 \end{grammar} 4598 \end{grammar}
5136 4599
5137 \LMHash{}
5138 The for statement has three forms - the traditional for loop and two forms of t he for-in statement - synchronous and asynchronous. 4600 The for statement has three forms - the traditional for loop and two forms of t he for-in statement - synchronous and asynchronous.
5139 4601
5140 \subsubsection{For Loop} 4602 \subsubsection{For Loop}
5141 \LMLabel{forLoop} 4603 \label{forLoop}
5142 4604
5143 4605
5144 \LMHash{}
5145 Execution of a for statement of the form \code{ \FOR{} (\VAR{} $v = e_0$ ; $c$ ; $e$) $s$} proceeds as follows: 4606 Execution of a for statement of the form \code{ \FOR{} (\VAR{} $v = e_0$ ; $c$ ; $e$) $s$} proceeds as follows:
5146 4607
5147 \LMHash{}
5148 If $c$ is empty then let $c^\prime$ be \TRUE{} otherwise let $c^\prime$ be $c$. 4608 If $c$ is empty then let $c^\prime$ be \TRUE{} otherwise let $c^\prime$ be $c$.
5149 4609
5150 \LMHash{}
5151 First the variable declaration statement \VAR{} $v = e_0$ is executed. Then: 4610 First the variable declaration statement \VAR{} $v = e_0$ is executed. Then:
5152 \begin{enumerate} 4611 \begin{enumerate}
5153 \item 4612 \item
5154 \label{beginFor} 4613 \label{beginFor}
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}. 4614 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}.
5156 \item 4615 \item
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 4616 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
5158 \ref{beginIteration}. 4617 \ref{beginIteration}.
5159 \item 4618 \item
5160 \label{beginIteration} 4619 \label{beginIteration}
5161 The statement $[v^\prime/v]\{s\}$ is executed. 4620 The statement $[v^\prime/v]\{s\}$ is executed.
5162 \item 4621 \item
5163 \label{allocateFreshVar} 4622 \label{allocateFreshVar}
5164 Let $v^{\prime\prime}$ be a fresh variable. $v^{\prime\prime}$ is bound to the value of $v^\prime$. 4623 Let $v^{\prime\prime}$ be a fresh variable. $v^{\prime\prime}$ is bound to the value of $v^\prime$.
5165 \item 4624 \item
5166 The expression $[v^{\prime\prime}/v]e$ is evaluated, and the process recurses at step 4625 The expression $[v^{\prime\prime}/v]e$ is evaluated, and the process recurses at step
5167 \ref{beginFor}. 4626 \ref{beginFor}.
5168 \end{enumerate} 4627 \end{enumerate}
5169 4628
5170 \rationale{ 4629 \rationale{
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. 4630 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.
5172 4631
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. 4632 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.
5174 } 4633 }
5175 4634
5176 \LMHash{}
5177 It is a static warning if the static type of $c$ may not be assigned to \cd{bool }. 4635 It is a static warning if the static type of $c$ may not be assigned to \cd{bool }.
5178 4636
5179 %A for statement of the form \code{ \FOR{} ($d$ ; $c$; $e$) $s$} is equivalent t o the the following code: 4637 %A for statement of the form \code{ \FOR{} ($d$ ; $c$; $e$) $s$} is equivalent t o the the following code:
5180 4638
5181 %\code{ 4639 %\code{
5182 %\{$d$; 4640 %\{$d$;
5183 %\WHILE{} ($c$) \{ 4641 %\WHILE{} ($c$) \{
5184 % \{$s$\} 4642 % \{$s$\}
5185 % $e$; 4643 % $e$;
5186 %\}\} 4644 %\}\}
5187 %} 4645 %}
5188 4646
5189 %If $c$ is empty, it is interpreted as \TRUE{}. 4647 %If $c$ is empty, it is interpreted as \TRUE{}.
5190 4648
5191 \subsubsection{For-in} 4649 \subsubsection{For-in}
5192 \LMLabel{for-in} 4650 \label{for-in}
5193 4651
5194 \LMHash{}
5195 A for statement of the form \code{ \FOR{} ($finalConstVarOrType?$ id \IN{} $e$) $s$} is equivalent to the following code: 4652 A for statement of the form \code{ \FOR{} ($finalConstVarOrType?$ id \IN{} $e$) $s$} is equivalent to the following code:
5196 4653
5197 \begin{dartCode} 4654 \begin{dartCode}
5198 var n0 = $e$.iterator; 4655 var n0 = $e$.iterator;
5199 \WHILE{} (n0.moveNext()) \{ 4656 \WHILE{} (n0.moveNext()) \{
5200 $finalConstVarOrType?$ id = n0.current; 4657 $finalConstVarOrType?$ id = n0.current;
5201 $s$ 4658 $s$
5202 \} 4659 \}
5203 \end{dartCode} 4660 \end{dartCode}
5204 where \code{n0} is an identifier that does not occur anywhere in the program. 4661 where \code{n0} is an identifier that does not occur anywhere in the program.
5205 4662
5206 \commentary{ 4663 \commentary{
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. 4664 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.
5208 } 4665 }
5209 4666
5210 \subsubsection{Asynchronous For-in} 4667 \subsubsection{Asynchronous For-in}
5211 \LMLabel{asynchronousFor-in} 4668 \label{asynchronousFor-in}
5212 4669
5213 \LMHash{}
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. 4670 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.
5215 4671
5216 \LMHash{}
5217 Execution of a for-in statement of the form \code{\AWAIT{} \FOR{} (finalConstVa rOrType? id \IN{} $e$) $s$} proceeds as follows: 4672 Execution of a for-in statement of the form \code{\AWAIT{} \FOR{} (finalConstVa rOrType? id \IN{} $e$) $s$} proceeds as follows:
5218 4673
5219 \LMHash{}
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}. 4674 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}.
5221 4675
5222 \LMHash{}
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}). 4676 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}).
5224 4677
5225 \LMHash{}
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. 4678 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.
5227 4679
5228 \rationale{ 4680 \rationale{
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. 4681 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.
5230 } 4682 }
5231 4683
5232 \LMHash{}
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. 4684 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.
5234 4685
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.} 4686 \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.}
5236 4687
5237 4688
5238 \subsection{While} 4689 \subsection{While}
5239 \LMLabel{while} 4690 \label{while}
5240 4691
5241 \LMHash{}
5242 The while statement supports conditional iteration, where the condition is evalu ated prior to the loop. 4692 The while statement supports conditional iteration, where the condition is evalu ated prior to the loop.
5243 4693
5244 \begin{grammar} 4694 \begin{grammar}
5245 {\bf whileStatement:} 4695 {\bf whileStatement:}
5246 \WHILE{} `(' expression `)' statement % could do top level here, and in f or 4696 \WHILE{} `(' expression `)' statement % could do top level here, and in f or
5247 . 4697 .
5248 \end{grammar} 4698 \end{grammar}
5249 4699
5250 \LMHash{}
5251 Execution of a while statement of the form \code{\WHILE{} ($e$) $s$;} proceeds as follows: 4700 Execution of a while statement of the form \code{\WHILE{} ($e$) $s$;} proceeds as follows:
5252 4701
5253 \LMHash{}
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. 4702 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.
5255 4703
5256 \LMHash{}
5257 It is a static type warning if the static type of $e$ may not be assigned to \co de{bool}. 4704 It is a static type warning if the static type of $e$ may not be assigned to \co de{bool}.
5258 4705
5259 4706
5260 \subsection{Do} 4707 \subsection{Do}
5261 \LMLabel{do} 4708 \label{do}
5262 4709
5263 \LMHash{}
5264 The do statement supports conditional iteration, where the condition is evaluate d after the loop. 4710 The do statement supports conditional iteration, where the condition is evaluate d after the loop.
5265 4711
5266 \begin{grammar} 4712 \begin{grammar}
5267 {\bf doStatement:} 4713 {\bf doStatement:}
5268 \DO{} statement \WHILE{} `(' expression `)' `{\escapegrammar ;}'% could do t op level here 4714 \DO{} statement \WHILE{} `(' expression `)' `{\escapegrammar ;}'% could do t op level here
5269 . 4715 .
5270 \end{grammar} 4716 \end{grammar}
5271 4717
5272 4718
5273 \LMHash{}
5274 Execution of a do statement of the form \code{\DO{} $s$ \WHILE{} ($e$);} proceed s as follows: 4719 Execution of a do statement of the form \code{\DO{} $s$ \WHILE{} ($e$);} proceed s as follows:
5275 4720
5276 \LMHash{}
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. 4721 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.
5278 4722
5279 \LMHash{}
5280 It is a static type warning if the static type of $e$ may not be assigned to \co de{bool}. 4723 It is a static type warning if the static type of $e$ may not be assigned to \co de{bool}.
5281 4724
5282 \subsection{Switch} 4725 \subsection{Switch}
5283 \LMLabel{switch} 4726 \label{switch}
5284 4727
5285 \LMHash{}
5286 The {\em switch statement} supports dispatching control among a large number of cases. 4728 The {\em switch statement} supports dispatching control among a large number of cases.
5287 4729
5288 \begin{grammar} 4730 \begin{grammar}
5289 {\bf switchStatement:} 4731 {\bf switchStatement:}
5290 \SWITCH{} `(' expression `)' `\{' switchCase* defaultCase? `\}'% could do top level here and in cases 4732 \SWITCH{} `(' expression `)' `\{' switchCase* defaultCase? `\}'% could do top level here and in cases
5291 . 4733 .
5292 4734
5293 4735
5294 {\bf switchCase:} 4736 {\bf switchCase:}
5295 label* (\CASE{} expression `{\escapegrammar :}') statements 4737 label* (\CASE{} expression `{\escapegrammar :}') statements
5296 . 4738 .
5297 4739
5298 {\bf defaultCase:} 4740 {\bf defaultCase:}
5299 label* \DEFAULT{} `{\escapegrammar :}' statements 4741 label* \DEFAULT{} `{\escapegrammar :}' statements
5300 . 4742 .
5301 \end{grammar} 4743 \end{grammar}
5302 4744
5303 \LMHash{}
5304 Given a switch statement of the form 4745 Given a switch statement of the form
5305 4746
5306 \begin{dartCode} 4747 \begin{dartCode}
5307 \SWITCH{} ($e$) \{ 4748 \SWITCH{} ($e$) \{
5308 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ 4749 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$
5309 $\ldots$ 4750 $\ldots$
5310 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ 4751 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$
5311 \DEFAULT{}: $s_{n+1}$ 4752 \DEFAULT{}: $s_{n+1}$
5312 \} 4753 \}
5313 \end{dartCode} 4754 \end{dartCode}
(...skipping 11 matching lines...) Expand all
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: 4766 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:
5326 \begin{itemize} 4767 \begin{itemize}
5327 \item instances of the same class $C$, for all $k \in 1..n$, or 4768 \item instances of the same class $C$, for all $k \in 1..n$, or
5328 \item instances of a class that implements \cd{int}, for all $k \in 1..n$, or 4769 \item instances of a class that implements \cd{int}, for all $k \in 1..n$, or
5329 \item instances of a class that implements \cd{String}, for all $k \in 1..n$. 4770 \item instances of a class that implements \cd{String}, for all $k \in 1..n$.
5330 \end{itemize} 4771 \end{itemize}
5331 4772
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. 4773 \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.
5333 } 4774 }
5334 4775
5335 \LMHash{}
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}. 4776 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}.
5337 4777
5338 \rationale{ 4778 \rationale{
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. 4779 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.
5340 4780
5341 } 4781 }
5342 4782
5343 \commentary{ 4783 \commentary{
5344 The \SWITCH{} statement should only be used in very limited situations (e.g., i nterpreters or scanners). 4784 The \SWITCH{} statement should only be used in very limited situations (e.g., i nterpreters or scanners).
5345 } 4785 }
5346 4786
5347 \LMHash{}
5348 Execution of a switch statement of the form 4787 Execution of a switch statement of the form
5349 4788
5350 \begin{dartCode} 4789 \begin{dartCode}
5351 \SWITCH{} ($e$) \{ 4790 \SWITCH{} ($e$) \{
5352 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ 4791 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$
5353 $\ldots$ 4792 $\ldots$
5354 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ 4793 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$
5355 \DEFAULT{}: $s_{n+1}$ 4794 \DEFAULT{}: $s_{n+1}$
5356 \} 4795 \}
5357 \end{dartCode} 4796 \end{dartCode}
5358 4797
5359 or the form 4798 or the form
5360 4799
5361 \begin{dartCode} 4800 \begin{dartCode}
5362 \SWITCH{} ($e$) \{ 4801 \SWITCH{} ($e$) \{
5363 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ 4802 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$
5364 $\ldots$ 4803 $\ldots$
5365 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ 4804 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$
5366 \} 4805 \}
5367 \end{dartCode} 4806 \end{dartCode}
5368 4807
5369 proceeds as follows: 4808 proceeds as follows:
5370 4809
5371 \LMHash{}
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$. 4810 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$.
5373 4811
5374 \commentary{Note that if there are no case clauses ($n = 0$), the type of $e$ do es not matter.} 4812 \commentary{Note that if there are no case clauses ($n = 0$), the type of $e$ do es not matter.}
5375 4813
5376 \LMHash{}
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}$. 4814 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}$.
5378 4815
5379 \LMHash{}
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. 4816 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.
5381 4817
5382 \LMHash{}
5383 Execution of a \CASE{} clause \CASE{} $e_{k}: s_{k}$ of a switch statement 4818 Execution of a \CASE{} clause \CASE{} $e_{k}: s_{k}$ of a switch statement
5384 4819
5385 \begin{dartCode} 4820 \begin{dartCode}
5386 \SWITCH{} ($e$) \{ 4821 \SWITCH{} ($e$) \{
5387 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ 4822 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$
5388 $\ldots$ 4823 $\ldots$
5389 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ 4824 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$
5390 \DEFAULT{}: $s_{n+1}$ 4825 \DEFAULT{}: $s_{n+1}$
5391 \} 4826 \}
5392 \end{dartCode} 4827 \end{dartCode}
5393 4828
5394 proceeds as follows: 4829 proceeds as follows:
5395 4830
5396 \LMHash{}
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$. 4831 The expression \code{$e_k$ == id} is evaluated to an object $o$ which is then su bjected to boolean conversion yielding a value $v$.
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}$. 4832 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}$.
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. 4833 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.
5400 If execution reaches the point after $s_h$ then a runtime error occurs, unless $h = n+1$. 4834 If execution reaches the point after $s_h$ then a runtime error occurs, unless $h = n+1$.
5401 4835
5402 \LMHash{}
5403 Execution of a \CASE{} clause \CASE{} $e_{k}: s_{k}$ of a switch statement 4836 Execution of a \CASE{} clause \CASE{} $e_{k}: s_{k}$ of a switch statement
5404 4837
5405 \begin{dartCode} 4838 \begin{dartCode}
5406 \SWITCH{} ($e$) \{ 4839 \SWITCH{} ($e$) \{
5407 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ 4840 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$
5408 $\ldots$ 4841 $\ldots$
5409 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ 4842 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$
5410 \} 4843 \}
5411 \end{dartCode} 4844 \end{dartCode}
5412 4845
5413 proceeds as follows: 4846 proceeds as follows:
5414 4847
5415 \LMHash{}
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$. 4848 The expression \code{$e_k$ == id} is evaluated to an object $o$ which is then su bjected to boolean conversion yielding a value $v$.
5417 If $v$ is not \TRUE{} the following case, \CASE{} $e_{k+1}: s_{k+1}$ is execut ed if it exists. 4849 If $v$ is not \TRUE{} the following case, \CASE{} $e_{k+1}: s_{k+1}$ is execut ed 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. 4850 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.
5419 If execution reaches the point after $s_h$ then a runtime error occurs, unless $h = n$. 4851 If execution reaches the point after $s_h$ then a runtime error occurs, unless $h = n$.
5420 4852
5421 4853
5422 \commentary{ 4854 \commentary{
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 . 4855 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 .
5424 } 4856 }
5425 4857
5426 \LMHash{}
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. 4858 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.
5428 4859
5429 \rationale{ 4860 \rationale{
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) . 4861 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) .
5431 4862
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.: 4863 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.:
5433 } 4864 }
5434 4865
5435 \begin{dartCode} 4866 \begin{dartCode}
5436 \SWITCH{} (x) \{ 4867 \SWITCH{} (x) \{
5437 \CASE{} 1: \TRY{} \{ $\ldots$ \RETURN{};\} \FINALLY{} \{ $\ldots$ \RETURN{};\} 4868 \CASE{} 1: \TRY{} \{ $\ldots$ \RETURN{};\} \FINALLY{} \{ $\ldots$ \RETURN{};\}
5438 \} 4869 \}
5439 \end{dartCode} 4870 \end{dartCode}
5440 4871
5441 \rationale{ 4872 \rationale{
5442 Very elaborate code in a case clause is probably bad style in any case, and su ch code can always be refactored. 4873 Very elaborate code in a case clause is probably bad style in any case, and su ch code can always be refactored.
5443 } 4874 }
5444 4875
5445 \LMHash{}
5446 It is a static warning if all of the following conditions hold: 4876 It is a static warning if all of the following conditions hold:
5447 \begin{itemize} 4877 \begin{itemize}
5448 \item The switch statement does not have a default clause. 4878 \item The switch statement does not have a default clause.
5449 \item The static type of $e$ is an enumerated typed with elements $id_1, \ldots , id_n$. 4879 \item The static type of $e$ is an enumerated typed with elements $id_1, \ldots , id_n$.
5450 \item The sets $\{e_1, \ldots, e_k\} $ and $\{id_1, \ldots, id_n\}$ are not the same. 4880 \item The sets $\{e_1, \ldots, e_k\} $ and $\{id_1, \ldots, id_n\}$ are not the same.
5451 \end{itemize} 4881 \end{itemize}
5452 4882
5453 \commentary{ 4883 \commentary{
5454 In other words, a warning will be issued if a switch statement over an enum is n ot exhaustive. 4884 In other words, a warning will be issued if a switch statement over an enum is n ot exhaustive.
5455 } 4885 }
5456 4886
5457 4887
5458 \subsection{ Rethrow} 4888 \subsection{ Rethrow}
5459 \LMLabel{rethrow} 4889 \label{rethrow}
5460 4890
5461 4891
5462 \LMHash{}
5463 The {\em rethrow statement} is used to re-raise an exception. 4892 The {\em rethrow statement} is used to re-raise an exception.
5464 4893
5465 \begin{grammar} 4894 \begin{grammar}
5466 {\bf rethrowStatement:} 4895 {\bf rethrowStatement:}
5467 \RETHROW{} `{\escapegrammar ;}' 4896 \RETHROW{} `{\escapegrammar ;}'
5468 . 4897 .
5469 \end{grammar} 4898 \end{grammar}
5470 4899
5471 \LMHash{}
5472 Execution of a \code{\RETHROW{}} statement proceeds as follows: 4900 Execution of a \code{\RETHROW{}} statement proceeds as follows:
5473 4901
5474 \LMHash{}
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}). 4902 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}).
5476 4903
5477 \rationale{ 4904 \rationale{
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. 4905 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.
5479 } 4906 }
5480 4907
5481 \LMHash{}
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$. 4908 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$.
5483 4909
5484 \LMHash{}
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. 4910 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.
5486 4911
5487 \rationale{ 4912 \rationale{
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. 4913 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.
5489 } 4914 }
5490 4915
5491 \LMHash{}
5492 Otherwise, control is transferred to the innermost enclosing exception handler. 4916 Otherwise, control is transferred to the innermost enclosing exception handler.
5493 4917
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.} 4918 \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.}
5495 4919
5496 \LMHash{}
5497 It is a compile-time error if a \code{\RETHROW{}} statement is not enclosed wit hin an \ON-\CATCH{} clause. 4920 It is a compile-time error if a \code{\RETHROW{}} statement is not enclosed wit hin an \ON-\CATCH{} clause.
5498 4921
5499 4922
5500 4923
5501 \subsection{ Try} 4924 \subsection{ Try}
5502 \LMLabel{try} 4925 \label{try}
5503 4926
5504 \LMHash{}
5505 The try statement supports the definition of exception handling code in a struct ured way. 4927 The try statement supports the definition of exception handling code in a struct ured way.
5506 4928
5507 \begin{grammar} 4929 \begin{grammar}
5508 {\bf tryStatement:} 4930 {\bf tryStatement:}
5509 \TRY{} block (onPart+ finallyPart? $|$ finallyPart) 4931 \TRY{} block (onPart+ finallyPart? $|$ finallyPart)
5510 . 4932 .
5511 4933
5512 {\bf onPart:}catchPart block; 4934 {\bf onPart:}catchPart block;
5513 \ON{} type catchPart? block 4935 \ON{} type catchPart? block
5514 . 4936 .
5515 4937
5516 {\bf catchPart:} 4938 {\bf catchPart:}
5517 \CATCH{} `(' identifier (`,' identifier)? `)' 4939 \CATCH{} `(' identifier (`,' identifier)? `)'
5518 . 4940 .
5519 4941
5520 {\bf finallyPart:} 4942 {\bf finallyPart:}
5521 \FINALLY{} block 4943 \FINALLY{} block
5522 . 4944 .
5523 \end{grammar} 4945 \end{grammar}
5524 4946
5525 \LMHash{}
5526 A try statement consists of a block statement, followed by at least one of: 4947 A try statement consists of a block statement, followed by at least one of:
5527 \begin{enumerate} 4948 \begin{enumerate}
5528 \item 4949 \item
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. 4950 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.
5530 \item 4951 \item
5531 A \FINALLY{} clause, which consists of a block statement. 4952 A \FINALLY{} clause, which consists of a block statement.
5532 \end{enumerate} 4953 \end{enumerate}
5533 4954
5534 \rationale{ 4955 \rationale{
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. 4956 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.
5536 } 4957 }
5537 4958
5538 \LMHash{}
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. 4959 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.
5540 4960
5541 \commentary { 4961 \commentary {
5542 It is of course a static warning if $T$ is a deferred or malformed type. 4962 It is of course a static warning if $T$ is a deferred or malformed type.
5543 } 4963 }
5544 4964
5545 \LMHash{}
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}. 4965 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}.
5547 4966
5548 4967
5549 \LMHash{}
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. 4968 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.
5551 4969
5552 4970
5553 \LMHash{}
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$}. 4971 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$}.
5555 4972
5556 4973
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{}. 4974 %If an explicit type is associated with of $p_2$, it is a static warning if that type is not \code{Object} or \DYNAMIC{}.
5558 4975
5559 \LMHash{}
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. 4976 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.
5561 %\begin{enumerate} 4977 %\begin{enumerate}
5562 %\item Started execution after the currently executing function. 4978 %\item Started execution after the currently executing function.
5563 %\item Had not completed execution at the point where the exception caught by th e currently executing \ON{}-\CATCH{} clause was initially thrown. 4979 %\item Had not completed execution at the point where the exception caught by th e currently executing \ON{}-\CATCH{} clause was initially thrown.
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.} 4980 %\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.}
5565 %\end{enumerate} 4981 %\end{enumerate}
5566 4982
5567 \commentary{ 4983 \commentary{
5568 This implies that no synthetic function activations may be added to the trace, n or may any source level activations be omitted. 4984 This implies that no synthetic function activations may be added to the trace, n or may any source level activations be omitted.
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. 4985 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
5580 4996
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. 4997 % 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.
5582 4998
5583 % Is this controversial? We were thinking of viewing the trace as a List<Invoca tion>, 4999 % Is this controversial? We were thinking of viewing the trace as a List<Invoca tion>,
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. 5000 % 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.
5585 5001
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. } 5002 \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. }
5587 5003
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. 5004 % A position can be represented via a Token. If we make that part of the core r eflection facility, we can state this here.
5589 5005
5590 \LMHash{}
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: 5006 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:
5592 5007
5593 \LMHash{}
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. 5008 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.
5595 5009
5596 5010
5597 \LMHash{}
5598 A finally clause \FINALLY{} $s$ defines an exception handler $h$ that executes a s follows: 5011 A finally clause \FINALLY{} $s$ defines an exception handler $h$ that executes a s follows:
5599 5012
5600 \LMHash{}
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. 5013 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.
5602 5014
5603 \rationale{ 5015 \rationale{
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. 5016 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.
5605 } 5017 }
5606 5018
5607 \LMHash{}
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: 5019 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:
5609 \begin{itemize} 5020 \begin{itemize}
5610 \item 5021 \item
5611 if there is a dynamically enclosing error handler $g$ defined by a \FINALLY{} c lause in $m$, control is transferred to $g$. 5022 if there is a dynamically enclosing error handler $g$ defined by a \FINALLY{} c lause in $m$, control is transferred to $g$.
5612 \item 5023 \item
5613 Otherwise $m$ terminates. 5024 Otherwise $m$ terminates.
5614 \end{itemize} 5025 \end{itemize}
5615 5026
5616 Otherwise, execution resumes at the end of the try statement. 5027 Otherwise, execution resumes at the end of the try statement.
5617 5028
5618 \LMHash{}
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. 5029 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.
5620 5030
5621 \LMHash{}
5622 Execution of a \FINALLY{} clause \FINALLY{} $s$ of a try statement proceeds as f ollows: 5031 Execution of a \FINALLY{} clause \FINALLY{} $s$ of a try statement proceeds as f ollows:
5623 5032
5624 \LMHash{}
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. 5033 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.
5626 5034
5627 5035
5628 \LMHash{}
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: 5036 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:
5630 5037
5631 \LMHash{}
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. 5038 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.
5633 5039
5634 \commentary{ 5040 \commentary{
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). 5041 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).
5636 5042
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 . 5043 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 .
5638 5044
5639 If a matching \ON{}-\CATCH{} was found, it will execute first, and then the \FIN ALLY{} clause will be executed. 5045 If a matching \ON{}-\CATCH{} was found, it will execute first, and then the \FIN ALLY{} clause will be executed.
5640 5046
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. 5047 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.
5642 5048
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. 5049 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.
5644 } 5050 }
5645 5051
5646 \LMHash{}
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{} $\{\}$}. 5052 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{} $\{\}$}.
5648 5053
5649 5054
5650 \subsection{ Return} 5055 \subsection{ Return}
5651 \LMLabel{return} 5056 \label{return}
5652 5057
5653 \LMHash{}
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}). 5058 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}).
5655 5059
5656 5060
5657 \begin{grammar} 5061 \begin{grammar}
5658 {\bf returnStatement:} 5062 {\bf returnStatement:}
5659 \RETURN{} expression? `{\escapegrammar ;}' % could do top level here 5063 \RETURN{} expression? `{\escapegrammar ;}' % could do top level here
5660 . 5064 .
5661 \end{grammar} 5065 \end{grammar}
5662 5066
5663 \commentary{ 5067 \commentary{
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. 5068 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.
5665 } 5069 }
5666 5070
5667 \LMHash{}
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. 5071 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.
5669 5072
5670 \LMHash{}
5671 Executing a return statement \code{\RETURN{} $e$;} proceeds as follows: 5073 Executing a return statement \code{\RETURN{} $e$;} proceeds as follows:
5672 5074
5673 \LMHash{}
5674 First the expression $e$ is evaluated, producing an object $o$. Next: 5075 First the expression $e$ is evaluated, producing an object $o$. Next:
5675 \begin{itemize} 5076 \begin{itemize}
5676 \item 5077 \item
5677 The current return value is set to $o$ and the current exception (\ref{throw}) a nd active stack trace (\ref{try}) become undefined. 5078 The current return value is set to $o$ and the current exception (\ref{throw}) a nd active stack trace (\ref{try}) become undefined.
5678 \item 5079 \item
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$. 5080 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$.
5680 \item 5081 \item
5681 Otherwise execution of the current method terminates. 5082 Otherwise execution of the current method terminates.
5682 \end{itemize} 5083 \end{itemize}
5683 5084
5684 \commentary{ 5085 \commentary{
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}. 5086 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}.
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. 5087 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.
5687 } 5088 }
5688 5089
5689 \LMHash{}
5690 Let $T$ be the static type of $e$ and let $f$ be the immediately enclosing funct ion. 5090 Let $T$ be the static type of $e$ and let $f$ be the immediately enclosing funct ion.
5691 5091
5692 \LMHash{}
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$. 5092 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$.
5694 5093
5695 \LMHash{}
5696 Let $S$ be the runtime type of $o$. In checked mode: 5094 Let $S$ be the runtime type of $o$. In checked mode:
5697 \begin{itemize} 5095 \begin{itemize}
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$. 5096 \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$.
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$. 5097 \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$.
5700 \end{itemize} 5098 \end{itemize}
5701 5099
5702 \LMHash{}
5703 It is a compile-time error if a return statement of the form \code{\RETURN{} $e$ ;} appears in a generative constructor (\ref{generativeConstructors}). 5100 It is a compile-time error if a return statement of the form \code{\RETURN{} $e$ ;} appears in a generative constructor (\ref{generativeConstructors}).
5704 5101
5705 \rationale{ 5102 \rationale{
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. 5103 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.
5707 } 5104 }
5708 5105
5709 \LMHash{}
5710 It is a compile-time error if a return statement of the form \code{\RETURN{} $e$ ;} appears in a generator function. 5106 It is a compile-time error if a return statement of the form \code{\RETURN{} $e$ ;} appears in a generator function.
5711 5107
5712 \rationale{ 5108 \rationale{
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. 5109 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.
5714 } 5110 }
5715 5111
5716 \LMHash{}
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: 5112 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:
5718 \begin{itemize} 5113 \begin{itemize}
5719 \item $f$ is synchronous and the return type of $f$ may not be assigned to \VOI D{} (\ref{typeVoid}) or, 5114 \item $f$ is synchronous and the return type of $f$ may not be assigned to \VOI D{} (\ref{typeVoid}) or,
5720 \item $f$ is asynchronous and the return type of $f$ may not be assigned to \co de{Future$<$Null$>$}. 5115 \item $f$ is asynchronous and the return type of $f$ may not be assigned to \co de{Future$<$Null$>$}.
5721 \end{itemize} 5116 \end{itemize}
5722 5117
5723 \commentary{ 5118 \commentary{
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. 5119 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.
5725 } 5120 }
5726 \rationale{This helps catch situations where users forget to return a value in a return statement.} 5121 \rationale{This helps catch situations where users forget to return a value in a return statement.}
5727 5122
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.} 5123 \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.}
5729 5124
5730 \LMHash{}
5731 A return statement with no expression, \code{\RETURN;} is executed as follows: 5125 A return statement with no expression, \code{\RETURN;} is executed as follows:
5732 5126
5733 \LMHash{}
5734 If the immediately enclosing function $f$ is a generator, then: 5127 If the immediately enclosing function $f$ is a generator, then:
5735 \begin{itemize} 5128 \begin{itemize}
5736 \item 5129 \item
5737 The current return value is set to \NULL{}. 5130 The current return value is set to \NULL{}.
5738 \item 5131 \item
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$. 5132 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$.
5740 \item 5133 \item
5741 Otherwise, execution of the current method terminates. 5134 Otherwise, execution of the current method terminates.
5742 \end{itemize} 5135 \end{itemize}
5743 5136
5744 \LMHash{}
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{};}. 5137 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{};}.
5746 5138
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{};} 5139 \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{};}
5748 %in a \VOID{} function; neither is it illegal 5140 %in a \VOID{} function; neither is it illegal
5749 in a generative constructor. The rules relate only to the specific syntactic for m \code{\RETURN{} $e$;}. 5141 in a generative constructor. The rules relate only to the specific syntactic for m \code{\RETURN{} $e$;}.
5750 } 5142 }
5751 5143
5752 5144
5753 \rationale{ 5145 \rationale{
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. 5146 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.
5755 5147
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. 5148 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.
5757 } 5149 }
5758 5150
5759 \LMHash{}
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$;}. 5151 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$;}.
5761 5152
5762 5153
5763 5154
5764 5155
5765 \subsection{ Labels} 5156 \subsection{ Labels}
5766 \LMLabel{labels} 5157 \label{labels}
5767 5158
5768 \LMHash{}
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$. 5159 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$.
5770 5160
5771 \rationale{The sole role of labels is to provide targets for the break (\ref{bre ak}) and continue (\ref{continue}) statements.} 5161 \rationale{The sole role of labels is to provide targets for the break (\ref{bre ak}) and continue (\ref{continue}) statements.}
5772 5162
5773 %\Q{Are labels in a separate namespace? Bug 49774299} 5163 %\Q{Are labels in a separate namespace? Bug 49774299}
5774 5164
5775 \begin{grammar} 5165 \begin{grammar}
5776 {\bf label:} 5166 {\bf label:}
5777 identifier `{\escapegrammar :}' 5167 identifier `{\escapegrammar :}'
5778 . 5168 .
5779 \end{grammar} 5169 \end{grammar}
5780 5170
5781 \LMHash{}
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. 5171 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.
5783 5172
5784 \LMHash{}
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$. 5173 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$.
5786 5174
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. 5175 \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.
5788 } 5176 }
5789 5177
5790 5178
5791 \subsection{ Break} 5179 \subsection{ Break}
5792 \LMLabel{break} 5180 \label{break}
5793 5181
5794 \LMHash{}
5795 The {\em break statement} consists of the reserved word \BREAK{} and an optional label (\ref{labels}). 5182 The {\em break statement} consists of the reserved word \BREAK{} and an optional label (\ref{labels}).
5796 5183
5797 \begin{grammar} 5184 \begin{grammar}
5798 {\bf breakStatement:} 5185 {\bf breakStatement:}
5799 \BREAK{} identifier? `{\escapegrammar ;}' 5186 \BREAK{} identifier? `{\escapegrammar ;}'
5800 . 5187 .
5801 \end{grammar} 5188 \end{grammar}
5802 5189
5803 \LMHash{}
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$. 5190 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$.
5805 5191
5806 \LMHash{}
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$. 5192 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$.
5808 5193
5809 5194
5810 5195
5811 \subsection{ Continue} 5196 \subsection{ Continue}
5812 \LMLabel{continue} 5197 \label{continue}
5813 5198
5814 \LMHash{}
5815 The {\em continue statement} consists of the reserved word \CONTINUE{} and an op tional label (\ref{labels}). 5199 The {\em continue statement} consists of the reserved word \CONTINUE{} and an op tional label (\ref{labels}).
5816 5200
5817 \begin{grammar} 5201 \begin{grammar}
5818 {\bf continueStatement:} 5202 {\bf continueStatement:}
5819 \CONTINUE{} identifier? `{\escapegrammar ;}' 5203 \CONTINUE{} identifier? `{\escapegrammar ;}'
5820 . 5204 .
5821 \end{grammar} 5205 \end{grammar}
5822 5206
5823 \LMHash{}
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. 5207 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.
5825 5208
5826 \commentary{ 5209 \commentary{
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. 5210 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.
5828 } 5211 }
5829 5212
5830 \LMHash{}
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$. 5213 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$.
5832 5214
5833 \subsection{ Yield and Yield-Each} 5215 \subsection{ Yield and Yield-Each}
5834 \LMLabel{yieldAndYieldEach} 5216 \label{yieldAndYieldEach}
5835 5217
5836 \subsubsection{ Yield} 5218 \subsubsection{ Yield}
5837 \LMLabel{yield} 5219 \label{yield}
5838 5220
5839 \LMHash{}
5840 The {\em yield statement} adds an element to the result of a generator function (\ref{functions}). 5221 The {\em yield statement} adds an element to the result of a generator function (\ref{functions}).
5841 5222
5842 \begin{grammar} 5223 \begin{grammar}
5843 {\bf yieldStatement:} 5224 {\bf yieldStatement:}
5844 \YIELD{} expression `{\escapegrammar ;}' 5225 \YIELD{} expression `{\escapegrammar ;}'
5845 . 5226 .
5846 \end{grammar} 5227 \end{grammar}
5847 5228
5848 \LMHash{}
5849 Execution of a statement $s$ of the form \code{\YIELD{} $e$;} proceeds as follo ws: 5229 Execution of a statement $s$ of the form \code{\YIELD{} $e$;} proceeds as follo ws:
5850 5230
5851 \LMHash{}
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. 5231 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.
5853 5232
5854 \LMHash{}
5855 Next, $o$ is added to the iterable or stream associated with the immediately enc losing function. 5233 Next, $o$ is added to the iterable or stream associated with the immediately enc losing function.
5856 5234
5857 \LMHash{}
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. 5235 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.
5859 5236
5860 \rationale{ 5237 \rationale{
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. 5238 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.
5862 } 5239 }
5863 5240
5864 \LMHash{}
5865 If the enclosing function $m$ is marked \SYNC* (\ref{functions}) then: 5241 If the enclosing function $m$ is marked \SYNC* (\ref{functions}) then:
5866 \begin{itemize} 5242 \begin{itemize}
5867 \item 5243 \item
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$. 5244 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$.
5869 \item 5245 \item
5870 The current call to \code{moveNext()} returns \TRUE. 5246 The current call to \code{moveNext()} returns \TRUE.
5871 \end{itemize} 5247 \end{itemize}
5872 5248
5873 \LMHash{}
5874 It is a compile-time error if a yield statement appears in a function that is no t a generator function. 5249 It is a compile-time error if a yield statement appears in a function that is no t a generator function.
5875 5250
5876 \LMHash{}
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: 5251 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:
5878 \begin{itemize} 5252 \begin{itemize}
5879 \item 5253 \item
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$. 5254 the body of $f$ is marked \ASYNC* and the type \code{Stream$<$T$>$} may not be assigned to the declared return type of $f$.
5881 \item 5255 \item
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$. 5256 the body of $f$ is marked \SYNC* and the type \code{Iterable$<$T$>$} may not be assigned to the declared return type of $f$.
5883 \end{itemize} 5257 \end{itemize}
5884 5258
5885 5259
5886 \subsubsection{ Yield-Each} 5260 \subsubsection{ Yield-Each}
5887 \LMLabel{yieldEach} 5261 \label{yieldEach}
5888 5262
5889 \LMHash{}
5890 The {\em yield-each statement} adds a series of values to the result of a gener ator function (\ref{functions}). 5263 The {\em yield-each statement} adds a series of values to the result of a gener ator function (\ref{functions}).
5891 5264
5892 \begin{grammar} 5265 \begin{grammar}
5893 {\bf yieldEachStatement:} 5266 {\bf yieldEachStatement:}
5894 \YIELD* expression `{\escapegrammar ;}' 5267 \YIELD* expression `{\escapegrammar ;}'
5895 . 5268 .
5896 \end{grammar} 5269 \end{grammar}
5897 5270
5898 \LMHash{}
5899 Execution of a statement s of the form \code{\YIELD* $e$;} proceeds as follows: 5271 Execution of a statement s of the form \code{\YIELD* $e$;} proceeds as follows:
5900 5272
5901 \LMHash{}
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$: 5273 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$:
5903 \begin{itemize} 5274 \begin{itemize}
5904 \item 5275 \item
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. 5276 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.
5906 \item 5277 \item
5907 $x$ is added to the iterable or stream associated with $m$ in the order it appe ars in $o$. 5278 $x$ is added to the iterable or stream associated with $m$ in the order it appe ars in $o$.
5908 \item 5279 \item
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. 5280 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.
5910 \end{itemize} 5281 \end{itemize}
5911 5282
5912 \LMHash{}
5913 If the enclosing function is marked \SYNC* (\ref{functions}) then: 5283 If the enclosing function is marked \SYNC* (\ref{functions}) then:
5914 \begin{itemize} 5284 \begin{itemize}
5915 \item 5285 \item
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$. 5286 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$.
5917 \item 5287 \item
5918 The current call to \code{moveNext()} returns \TRUE. 5288 The current call to \code{moveNext()} returns \TRUE.
5919 \end{itemize} 5289 \end{itemize}
5920 5290
5921 \LMHash{}
5922 It is a compile-time error if a yield-each statement appears in a function that is not a generator function. 5291 It is a compile-time error if a yield-each statement appears in a function that is not a generator function.
5923 5292
5924 \LMHash{}
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$. 5293 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$.
5926 5294
5927 5295
5928 \subsection{ Assert} 5296 \subsection{ Assert}
5929 \LMLabel{assert} 5297 \label{assert}
5930 5298
5931 \LMHash{}
5932 An {\em assert statement} is used to disrupt normal execution if a given boolean condition does not hold. 5299 An {\em assert statement} is used to disrupt normal execution if a given boolean condition does not hold.
5933 5300
5934 \begin{grammar} 5301 \begin{grammar}
5935 {\bf assertStatement:} 5302 {\bf assertStatement:}
5936 assert `(' conditionalExpression `)' `{\escapegrammar ;}' 5303 assert `(' conditionalExpression `)' `{\escapegrammar ;}'
5937 . 5304 .
5938 \end{grammar} 5305 \end{grammar}
5939 5306
5940 \LMHash{}
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: 5307 The assert statement has no effect in production mode. In checked mode, executio n of an assert statement \code{\ASSERT{}($e$);} proceeds as follows:
5942 5308
5943 \LMHash{}
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$. 5309 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$.
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. 5310 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.
5946 5311
5947 %\Q{Might be cleaner to define it as \code{if (!$e$) \{\THROW{} \NEW{} Assertion Error();\}} (in checked mode only). 5312 %\Q{Might be cleaner to define it as \code{if (!$e$) \{\THROW{} \NEW{} Assertion Error();\}} (in checked mode only).
5948 %What about an error message as part of the assert?} 5313 %What about an error message as part of the assert?}
5949 5314
5950 \LMHash{}
5951 It is a static type warning if the type of $e$ may not be assigned to either \ code{bool} or $() \rightarrow$ \code{bool}. 5315 It is a static type warning if the type of $e$ may not be assigned to either \ code{bool} or $() \rightarrow$ \code{bool}.
5952 5316
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. 5317 \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.
5954 } 5318 }
5955 5319
5956 %If a lexically visible declaration named \code{assert} is in scope, an assert s tatement 5320 %If a lexically visible declaration named \code{assert} is in scope, an assert s tatement
5957 %\code{\ASSERT{} (e); } 5321 %\code{\ASSERT{} (e); }
5958 %is interpreted as an expression statement \code{(assert(e));} . 5322 %is interpreted as an expression statement \code{(assert(e));} .
5959 5323
5960 %\rationale{ 5324 %\rationale{
5961 %Since \ASSERT{} is a built-in identifier, one might define a function or method with this name. 5325 %Since \ASSERT{} is a built-in identifier, one might define a function or method with this name.
5962 %It is impossible to distinguish as \ASSERT{} statement from a method invocation in such a situation. 5326 %It is impossible to distinguish as \ASSERT{} statement from a method invocation in such a situation.
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.,} 5327 %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.,}
5964 5328
5965 %\begin{dartCode} 5329 %\begin{dartCode}
5966 % assert(bool b)\{print('My Personal Assertion \$b');\} 5330 % assert(bool b)\{print('My Personal Assertion \$b');\}
5967 5331
5968 % assert\_puzzler() \{ 5332 % assert\_puzzler() \{
5969 % (assert(\TRUE{})); // prints true 5333 % (assert(\TRUE{})); // prints true
5970 % assert(\TRUE{}); // would do nothing 5334 % assert(\TRUE{}); // would do nothing
5971 % (assert(\FALSE{})); // prints false 5335 % (assert(\FALSE{})); // prints false
5972 % assert(\FALSE{}); // would throw if asserts enabled, or do nothing otherwise 5336 % assert(\FALSE{}); // would throw if asserts enabled, or do nothing otherwise
5973 % \} 5337 % \}
5974 5338
5975 %\end{dartCode} 5339 %\end{dartCode}
5976 5340
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.} 5341 %\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.}
5978 5342
5979 \section{Libraries and Scripts} 5343 \section{Libraries and Scripts}
5980 \LMLabel{librariesAndScripts} 5344 \label{librariesAndScripts}
5981 5345
5982 \LMHash{}
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}). 5346 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}).
5984 5347
5985 \LMHash{}
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$. 5348 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$.
5987 5349
5988 \begin{grammar} 5350 \begin{grammar}
5989 {\bf topLevelDefinition:}classDefinition; 5351 {\bf topLevelDefinition:}classDefinition;
5990 enumType; 5352 enumType;
5991 % classDefinitionOrInterfaceInjection; 5353 % classDefinitionOrInterfaceInjection;
5992 % interfaceDefinitionOrInterfaceInjection; 5354 % interfaceDefinitionOrInterfaceInjection;
5993 % mixinApplication; 5355 % mixinApplication;
5994 typeAlias; 5356 typeAlias;
5995 \EXTERNAL{}? functionSignature `{\escapegrammar ;}'; 5357 \EXTERNAL{}? functionSignature `{\escapegrammar ;}';
(...skipping 30 matching lines...) Expand all
6026 . 5388 .
6027 5389
6028 {\bf libraryName:} 5390 {\bf libraryName:}
6029 metadata \LIBRARY{} identifier (`{\escapegrammar .}' identifier)* `{\escapegr ammar ;}' 5391 metadata \LIBRARY{} identifier (`{\escapegrammar .}' identifier)* `{\escapegr ammar ;}'
6030 . 5392 .
6031 5393
6032 {\bf importOrExport:}libraryImport ; 5394 {\bf importOrExport:}libraryImport ;
6033 libraryExport 5395 libraryExport
6034 \end{grammar} 5396 \end{grammar}
6035 5397
6036 \LMHash{}
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. 5398 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.
6038 5399
6039 \commentary{ 5400 \commentary{
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. 5401 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.
6041 } 5402 }
6042 5403
6043 \LMHash{}
6044 An implicitly named library has the empty string as its name. 5404 An implicitly named library has the empty string as its name.
6045 5405
6046 \rationale{ 5406 \rationale{
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. 5407 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.
6048 } 5408 }
6049 5409
6050 \commentary{ 5410 \commentary{
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. 5411 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.
6052 } 5412 }
6053 5413
6054 \LMHash{}
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. 5414 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.
6056 5415
6057 \LMHash{}
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. 5416 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.
6059 5417
6060 \commentary{Since top level privates are not imported, using the top level priva tes of another library is never possible. } 5418 \commentary{Since top level privates are not imported, using the top level priva tes of another library is never possible. }
6061 5419
6062 \LMHash{}
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$. 5420 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$.
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}). 5421 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}).
6065 5422
6066 5423
6067 \subsection{Imports} 5424 \subsection{Imports}
6068 \LMLabel{imports} 5425 \label{imports}
6069 5426
6070 \LMHash{}
6071 An {\em import} specifies a library to be used in the scope of another library. 5427 An {\em import} specifies a library to be used in the scope of another library.
6072 \begin{grammar} 5428 \begin{grammar}
6073 {\bf libraryImport:} 5429 {\bf libraryImport:}
6074 metadata importSpecification 5430 metadata importSpecification
6075 . 5431 .
6076 5432
6077 {\bf importSpecification:} 5433 {\bf importSpecification:}
6078 \IMPORT{} uri (\AS{} identifier)? combinator* `{\escapegrammar ;}'; 5434 \IMPORT{} uri (\AS{} identifier)? combinator* `{\escapegrammar ;}';
6079 \IMPORT{} uri \DEFERRED{} \AS{} identifier combinator* `{\escapegrammar ; }' 5435 \IMPORT{} uri \DEFERRED{} \AS{} identifier combinator* `{\escapegrammar ; }'
6080 . 5436 .
6081 5437
6082 {\bf combinator:}\SHOW{} identifierList; 5438 {\bf combinator:}\SHOW{} identifierList;
6083 \HIDE{} identifierList 5439 \HIDE{} identifierList
6084 . 5440 .
6085 5441
6086 {\bf identifierList:} 5442 {\bf identifierList:}
6087 identifier (, identifier)* 5443 identifier (, identifier)*
6088 \end{grammar} 5444 \end{grammar}
6089 5445
6090 5446
6091 \LMHash{}
6092 An import specifies a URI $x$ where the declaration of an imported library is to be found. 5447 An import specifies a URI $x$ where the declaration of an imported library is to be found.
6093 5448
6094 \LMHash{}
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. 5449 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.
6096 5450
6097 \LMHash{}
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. 5451 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.
6099 5452
6100 \LMHash{}
6101 It is a static warning if the specified URI of a deferred import does not refer to a library declaration. 5453 It is a static warning if the specified URI of a deferred import does not refer to a library declaration.
6102 5454
6103 \rationale{ 5455 \rationale{
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. 5456 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.
6105 } 5457 }
6106 5458
6107 5459
6108 \LMHash{}
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. 5460 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.
6110 5461
6111 \LMHash{}
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. 5462 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.
6113 5463
6114 \LMHash{}
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{}. 5464 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{}.
6116 5465
6117 \LMHash{}
6118 Let $I$ be an import directive that refers to a URI via the string $s_1$. Evalua tion of $I$ proceeds as follows: 5466 Let $I$ be an import directive that refers to a URI via the string $s_1$. Evalua tion of $I$ proceeds as follows:
6119 5467
6120 \LMHash{} 5468 If $I$ is a deferred import, no evaluation takes place. Instead, a mapping of th e name of the prefix, $p$ to a {\em deferred prefix object} is added to the scop e 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$.
6122 The deferred prefix object has the following methods: 5469 The deferred prefix object has the following methods:
6123 5470
6124 \begin{itemize} 5471 \begin{itemize}
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. 5472 \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.
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. 5473 \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.
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. 5474 \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.
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. 5475 \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.
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. 5476 \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.
6130 \end{itemize} 5477 \end{itemize}
6131 5478
6132 \LMHash{}
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. 5479 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.
6134 5480
6135 \LMHash{}
6136 The effect of a repeated call to \code{$p$.loadLibrary} is as follows: 5481 The effect of a repeated call to \code{$p$.loadLibrary} is as follows:
6137 \begin{itemize} 5482 \begin{itemize}
6138 \item 5483 \item
6139 If another call to \code{$p$.loadLibrary} has already succeeded, the repeated ca ll also succeeds. 5484 If another call to \code{$p$.loadLibrary} has already succeeded, the repeated ca ll also succeeds.
6140 Otherwise, 5485 Otherwise,
6141 \item 5486 \item
6142 If another call to to \code{$p$.loadLibrary} has failed: 5487 If another call to to \code{$p$.loadLibrary} has failed:
6143 \begin{itemize} 5488 \begin{itemize}
6144 \item 5489 \item
6145 If the failure is due to a compilation error, the repeated call fails for the sa me reason. 5490 If the failure is due to a compilation error, the repeated call fails for the sa me reason.
6146 \item 5491 \item
6147 If the failure is due to other causes, the repeated call behaves as if no previo us call had been made. 5492 If the failure is due to other causes, the repeated call behaves as if no previo us call had been made.
6148 \end{itemize} 5493 \end{itemize}
6149 \end{itemize} 5494 \end{itemize}
6150 5495
6151 \commentary{ 5496 \commentary{
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. 5497 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.
6153 5498
6154 We do not specify what value the future returned resolves to. 5499 We do not specify what value the future returned resolves to.
6155 } 5500 }
6156 5501
6157 \LMHash{}
6158 If $I$ is an immediate import then, first 5502 If $I$ is an immediate import then, first
6159 5503
6160 \begin{itemize} 5504 \begin{itemize}
6161 \item 5505 \item
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. 5506 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.
6163 } 5507 }
6164 \item Otherwise, the contents of the URI denoted by $s_1$ have been compiled int o a library $B$ within the current isolate. 5508 \item Otherwise, the contents of the URI denoted by $s_1$ have been compiled int o a library $B$ within the current isolate.
6165 \end{itemize} 5509 \end{itemize}
6166 5510
6167 5511
6168 \LMHash{}
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$: 5512 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$:
6170 \begin{itemize} 5513 \begin{itemize}
6171 \item If $C_i$ is of the form 5514 \item If $C_i$ is of the form
6172 5515
6173 \code{\SHOW{} $id_1, \ldots, id_k$} 5516 \code{\SHOW{} $id_1, \ldots, id_k$}
6174 5517
6175 then let $NS_i = \SHOW{}([id_1, \ldots, id_k], NS_{i-1}$) 5518 then let $NS_i = \SHOW{}([id_1, \ldots, id_k], NS_{i-1}$)
6176 5519
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. 5520 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.
6178 5521
6179 \item If $C_i$ is of the form 5522 \item If $C_i$ is of the form
6180 5523
6181 \code{\HIDE{} $id_1, \ldots, id_k$} 5524 \code{\HIDE{} $id_1, \ldots, id_k$}
6182 5525
6183 then let $NS_i = \HIDE{}([id_1, \ldots, id_k], NS_{i-1}$) 5526 then let $NS_i = \HIDE{}([id_1, \ldots, id_k], NS_{i-1}$)
6184 5527
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. 5528 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.
6186 \end{itemize} 5529 \end{itemize}
6187 5530
6188 \LMHash{}
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: 5531 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:
6190 5532
6191 \begin{itemize} 5533 \begin{itemize}
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$. 5534 \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$.
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$. 5535 \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$.
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$. 5536 \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$.
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$. 5537 \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$.
6196 \end{itemize} 5538 \end{itemize}
6197 5539
6198 \LMHash{}
6199 Otherwise, let $NS = NS_n$. 5540 Otherwise, let $NS = NS_n$.
6200 It is a compile-time error if the current library declares a top-level member na med $p$. 5541 It is a compile-time error if the current library declares a top-level member na med $p$.
6201 5542
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 5543 % 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
6203 % either. After all, p isn't actually available as a stand alone name. 5544 % either. After all, p isn't actually available as a stand alone name.
6204 5545
6205 \LMHash{}
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: 5546 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:
6207 \begin{itemize} 5547 \begin{itemize}
6208 \item 5548 \item
6209 a top-level declaration with the name $k$ exists in $L$, OR 5549 a top-level declaration with the name $k$ exists in $L$, OR
6210 \item a prefix clause of the form \AS{} $k$ is used in $L$. 5550 \item a prefix clause of the form \AS{} $k$ is used in $L$.
6211 \end{itemize} 5551 \end{itemize}
6212 5552
6213 \rationale{The greatly increases the chance that a member can be added to a libr ary without breaking its importers.} 5553 \rationale{The greatly increases the chance that a member can be added to a libr ary without breaking its importers.}
6214 5554
6215 \LMHash{}
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 5555 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
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: 5556 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:
6218 5557
6219 %an import of a system library and an import of a non-system library: 5558 %an import of a system library and an import of a non-system library:
6220 \begin{itemize} 5559 \begin{itemize}
6221 \item The import of $L_1$ is implicitly extended by a \code{\HIDE{} $N$} clause. 5560 \item The import of $L_1$ is implicitly extended by a \code{\HIDE{} $N$} clause.
6222 \item A static warning is issued. 5561 \item A static warning is issued.
6223 \end{itemize} 5562 \end{itemize}
6224 5563
6225 \rationale { 5564 \rationale {
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. 5565 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.
6227 5566
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. 5567 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.
6229 } 5568 }
6230 5569
6231 \LMHash{}
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: 5570 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:
6233 \begin{itemize} 5571 \begin{itemize}
6234 \item A static warning occurs. 5572 \item A static warning occurs.
6235 \item If $N$ is referenced as a function, getter or setter, a \code{NoSuchMethod Error} is thrown. 5573 \item If $N$ is referenced as a function, getter or setter, a \code{NoSuchMethod Error} is thrown.
6236 \item If $N$ is referenced as a type, it is treated as a malformed type. 5574 \item If $N$ is referenced as a type, it is treated as a malformed type.
6237 5575
6238 \end{itemize} 5576 \end{itemize}
6239 5577
6240 \LMHash{}
6241 We say that the namespace $NS$ {\em has been imported into} $L$. 5578 We say that the namespace $NS$ {\em has been imported into} $L$.
6242 5579
6243 \commentary{ 5580 \commentary{
6244 It is neither an error nor a warning if $N$ is introduced by two or more import s but never referred to. 5581 It is neither an error nor a warning if $N$ is introduced by two or more import s but never referred to.
6245 } 5582 }
6246 5583
6247 \rationale{ 5584 \rationale{
6248 The policy above makes libraries more robust in the face of additions made to th eir imports. 5585 The policy above makes libraries more robust in the face of additions made to th eir imports.
6249 5586
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. 5587 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.
6251 5588
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. 5589 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.
6253 5590
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. 5591 %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.
6255 } 5592 }
6256 5593
6257 \LMHash{}
6258 It is a static warning to import two different libraries with the same name. 5594 It is a static warning to import two different libraries with the same name.
6259 5595
6260 \commentary{ 5596 \commentary{
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. 5597 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.
6262 } 5598 }
6263 5599
6264 \commentary{Note that no errors or warnings are given if one hides or shows a na me that is not in a namespace.} 5600 \commentary{Note that no errors or warnings are given if one hides or shows a na me that is not in a namespace.}
6265 \rationale{ 5601 \rationale{
6266 This prevents situations where removing a name from a library would cause breaka ge of a client library. 5602 This prevents situations where removing a name from a library would cause breaka ge of a client library.
6267 } 5603 }
6268 5604
6269 \LMHash{}
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 5605 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
6271 5606
6272 \code{\IMPORT{} `dart:core';} 5607 \code{\IMPORT{} `dart:core';}
6273 5608
6274 unless the importing library explicitly imports \code{dart:core}. 5609 unless the importing library explicitly imports \code{dart:core}.
6275 5610
6276 \commentary{ 5611 \commentary{
6277 Any import of \code{dart:core}, even if restricted via \SHOW{}, \HIDE{} or \AS{} , preempts the automatic import. 5612 Any import of \code{dart:core}, even if restricted via \SHOW{}, \HIDE{} or \AS{} , preempts the automatic import.
6278 } 5613 }
6279 5614
6280 \rationale{ 5615 \rationale{
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. 5616 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.
6282 } 5617 }
6283 5618
6284 \subsection{Exports} 5619 \subsection{Exports}
6285 \LMLabel{exports} 5620 \label{exports}
6286 5621
6287 \LMHash{}
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}. 5622 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}.
6289 5623
6290 \begin{grammar} 5624 \begin{grammar}
6291 {\bf libraryExport:} 5625 {\bf libraryExport:}
6292 metadata \EXPORT{} uri combinator* `{\escapegrammar ;}' 5626 metadata \EXPORT{} uri combinator* `{\escapegrammar ;}'
6293 . 5627 .
6294 \end{grammar} 5628 \end{grammar}
6295 5629
6296 \LMHash{}
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. 5630 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.
6298 5631
6299 \LMHash{}
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. 5632 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.
6301 5633
6302 \LMHash{}
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}. 5634 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}.
6304 5635
6305 \LMHash{}
6306 Let $E$ be an export directive that refers to a URI via the string $s_1$. Evalua tion of $E$ proceeds as follows: 5636 Let $E$ be an export directive that refers to a URI via the string $s_1$. Evalua tion of $E$ proceeds as follows:
6307 5637
6308 \LMHash{}
6309 First, 5638 First,
6310 5639
6311 \begin{itemize} 5640 \begin{itemize}
6312 \item 5641 \item
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$. 5642 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$.
6314 \item Otherwise, the contents of the URI denoted by $s_1$ have been compiled int o a library $B$ within the current isolate. 5643 \item Otherwise, the contents of the URI denoted by $s_1$ have been compiled int o a library $B$ within the current isolate.
6315 \end{itemize} 5644 \end{itemize}
6316 5645
6317 5646
6318 \LMHash{}
6319 Let $NS_0$ be the exported namespace of $B$. Then, for each combinator clause $C _i, i \in 1..n$ in $E$: 5647 Let $NS_0$ be the exported namespace of $B$. Then, for each combinator clause $C _i, i \in 1..n$ in $E$:
6320 \begin{itemize} 5648 \begin{itemize}
6321 \item If $C_i$ is of the form \code{\SHOW{} $id_1, \ldots, id_k$} then let 5649 \item If $C_i$ is of the form \code{\SHOW{} $id_1, \ldots, id_k$} then let
6322 5650
6323 $NS_i = \SHOW{}([id_1, \ldots, id_k], NS_{i-1}$). 5651 $NS_i = \SHOW{}([id_1, \ldots, id_k], NS_{i-1}$).
6324 \item If $C_i$ is of the form \code{\HIDE{} $id_1, \ldots, id_k$} 5652 \item If $C_i$ is of the form \code{\HIDE{} $id_1, \ldots, id_k$}
6325 5653
6326 then let $NS_i = \HIDE{}([id_1, \ldots, id_k], NS_{i-1}$). 5654 then let $NS_i = \HIDE{}([id_1, \ldots, id_k], NS_{i-1}$).
6327 \end{itemize} 5655 \end{itemize}
6328 5656
6329 \LMHash{}
6330 For each 5657 For each
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$. 5658 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$.
6332 5659
6333 \LMHash{}
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: 5660 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:
6335 %an export of a system library and an export of a non-system library: 5661 %an export of a system library and an export of a non-system library:
6336 \begin{itemize} 5662 \begin{itemize}
6337 \item The export of $L_1$ is implicitly extended by a \code{\HIDE{} $N$} clause. 5663 \item The export of $L_1$ is implicitly extended by a \code{\HIDE{} $N$} clause.
6338 \item A static warning is issued. 5664 \item A static warning is issued.
6339 \end{itemize} 5665 \end{itemize}
6340 5666
6341 \rationale{ 5667 \rationale{
6342 See the discussion in section \ref{imports} for the reasoning behind this rule. 5668 See the discussion in section \ref{imports} for the reasoning behind this rule.
6343 } 5669 }
6344 5670
6345 \LMHash{}
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$. 5671 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$.
6347 5672
6348 \LMHash{}
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. 5673 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.
6350 5674
6351 5675
6352 5676
6353 \subsection{Parts} 5677 \subsection{Parts}
6354 \LMLabel{parts} 5678 \label{parts}
6355 5679
6356 \LMHash{}
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. 5680 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.
6358 5681
6359 \LMHash{}
6360 A {\em part directive} specifies a URI where a Dart compilation unit that should be incorporated into the current library may be found. 5682 A {\em part directive} specifies a URI where a Dart compilation unit that should be incorporated into the current library may be found.
6361 5683
6362 \begin{grammar} 5684 \begin{grammar}
6363 {\bf partDirective:} 5685 {\bf partDirective:}
6364 metadata \PART{} uri '{\escapegrammar ;}' 5686 metadata \PART{} uri `{\escapegrammar ;}'
6365 . 5687 .
6366 5688
6367 {\bf partHeader:} 5689 {\bf partHeader:}
6368 metadata \PART{} \OF{} identifier (`{\escapegrammar .}' identifier)* `{\es capegrammar ;}' 5690 metadata \PART{} \OF{} identifier (`{\escapegrammar .}' identifier)* `{\es capegrammar ;}'
6369 . 5691 .
6370 {\bf partDeclaration:} 5692 {\bf partDeclaration:}
6371 partHeader topLevelDefinition* EOF 5693 partHeader topLevelDefinition* EOF
6372 . 5694 .
6373 \end{grammar} 5695 \end{grammar}
6374 5696
6375 \LMHash{}
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. 5697 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.
6377 5698
6378 \LMHash{}
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. 5699 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.
6380 5700
6381 \subsection{Scripts} 5701 \subsection{Scripts}
6382 \LMLabel{scripts} 5702 \label{scripts}
6383 5703
6384 \LMHash{}
6385 A {\em script} is a library whose exported namespace (\ref{exports}) includes a top-level function \code{main}. 5704 A {\em script} is a library whose exported namespace (\ref{exports}) includes a top-level function \code{main}.
6386 A script $S$ may be executed as follows: 5705 A script $S$ may be executed as follows:
6387 5706
6388 \LMHash{}
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: 5707 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:
6390 \begin{enumerate} 5708 \begin{enumerate}
6391 \item An object whose runtime type implements \code{List$<$String$>$}. 5709 \item An object whose runtime type implements \code{List$<$String$>$}.
6392 \item The initial message of the current isolate $i$ as determined by the invoca tion of \code{Isolate.spawnUri} that spawned $i$. 5710 \item The initial message of the current isolate $i$ as determined by the invoca tion of \code{Isolate.spawnUri} that spawned $i$.
6393 \end{enumerate} 5711 \end{enumerate}
6394 5712
6395 \LMHash{}
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. 5713 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.
6397 5714
6398 \commentary { 5715 \commentary {
6399 Note that if \code{main} requires more than two arguments, a run time error will occur. 5716 Note that if \code{main} requires more than two arguments, a run time error will occur.
6400 } 5717 }
6401 5718
6402 \rationale{ 5719 \rationale{
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. 5720 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.
6404 } 5721 }
6405 5722
6406 \commentary { 5723 \commentary {
6407 A Dart program will typically be executed by executing a script. 5724 A Dart program will typically be executed by executing a script.
6408 } 5725 }
6409 5726
6410 \subsection{URIs} 5727 \subsection{URIs}
6411 \LMLabel{uris} 5728 \label{uris}
6412 5729
6413 \LMHash{}
6414 URIs are specified by means of string literals: 5730 URIs are specified by means of string literals:
6415 5731
6416 \begin{grammar} 5732 \begin{grammar}
6417 {\bf uri:} 5733 {\bf uri:}
6418 stringLiteral 5734 stringLiteral
6419 . 5735 .
6420 \end{grammar} 5736 \end{grammar}
6421 5737
6422 \LMHash{}
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. 5738 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.
6424 5739
6425 \LMHash{}
6426 This specification does not discuss the interpretation of URIs, with the followi ng exceptions. 5740 This specification does not discuss the interpretation of URIs, with the followi ng exceptions.
6427 5741
6428 \rationale{ 5742 \rationale{
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. 5743 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.
6430 } 5744 }
6431 5745
6432 \LMHash{}
6433 A URI of the form \code{dart:$s$} is interpreted as a reference to a system libr ary (\ref{imports}) $s$. 5746 A URI of the form \code{dart:$s$} is interpreted as a reference to a system libr ary (\ref{imports}) $s$.
6434 5747
6435 \LMHash{}
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. 5748 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.
6437 5749
6438 \commentary{ 5750 \commentary{
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. 5751 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.
6440 } 5752 }
6441 5753
6442 \rationale{ 5754 \rationale{
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). 5755 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).
6444 } 5756 }
6445 5757
6446 \LMHash{}
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. 5758 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.
6448 5759
6449 \commentary{This means it is dependent on the embedder.} 5760 \commentary{This means it is dependent on the embedder.}
6450 5761
6451 5762
6452 \section{Types} 5763 \section{Types}
6453 \LMLabel{types} 5764 \label{types}
6454 5765
6455 \LMHash{}
6456 Dart supports optional typing based on interface types. 5766 Dart supports optional typing based on interface types.
6457 5767
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. 5768 \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.
6459 } 5769 }
6460 5770
6461 \subsection{Static Types} 5771 \subsection{Static Types}
6462 \LMLabel{staticTypes} 5772 \label{staticTypes}
6463 5773
6464 \LMHash{}
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. 5774 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.
6466 5775
6467 \begin{grammar} 5776 \begin{grammar}
6468 {\bf type:} 5777 {\bf type:}
6469 typeName typeArguments? 5778 typeName typeArguments?
6470 . 5779 .
6471 5780
6472 {\bf typeName:} 5781 {\bf typeName:}
6473 qualified 5782 qualified
6474 . 5783 .
6475 5784
6476 {\bf typeArguments:} 5785 {\bf typeArguments:}
6477 '<' typeList '>' 5786 '<' typeList '>'
6478 . 5787 .
6479 5788
6480 {\bf typeList:} 5789 {\bf typeList:}
6481 type (',' type)* 5790 type (',' type)*
6482 . 5791 .
6483 \end{grammar} 5792 \end{grammar}
6484 5793
6485 \LMHash{}
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: 5794 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:
6487 \begin{itemize} 5795 \begin{itemize}
6488 \item Running the static checker on a program $P$ is not required for compiling and running $P$. 5796 \item Running the static checker on a program $P$ is not required for compiling and running $P$.
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. 5797 \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.
6490 \end{itemize} 5798 \end{itemize}
6491 5799
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. 5800 \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.
6493 } 5801 }
6494 5802
6495 %\Q{Should we do something with respect to non-nullable types?} 5803 %\Q{Should we do something with respect to non-nullable types?}
6496 5804
6497 \LMHash{}
6498 A type $T$ is {\em malformed} iff: 5805 A type $T$ is {\em malformed} iff:
6499 \begin{itemize} 5806 \begin{itemize}
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. 5807 \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.
6501 \item $T$ denotes a type variable in the enclosing lexical scope, but occurs in the signature or body of a static member. 5808 \item $T$ denotes a type variable in the enclosing lexical scope, but occurs in the signature or body of a static member.
6502 \item $T$ is a parameterized type of the form $G<S_1, \ldots , S_n>$, and $G$ i s malformed. 5809 \item $T$ is a parameterized type of the form $G<S_1, \ldots , S_n>$, and $G$ i s malformed.
6503 \item $T$ denotes declarations that were imported from multiple imports clauses. 5810 \item $T$ denotes declarations that were imported from multiple imports clauses.
6504 %Either $G$ or $S_i, i \in 1.. n$ are malformed. 5811 %Either $G$ or $S_i, i \in 1.. n$ are malformed.
6505 % \item $G$ is not a generic type with $n$ type parameters. 5812 % \item $G$ is not a generic type with $n$ type parameters.
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$. 5813 % \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$.
6507 % \end{itemize} 5814 % \end{itemize}
6508 \end{itemize} 5815 \end{itemize}
6509 5816
6510 \LMHash{}
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. 5817 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.
6512 5818
6513 \rationale{ 5819 \rationale{
6514 This ensures that the developer is spared a series of cascading warnings as the malformed type interacts with other types. 5820 This ensures that the developer is spared a series of cascading warnings as the malformed type interacts with other types.
6515 } 5821 }
6516 5822
6517 \LMHash{}
6518 A type $T$ is {\em deferred} iff it is of the form $p.T$ where $p$ is a deferred prefix. 5823 A type $T$ is {\em deferred} iff it is of the form $p.T$ where $p$ is a deferred prefix.
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. 5824 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.
6520 5825
6521 5826
6522 \subsubsection{Type Promotion} 5827 \subsubsection{Type Promotion}
6523 \LMLabel{typePromotion} 5828 \label{typePromotion}
6524 5829
6525 \LMHash{}
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. 5830 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.
6527 5831
6528 \LMHash{}
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}). 5832 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}).
6530 5833
6531 \LMHash{}
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}). 5834 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}).
6533 5835
6534 5836
6535 \subsection{Dynamic Type System} 5837 \subsection{Dynamic Type System}
6536 \LMLabel{dynamicTypeSystem} 5838 \label{dynamicTypeSystem}
6537 5839
6538 \LMHash{}
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. 5840 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.
6540 5841
6541 \commentary{ 5842 \commentary{
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. 5843 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.
6543 5844
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. 5845 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.
6545 5846
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. 5847 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.
6547 5848
6548 } 5849 }
6549 5850
6550 %It is a run-time type error to access an undeclared type outside . 5851 %It is a run-time type error to access an undeclared type outside .
6551 5852
6552 \LMHash{}
6553 %It is a dynamic type error if a malformed type is used in a subtype test. 5853 %It is a dynamic type error if a malformed type is used in a subtype test.
6554 In checked mode, it is a dynamic type error if a deferred, malformed or malbound ed (\ref{parameterizedTypes}) 5854 In checked mode, it is a dynamic type error if a deferred, malformed or malbound ed (\ref{parameterizedTypes})
6555 type is used in a subtype test. 5855 type is used in a subtype test.
6556 5856
6557 %In production mode, an undeclared type is treated as an instance of type \DYNAM IC{}. 5857 %In production mode, an undeclared type is treated as an instance of type \DYNAM IC{}.
6558 5858
6559 \commentary{Consider the following program} 5859 \commentary{Consider the following program}
6560 5860
6561 \begin{dartCode} 5861 \begin{dartCode}
6562 \TYPEDEF{} F(bool x); 5862 \TYPEDEF{} F(bool x);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
6624 bool b = x is I; 5924 bool b = x is I;
6625 \end{dartCode} 5925 \end{dartCode}
6626 5926
6627 \commentary{ 5927 \commentary{
6628 \code{b} is bound to \TRUE, but in checked mode the second line causes a dynamic type error. 5928 \code{b} is bound to \TRUE, but in checked mode the second line causes a dynamic type error.
6629 } 5929 }
6630 5930
6631 5931
6632 5932
6633 \subsection{Type Declarations} 5933 \subsection{Type Declarations}
6634 \LMLabel{typeDeclarations} 5934 \label{typeDeclarations}
6635 5935
6636 \subsubsection{Typedef} 5936 \subsubsection{Typedef}
6637 \LMLabel{typedef} 5937 \label{typedef}
6638 5938
6639 \LMHash{}
6640 A {\em type alias} declares a name for a type expression. 5939 A {\em type alias} declares a name for a type expression.
6641 5940
6642 5941
6643 \begin{grammar} 5942 \begin{grammar}
6644 5943
6645 {\bf typeAlias:} 5944 {\bf typeAlias:}
6646 metadata \TYPEDEF{} typeAliasBody 5945 metadata \TYPEDEF{} typeAliasBody
6647 . 5946 .
6648 5947
6649 {\bf typeAliasBody:} 5948 {\bf typeAliasBody:}
6650 functionTypeAlias 5949 functionTypeAlias
6651 . 5950 .
6652 5951
6653 {\bf functionTypeAlias:} 5952 {\bf functionTypeAlias:}
6654 functionPrefix typeParameters? formalParameterList '{\escapegrammar ;}' 5953 functionPrefix typeParameters? formalParameterList '{\escapegrammar ;}'
6655 . 5954 .
6656 5955
6657 {\bf functionPrefix:} 5956 {\bf functionPrefix:}
6658 returnType? identifier 5957 returnType? identifier
6659 . 5958 .
6660 5959
6661 \end{grammar} 5960 \end{grammar}
6662 5961
6663 \LMHash{}
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{}. 5962 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{}.
6665 5963
6666 \LMHash{}
6667 It is a compile-time error if any default values are specified in the signature of a function type alias. 5964 It is a compile-time error if any default values are specified in the signature of a function type alias.
6668 %A typedef may only refer to itself via the bounds of its generic parameters. 5965 %A typedef may only refer to itself via the bounds of its generic parameters.
6669 Any self reference in a typedef, either directly, or recursively via another ty pedef, is a compile time error. 5966 Any self reference in a typedef, either directly, or recursively via another ty pedef, is a compile time error.
6670 %via a chain of references that does not include a class declaration. 5967 %via a chain of references that does not include a class declaration.
6671 5968
6672 5969
6673 5970
6674 \subsection{Interface Types} 5971 \subsection{Interface Types}
6675 \LMLabel{interfaceTypes} 5972 \label{interfaceTypes}
6676 5973
6677 \LMHash{}
6678 The implicit interface of class $I$ is a direct supertype of the implicit interf ace of class $J$ iff: 5974 The implicit interface of class $I$ is a direct supertype of the implicit interf ace of class $J$ iff:
6679 \begin{itemize} 5975 \begin{itemize}
6680 \item 5976 \item
6681 If $I$ is \code{Object}, and $J$ has no \EXTENDS{} clause% and no interface inje ction declaration has extended $J. 5977 If $I$ is \code{Object}, and $J$ has no \EXTENDS{} clause% and no interface inje ction declaration has extended $J.
6682 \item 5978 \item
6683 If $I$ is listed in the \EXTENDS{} clause of $J$% or an interface injection decl aration has extended $J$ with $I$ 5979 If $I$ is listed in the \EXTENDS{} clause of $J$% or an interface injection decl aration has extended $J$ with $I$
6684 . 5980 .
6685 \item If $I$ is listed in the \IMPLEMENTS{} clause of $J$ 5981 \item If $I$ is listed in the \IMPLEMENTS{} clause of $J$
6686 5982
6687 \item If $I$ is listed in the \WITH{} clause of $J$ 5983 \item If $I$ is listed in the \WITH{} clause of $J$
6688 5984
6689 \item If $J$ is a mixin application (\ref{mixinApplication}) of the mixin of $I$ . 5985 \item If $J$ is a mixin application (\ref{mixinApplication}) of the mixin of $I$ .
6690 \end{itemize} 5986 \end{itemize}
6691 5987
6692 \commentary{ 5988 \commentary{
6693 5989
6694 5990
6695 } 5991 }
6696 5992
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. 5993 %\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.
6698 %} 5994 %}
6699 5995
6700 \LMHash{}
6701 A type $T$ is more specific than a type $S$, written $T << S$, if one of the fo llowing conditions is met: 5996 A type $T$ is more specific than a type $S$, written $T << S$, if one of the fo llowing conditions is met:
6702 \begin{itemize} 5997 \begin{itemize}
6703 \item $T$ is $S$. 5998 \item $T$ is $S$.
6704 \item T is $\bot$. 5999 \item T is $\bot$.
6705 \item S is \DYNAMIC{}. 6000 \item S is \DYNAMIC{}.
6706 \item $S$ is a direct supertype of $T$. 6001 \item $S$ is a direct supertype of $T$.
6707 \item $T$ is a type parameter and $S$ is the upper bound of $T$. 6002 \item $T$ is a type parameter and $S$ is the upper bound of $T$.
6708 \item $T$ is a type parameter and $S$ is \cd{Object}. 6003 \item $T$ is a type parameter and $S$ is \cd{Object}.
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: 6004 \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:
6710 $T_i << S_i, 1 \le i \le n$ 6005 $T_i << S_i, 1 \le i \le n$
6711 \item $T$ and $S$ are both function types, and $T << S$ under the rules of secti on \ref{functionTypes}. 6006 \item $T$ and $S$ are both function types, and $T << S$ under the rules of secti on \ref{functionTypes}.
6712 \item $T$ is a function type and $S$ is \cd{Function}. 6007 \item $T$ is a function type and $S$ is \cd{Function}.
6713 \item $T << U$ and $U << S$. 6008 \item $T << U$ and $U << S$.
6714 \end{itemize} 6009 \end{itemize}
6715 6010
6716 \LMHash{}
6717 $<<$ is a partial order on types. 6011 $<<$ is a partial order on types.
6718 $T$ is a subtype of $S$, written $T <: S$, iff $[\bot/\DYNAMIC{}]T << S$. 6012 $T$ is a subtype of $S$, written $T <: S$, iff $[\bot/\DYNAMIC{}]T << S$.
6719 6013
6720 \rationale{ 6014 \rationale{
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: 6015 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:
6722 $List <: List<String>$ and $List<int> <: List$, but $List<int>$ is not a subtype of $List<String>$. 6016 $List <: List<String>$ and $List<int> <: List$, but $List<int>$ is not a subtype of $List<String>$.
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. 6017 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.
6724 } 6018 }
6725 6019
6726 \LMHash{}
6727 $S$ is a supertype of $T$, written $S :> T$, iff $T$ is a subtype of $S$. 6020 $S$ is a supertype of $T$, written $S :> T$, iff $T$ is a subtype of $S$.
6728 6021
6729 \commentary{The supertypes of an interface are its direct supertypes and their s upertypes. } 6022 \commentary{The supertypes of an interface are its direct supertypes and their s upertypes. }
6730 6023
6731 \LMHash{}
6732 An interface type $T$ may be assigned to a type $S$, written $T \Longleftrighta rrow S$, iff either $T <: S$ or $S <: T$. 6024 An interface type $T$ may be assigned to a type $S$, written $T \Longleftrighta rrow S$, iff either $T <: S$ or $S <: T$.
6733 6025
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. 6026 \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.
6735 6027
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. 6028 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.
6737 } 6029 }
6738 6030
6739 \subsection{Function Types} 6031 \subsection{Function Types}
6740 \LMLabel{functionTypes} 6032 \label{functionTypes}
6741 6033
6742 \LMHash{}
6743 Function types come in two variants: 6034 Function types come in two variants:
6744 \begin{enumerate} 6035 \begin{enumerate}
6745 \item 6036 \item
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$. 6037 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$.
6747 \item 6038 \item
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$. 6039 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$.
6749 \end{enumerate} 6040 \end{enumerate}
6750 6041
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: 6042 %$(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:
6752 %\begin{enumerate} 6043 %\begin{enumerate}
6753 %\item Either 6044 %\item Either
6754 %\begin{itemize} 6045 %\begin{itemize}
6755 %\item $S$ is \VOID{}, Or 6046 %\item $S$ is \VOID{}, Or
6756 %\item $T \Longleftrightarrow S$. 6047 %\item $T \Longleftrightarrow S$.
6757 %\end{itemize} 6048 %\end{itemize}
6758 %\item$ \forall i \in 1 .. n, T_i \Longleftrightarrow S_i$. 6049 %\item$ \forall i \in 1 .. n, T_i \Longleftrightarrow S_i$.
6759 %\end{enumerate} 6050 %\end{enumerate}
6760 6051
6761 \LMHash{}
6762 %A function type $(T_1, \ldots T_n, [T_{n+1} \ldots, T_{n+k}]) \rightarrow T$ i s a subtype of the 6052 %A function type $(T_1, \ldots T_n, [T_{n+1} \ldots, T_{n+k}]) \rightarrow T$ i s a subtype of the
6763 % the line below revises the rule to be more liberal 6053 % the line below revises the rule to be more liberal
6764 A function type $(T_1, \ldots T_{k}, [T_{k+1} \ldots, T_{n+m}]) \rightarrow T$ is a subtype of the 6054 A function type $(T_1, \ldots T_{k}, [T_{k+1} \ldots, T_{n+m}]) \rightarrow T$ is a subtype of the
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: 6055 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:
6766 \begin{enumerate} 6056 \begin{enumerate}
6767 \item Either 6057 \item Either
6768 \begin{itemize} 6058 \begin{itemize}
6769 \item $S$ is \VOID{}, Or 6059 \item $S$ is \VOID{}, Or
6770 \item $T \Longleftrightarrow S$. 6060 \item $T \Longleftrightarrow S$.
6771 \end{itemize} 6061 \end{itemize}
6772 \item $\forall i \in 1 .. n, T_i \Longleftrightarrow S_i$. 6062 \item $\forall i \in 1 .. n, T_i \Longleftrightarrow S_i$.
6773 \end{enumerate} 6063 \end{enumerate}
6774 6064
6775 6065
6776 \LMHash{}
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: 6066 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:
6778 \begin{enumerate} 6067 \begin{enumerate}
6779 \item Either 6068 \item Either
6780 \begin{itemize} 6069 \begin{itemize}
6781 \item $S$ is \VOID{}, Or 6070 \item $S$ is \VOID{}, Or
6782 \item $T \Longleftrightarrow S$. 6071 \item $T \Longleftrightarrow S$.
6783 \end{itemize} 6072 \end{itemize}
6784 \item $\forall i \in 1 .. n, T_i \Longleftrightarrow S_i$. 6073 \item $\forall i \in 1 .. n, T_i \Longleftrightarrow S_i$.
6785 \item $k \ge m$ and $y_i \in \{x_1, \ldots, x_k\}, i \in 1 .. m$. 6074 \item $k \ge m$ and $y_i \in \{x_1, \ldots, x_k\}, i \in 1 .. m$.
6786 %\{x_1, \ldots, x_k\}$ is a superset of $\{y_1, \ldots, y_m\}$. 6075 %\{x_1, \ldots, x_k\}$ is a superset of $\{y_1, \ldots, y_m\}$.
6787 \item For all $y_i \in \{y_1, \ldots, y_m\}, y_i = x_j \Rightarrow T_j \Longlef trightarrow S_i$ 6076 \item For all $y_i \in \{y_1, \ldots, y_m\}, y_i = x_j \Rightarrow T_j \Longlef trightarrow S_i$
6788 \end{enumerate} 6077 \end{enumerate}
6789 6078
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$. 6079 %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$.
6791 6080
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?} 6081 %\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?}
6793 6082
6794 %We write $(T_1, \ldots, T_n) \rightarrow T$ as a shorthand for the type $(T_1, \ldots, T_n, []) \rightarrow T$. 6083 %We write $(T_1, \ldots, T_n) \rightarrow T$ as a shorthand for the type $(T_1, \ldots, T_n, []) \rightarrow T$.
6795 6084
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. 6085 %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.
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$. 6086 % 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$.
6798 6087
6799 \LMHash{}
6800 In addition, the following subtype rules apply: 6088 In addition, the following subtype rules apply:
6801 6089
6802 6090
6803 $(T_1, \ldots, T_n, []) \rightarrow T <: (T_1, \ldots, T_n) \rightarrow T$. 6091 $(T_1, \ldots, T_n, []) \rightarrow T <: (T_1, \ldots, T_n) \rightarrow T$.
6804 6092
6805 $(T_1, \ldots, T_n) \rightarrow T <: (T_1, \ldots, T_n, \{\}) \rightarrow T$. 6093 $(T_1, \ldots, T_n) \rightarrow T <: (T_1, \ldots, T_n, \{\}) \rightarrow T$.
6806 6094
6807 $(T_1, \ldots, T_n, \{\}) \rightarrow T <: (T_1, \ldots, T_n) \rightarrow T$. 6095 $(T_1, \ldots, T_n, \{\}) \rightarrow T <: (T_1, \ldots, T_n) \rightarrow T$.
6808 6096
6809 $(T_1, \ldots, T_n) \rightarrow T <: (T_1, \ldots, T_n, []) \rightarrow T$. 6097 $(T_1, \ldots, T_n) \rightarrow T <: (T_1, \ldots, T_n, []) \rightarrow T$.
6810 6098
6811 \rationale{ 6099 \rationale{
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. 6100 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.
6813 } 6101 }
6814 6102
6815 \LMHash{}
6816 A function type $T$ may be assigned to a function type $S$, written $T \Longlef trightarrow S$, iff $T <: S$. 6103 A function type $T$ may be assigned to a function type $S$, written $T \Longlef trightarrow S$, iff $T <: S$.
6817 6104
6818 \LMHash{}
6819 % ensure that Object and dynamic may be assign dot a function type 6105 % ensure that Object and dynamic may be assign dot a function type
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}. 6106 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}.
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()}. 6107 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()}.
6822 6108
6823 6109
6824 6110
6825 6111
6826 %\commentary{Need to specify how a function values dynamic type is derived from its static signature.} 6112 %\commentary{Need to specify how a function values dynamic type is derived from its static signature.}
6827 6113
6828 \LMHash{}
6829 A function type $(T_1, \ldots T_{k}, [T_{k+1} \ldots, T_{n+m}]) \rightarrow T$ is a more specific than the 6114 A function type $(T_1, \ldots T_{k}, [T_{k+1} \ldots, T_{n+m}]) \rightarrow T$ is a more specific than the
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: 6115 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:
6831 \begin{enumerate} 6116 \begin{enumerate}
6832 \item Either 6117 \item Either
6833 \begin{itemize} 6118 \begin{itemize}
6834 \item $S$ is \VOID{}, Or 6119 \item $S$ is \VOID{}, Or
6835 \item $T << S$. 6120 \item $T << S$.
6836 \end{itemize} 6121 \end{itemize}
6837 \item $\forall i \in 1 .. n, T_i << S_i$. 6122 \item $\forall i \in 1 .. n, T_i << S_i$.
6838 \end{enumerate} 6123 \end{enumerate}
6839 6124
6840 6125
6841 \LMHash{}
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: 6126 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:
6843 \begin{enumerate} 6127 \begin{enumerate}
6844 \item Either 6128 \item Either
6845 \begin{itemize} 6129 \begin{itemize}
6846 \item $S$ is \VOID{}, Or 6130 \item $S$ is \VOID{}, Or
6847 \item $T << S$. 6131 \item $T << S$.
6848 \end{itemize} 6132 \end{itemize}
6849 \item $\forall i \in 1 .. n, T_i << S_i$. 6133 \item $\forall i \in 1 .. n, T_i << S_i$.
6850 \item $k \ge m$ and $y_i \in \{x_1, \ldots, x_k\}, i \in 1 .. m$. 6134 \item $k \ge m$ and $y_i \in \{x_1, \ldots, x_k\}, i \in 1 .. m$.
6851 %\{x_1, \ldots, x_k\}$ is a superset of $\{y_1, \ldots, y_m\}$. 6135 %\{x_1, \ldots, x_k\}$ is a superset of $\{y_1, \ldots, y_m\}$.
6852 \item For all $y_i \in \{y_1, \ldots, y_m\}, y_i = x_j \Rightarrow T_j << S_i$ 6136 \item For all $y_i \in \{y_1, \ldots, y_m\}, y_i = x_j \Rightarrow T_j << S_i$
6853 \end{enumerate} 6137 \end{enumerate}
6854 6138
6855 \LMHash{}
6856 Furthermore, if $F$ is a function type, $F << \code{Function}$. 6139 Furthermore, if $F$ is a function type, $F << \code{Function}$.
6857 6140
6858 6141
6859 \subsection{Type \DYNAMIC{}} 6142 \subsection{Type \DYNAMIC{}}
6860 \LMLabel{typeDynamic} 6143 \label{typeDynamic}
6861 6144
6862 \LMHash{}
6863 The type \DYNAMIC{} denotes the unknown type. 6145 The type \DYNAMIC{} denotes the unknown type.
6864 6146
6865 \LMHash{}
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. 6147 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.
6867 6148
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{}>$. 6149 \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{}>$.
6869 } 6150 }
6870 6151
6871 \LMHash{}
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{}. 6152 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{}.
6873 Type \DYNAMIC{} has properties for every possible identifier. These properties all have type \DYNAMIC{}. 6153 Type \DYNAMIC{} has properties for every possible identifier. These properties all have type \DYNAMIC{}.
6874 6154
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. 6155 \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.
6876 6156
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: 6157 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:
6878 6158
6879 (1) \code{typedAPI(G\lt{String}\gt g)\{...\}} 6159 (1) \code{typedAPI(G\lt{String}\gt g)\{...\}}
6880 6160
6881 6161
6882 (2) \code{typedAPI(new G()); } 6162 (2) \code{typedAPI(new G()); }
6883 6163
6884 6164
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 6165 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
6886 6166
6887 (3) \code{typedAPI(new G\lt{String}\gt());} 6167 (3) \code{typedAPI(new G\lt{String}\gt());}
6888 6168
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. 6169 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.
6890 6170
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. 6171 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.
6892 } 6172 }
6893 6173
6894 \LMHash{}
6895 The name \DYNAMIC{} denotes a \cd{Type} object even though \DYNAMIC{} is not a c lass. 6174 The name \DYNAMIC{} denotes a \cd{Type} object even though \DYNAMIC{} is not a c lass.
6896 6175
6897 %\rationale { 6176 %\rationale {
6898 %Type objects reify the runtime types of instances. No instance ever has type \D YNAMIC{}. 6177 %Type objects reify the runtime types of instances. No instance ever has type \D YNAMIC{}.
6899 %} 6178 %}
6900 6179
6901 \subsection{Type Void} 6180 \subsection{Type Void}
6902 \LMLabel{typeVoid} 6181 \label{typeVoid}
6903 6182
6904 \LMHash{}
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. 6183 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.
6906 6184
6907 \commentary{ 6185 \commentary{
6908 For example, as a type argument, or as the type of a variable or parameter 6186 For example, as a type argument, or as the type of a variable or parameter
6909 6187
6910 Void is not an interface type. 6188 Void is not an interface type.
6911 6189
6912 The only subtype relations that pertain to void are therefore: 6190 The only subtype relations that pertain to void are therefore:
6913 \begin{itemize} 6191 \begin{itemize}
6914 \item 6192 \item
(...skipping 14 matching lines...) Expand all
6929 \commentary {The name \VOID{} does not denote a \cd{Type} object.} 6207 \commentary {The name \VOID{} does not denote a \cd{Type} object.}
6930 6208
6931 \rationale { 6209 \rationale {
6932 It is syntacticly illegal to use \VOID{} as an expression, and it would make no sense to do so. 6210 It is syntacticly illegal to use \VOID{} as an expression, and it would make no sense to do so.
6933 Type objects reify the runtime types of instances. No instance ever has type \VO ID{}. 6211 Type objects reify the runtime types of instances. No instance ever has type \VO ID{}.
6934 } 6212 }
6935 6213
6936 6214
6937 6215
6938 \subsection{Parameterized Types} 6216 \subsection{Parameterized Types}
6939 \LMLabel{parameterizedTypes} 6217 \label{parameterizedTypes}
6940 6218
6941 \LMHash{}
6942 A {\em parameterized type} is an invocation of a generic type declaration. 6219 A {\em parameterized type} is an invocation of a generic type declaration.
6943 6220
6944 \LMHash{}
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{}. 6221 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{}.
6946 6222
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. 6223 \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.
6948 } 6224 }
6949 6225
6950 \LMHash{}
6951 Otherwise, let 6226 Otherwise, let
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$. 6227 $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$.
6953 6228
6954 \commentary{ 6229 \commentary{
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}. 6230 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}.
6956 } 6231 }
6957 6232
6958 \LMHash{}
6959 Any use of a malbounded type gives rise to a static warning. 6233 Any use of a malbounded type gives rise to a static warning.
6960 6234
6961 \LMHash{}
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 . 6235 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 .
6963 6236
6964 6237
6965 6238
6966 6239
6967 6240
6968 \subsubsection{Actual Type of Declaration} 6241 \subsubsection{Actual Type of Declaration}
6969 \LMLabel{actualTypeOfADeclaration} 6242 \label{actualTypeOfADeclaration}
6970 6243
6971 \LMHash{}
6972 A type $T$ {\em depends on a type parameter} $U$ iff: 6244 A type $T$ {\em depends on a type parameter} $U$ iff:
6973 \begin{itemize} 6245 \begin{itemize}
6974 \item $T$ is $U$. 6246 \item $T$ is $U$.
6975 \item $T$ is a parameterized type, and one of the type arguments of $T$ depends on $U$. 6247 \item $T$ is a parameterized type, and one of the type arguments of $T$ depends on $U$.
6976 \end{itemize} 6248 \end{itemize}
6977 6249
6978 \LMHash{}
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 6250 Let $T$ be the declared type of a declaration $d$, as it appears in the program source. The {\em actual type} of $d$ is
6980 6251
6981 \begin{itemize} 6252 \begin{itemize}
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$. 6253 \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$.
6983 \item $T$ otherwise. 6254 \item $T$ otherwise.
6984 \end{itemize} 6255 \end{itemize}
6985 6256
6986 \subsubsection{Least Upper Bounds} 6257 \subsubsection{Least Upper Bounds}
6987 \LMLabel{leastUpperBounds} 6258 \label{leastUpperBounds}
6988 6259
6989 \LMHash{}
6990 % does this diverge in some cases? 6260 % does this diverge in some cases?
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$, 6261 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$,
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$. 6262 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$.
6993 6263
6994 \LMHash{}
6995 The least upper bound of \DYNAMIC{} and any type $T$ is \DYNAMIC{}. 6264 The least upper bound of \DYNAMIC{} and any type $T$ is \DYNAMIC{}.
6996 The least upper bound of \VOID{} and any type $T \ne \DYNAMIC{}$ is \VOID{}. 6265 The least upper bound of \VOID{} and any type $T \ne \DYNAMIC{}$ is \VOID{}.
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$. 6266 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$.
6998 6267
6999 \LMHash{}
7000 The least upper bound relation is symmetric and reflexive. 6268 The least upper bound relation is symmetric and reflexive.
7001 6269
7002 % Function types 6270 % Function types
7003 6271
7004 \LMHash{}
7005 The least upper bound of a function type and an interface type $T$ is the least upper bound of \cd{Function} and $T$. 6272 The least upper bound of a function type and an interface type $T$ is the least upper bound of \cd{Function} and $T$.
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: 6273 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:
7007 \begin{itemize} 6274 \begin{itemize}
7008 \item If 6275 \item If
7009 6276
7010 $F= (T_1 \ldots T_r, [T_{r+1}, \ldots, T_n]) \longrightarrow T_0$, 6277 $F= (T_1 \ldots T_r, [T_{r+1}, \ldots, T_n]) \longrightarrow T_0$,
7011 6278
7012 $G= (S_1 \ldots S_r, [S_{r+1}, \ldots, S_k]) \longrightarrow S_0$ 6279 $G= (S_1 \ldots S_r, [S_{r+1}, \ldots, S_k]) \longrightarrow S_0$
7013 6280
7014 where $k \le n$ then the least upper bound of $F$ and $G$ is 6281 where $k \le n$ then the least upper bound of $F$ and $G$ is
(...skipping 22 matching lines...) Expand all
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 6304 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
7038 the least upper bound of $F$ and $G$ is 6305 the least upper bound of $F$ and $G$ is
7039 6306
7040 $(L_1 \ldots L_r, \{ X_m$ $x_m, \ldots, X_n$ $x_n\}) \longrightarrow L_0$ 6307 $(L_1 \ldots L_r, \{ X_m$ $x_m, \ldots, X_n$ $x_n\}) \longrightarrow L_0$
7041 6308
7042 where $L_i$ is the least upper bound of $T_i$ and $S_i, i \in 0..r$ 6309 where $L_i$ is the least upper bound of $T_i$ and $S_i, i \in 0..r$
7043 \end{itemize} 6310 \end{itemize}
7044 6311
7045 6312
7046 \section{Reference} 6313 \section{Reference}
7047 \LMLabel{reference} 6314 \label{reference}
7048 6315
7049 \subsection{Lexical Rules} 6316 \subsection{Lexical Rules}
7050 \LMLabel{lexicalRules} 6317 \label{lexicalRules}
7051 6318
7052 \LMHash{}
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. 6319 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.
7054 6320
7055 \subsubsection{Reserved Words} 6321 \subsubsection{Reserved Words}
7056 \LMLabel{reservedWords} 6322 \label{reservedWords}
7057 6323
7058 \LMHash{}
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. 6324 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.
7060 6325
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{}. 6326 \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{}.
7062 6327
7063 6328
7064 6329
7065 %\Q{Unicode characters.} 6330 %\Q{Unicode characters.}
7066 6331
7067 \begin{grammar} 6332 \begin{grammar}
7068 {\bf LETTER:}`a' {\escapegrammar ..} `z'; 6333 {\bf LETTER:}`a' {\escapegrammar ..} `z';
7069 `A' {\escapegrammar ..}`Z' 6334 `A' {\escapegrammar ..}`Z'
7070 . 6335 .
7071 6336
7072 {\bf DIGIT:} 6337 {\bf DIGIT:}
7073 `0' {\escapegrammar ..} `9' 6338 `0' {\escapegrammar ..} `9'
7074 . 6339 .
7075 6340
7076 {\bf WHITESPACE:} 6341 {\bf WHITESPACE:}
7077 (`$\backslash$t' $|$ ` ' $|$ NEWLINE)+ 6342 (`$\backslash$t' $|$ ` ' $|$ NEWLINE)+
7078 . 6343 .
7079 \end{grammar} 6344 \end{grammar}
7080 6345
7081 \subsubsection{Comments} 6346 \subsubsection{Comments}
7082 \LMLabel{comments} 6347 \label{comments}
7083 6348
7084 \LMHash{}
7085 {\em Comments} are sections of program text that are used for documentation. 6349 {\em Comments} are sections of program text that are used for documentation.
7086 6350
7087 \begin{grammar}{\bf SINGLE\_LINE\_COMMENT:} 6351 \begin{grammar}{\bf SINGLE\_LINE\_COMMENT:}
7088 `//' \~{}(NEWLINE)* (NEWLINE)? 6352 `//' \~{}(NEWLINE)* (NEWLINE)?
7089 . 6353 .
7090 6354
7091 {\bf MULTI\_LINE\_COMMENT:} 6355 {\bf MULTI\_LINE\_COMMENT:}
7092 `/*' (MULTI\_LINE\_COMMENT $|$ \~{} `*/')* `*/' 6356 `/*' (MULTI\_LINE\_COMMENT $|$ \~{} `*/')* `*/'
7093 . 6357 .
7094 \end{grammar} 6358 \end{grammar}
7095 6359
7096 \LMHash{}
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. . 6360 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. .
7098 6361
7099 \LMHash{}
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. 6362 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.
7101 6363
7102 \LMHash{}
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. 6364 {\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.
7104 6365
7105 \LMHash{}
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. 6366 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.
7107 6367
7108 \LMHash{}
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. 6368 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.
7110 6369
7111 \LMHash{}
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 . 6370 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 .
7113 6371
7114 6372
7115 6373
7116 6374
7117 6375
7118 %\subsection{Grammar} 6376 %\subsection{Grammar}
7119 \subsection{Operator Precedence} 6377 \subsection{Operator Precedence}
7120 \LMLabel{operatorPrecedence} 6378 \label{operatorPrecedence}
7121 6379
7122 \LMHash{}
7123 Operator precedence is given implicitly by the grammar. 6380 Operator precedence is given implicitly by the grammar.
7124 6381
7125 \commentary{The following non-normative table may be helpful 6382 \commentary{The following non-normative table may be helpful
7126 \newline 6383 \newline
7127 6384
7128 \begin{tabular}{| r | r | r | r |} 6385 \begin{tabular}{| r | r | r | r |}
7129 \hline 6386 \hline
7130 Description & Operator & Associativity & Precedence \\ 6387 Description & Operator & Associativity & Precedence \\
7131 \hline 6388 \hline
7132 Unary postfix & ., e++, e--, e1[e2], e1() , () & None & 15 \\ 6389 Unary postfix & ., e++, e--, e1[e2], e1() , () & None & 15 \\
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
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. 6430 \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.
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 6431 \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
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. 6432 \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.
7176 \item The names of type variables are short (preferably single letter). Examples : T, S, K, V , E. 6433 \item The names of type variables are short (preferably single letter). Examples : T, S, K, V , E.
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. 6434 \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.
7178 \end{itemize} 6435 \end{itemize}
7179 } 6436 }
7180 6437
7181 6438
7182 \end{document} 6439 \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 | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698