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

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

Issue 722573003: Recovered \LM.. commands (Closed) Base URL: https://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}
3 \usepackage{dart} 4 \usepackage{dart}
4 \usepackage{bnf} 5 \usepackage{bnf}
5 \usepackage{hyperref} 6 \usepackage{hyperref}
7 \usepackage{lmodern}
6 \newcommand{\code}[1]{{\sf #1}} 8 \newcommand{\code}[1]{{\sf #1}}
7 \title{Dart Programming Language Specification \\ 9 \title{Dart Programming Language Specification \\
8 {\large Version 1.6}} 10 {\large Version 1.6}}
9 %\author{The Dart Team} 11 %\author{The Dart Team}
12
13 % For information about Location Markers (and in particular the
14 % commands \LMHash and \LMLabel), see the long comment at the
15 % end of this file.
16
10 \begin{document} 17 \begin{document}
11 \maketitle 18 \maketitle
12 \tableofcontents 19 \tableofcontents
13 20
14 21
15 \newpage 22 \newpage
16 23
17 \pagestyle{myheadings} 24 \pagestyle{myheadings}
18 \markright{Dart Programming Language Specification} 25 \markright{Dart Programming Language Specification}
19 26
20 % begin Ecma boilerplate 27 % begin Ecma boilerplate
21 \section{Scope} 28 \section{Scope}
22 \label{ecmaScope} 29 \LMLabel{ecmaScope}
23 30
31 \LMHash{}
24 This Ecma standard specifies the syntax and semantics of the Dart programming la nguage. It does not specify the APIs of the Dart libraries except where those l ibrary elements are essential to the correct functioning of the language itself (e.g., the existence of class \cd{Object} with methods such as \cd{noSuchMethod} , \cd{runtimeType}). 32 This Ecma standard specifies the syntax and semantics of the Dart programming la nguage. It does not specify the APIs of the Dart libraries except where those l ibrary elements are essential to the correct functioning of the language itself (e.g., the existence of class \cd{Object} with methods such as \cd{noSuchMethod} , \cd{runtimeType}).
25 33
26 \section{Conformance} 34 \section{Conformance}
27 \label{ecmaConformance} 35 \LMLabel{ecmaConformance}
28 36
37 \LMHash{}
29 A conforming implementation of the Dart programming language must provide and s upport all the APIs (libraries, types, functions, getters, setters, whether top -level, static, instance or local) mandated in this specification. 38 A conforming implementation of the Dart programming language must provide and s upport all the APIs (libraries, types, functions, getters, setters, whether top -level, static, instance or local) mandated in this specification.
30 39
40 \LMHash{}
31 A conforming implementation is permitted to provide additional APIs, but not add itional syntax. 41 A conforming implementation is permitted to provide additional APIs, but not add itional syntax.
32 42
33 % A claim of conformance with this Ecma Standard shall specify? 43 % A claim of conformance with this Ecma Standard shall specify?
34 44
35 \section{Normative References} 45 \section{Normative References}
36 \label{ecmaNormativeReferences} 46 \LMLabel{ecmaNormativeReferences}
37 47
48 \LMHash{}
38 The following referenced documents are indispensable for the application of this document. For dated references, only the edition cited applies. For undated ref erences, the latest edition of the referenced document (including any amendments ) applies. 49 The following referenced documents are indispensable for the application of this document. For dated references, only the edition cited applies. For undated ref erences, the latest edition of the referenced document (including any amendments ) applies.
39 50
40 \begin{enumerate} 51 \begin{enumerate}
41 \item 52 \item
42 The Unicode Standard, Version 5.0, as amended by Unicode 5.1.0, or successor. 53 The Unicode Standard, Version 5.0, as amended by Unicode 5.1.0, or successor.
43 \item 54 \item
44 Dart API Reference, https://api.dartlang.org/ 55 Dart API Reference, https://api.dartlang.org/
45 \end{enumerate} 56 \end{enumerate}
46 57
47 58
48 \section{Terms and Definitions} 59 \section{Terms and Definitions}
49 \label{ecmaTermsAndDefinitions} 60 \LMLabel{ecmaTermsAndDefinitions}
50 61
62 \LMHash{}
51 Terms and definitions used in this specification are given in the body of the sp ecification proper. Such terms are highlighted in italics when they are introduc ed, e.g., `we use the term {\em verbosity} to refer to the property of excess ve rbiage'. 63 Terms and definitions used in this specification are given in the body of the sp ecification proper. Such terms are highlighted in italics when they are introduc ed, e.g., `we use the term {\em verbosity} to refer to the property of excess ve rbiage'.
52 % End Ecma Boilerplate 64 % End Ecma Boilerplate
53 65
54 66
55 \section{Notation} 67 \section{Notation}
56 \label{notation} 68 \LMLabel{notation}
57 69
70 \LMHash{}
58 We distinguish between normative and non-normative text. Normative text defines the rules of Dart. It is given in this font. At this time, non-normative text in cludes: 71 We distinguish between normative and non-normative text. Normative text defines the rules of Dart. It is given in this font. At this time, non-normative text in cludes:
59 \begin{itemize} 72 \begin{itemize}
60 \item[Rationale] Discussion of the motivation for language design decisions appe ars in italics. \rationale{Distinguishing normative from non-normative helps cla rify what part of the text is binding and what part is merely expository.} 73 \item[Rationale] Discussion of the motivation for language design decisions appe ars in italics. \rationale{Distinguishing normative from non-normative helps cla rify what part of the text is binding and what part is merely expository.}
61 \item[Commentary] Comments such as ``\commentary{The careful reader will have n oticed that the name Dart has four characters}'' serve to illustrate or clarify the specification, but are redundant with the normative text. \commentary{The d ifference between commentary and rationale can be subtle.} \rationale{ Commentar y is more general than rationale, and may include illustrative examples or clari fications. } 74 \item[Commentary] Comments such as ``\commentary{The careful reader will have n oticed that the name Dart has four characters}'' serve to illustrate or clarify the specification, but are redundant with the normative text. \commentary{The d ifference between commentary and rationale can be subtle.} \rationale{ Commentar y is more general than rationale, and may include illustrative examples or clari fications. }
62 \item[Open questions] (\Q{in this font}). Open questions are points that are uns ettled in the mind of the author(s) of the specification; expect them (the quest ions, not the authors; precision is important in a specification) to be eliminat ed in the final specification. \Q{Should the text at the end of the previous bul let be rationale or commentary?} 75 \item[Open questions] (\Q{in this font}). Open questions are points that are uns ettled in the mind of the author(s) of the specification; expect them (the quest ions, not the authors; precision is important in a specification) to be eliminat ed in the final specification. \Q{Should the text at the end of the previous bul let be rationale or commentary?}
63 \end{itemize} 76 \end{itemize}
64 77
78 \LMHash{}
65 Reserved words and built-in identifiers (\ref{identifierReference}) appear in { \bf bold}. 79 Reserved words and built-in identifiers (\ref{identifierReference}) appear in { \bf bold}.
66 80
67 \commentary{ 81 \commentary{
68 Examples would be \SWITCH{} or \CLASS{}. 82 Examples would be \SWITCH{} or \CLASS{}.
69 } 83 }
70 84
71 85
86 \LMHash{}
72 Grammar productions are given in a common variant of EBNF. The left hand side o f a production ends with a colon. On the right hand side, alternation is repres ented by vertical bars, and sequencing by spacing. As in PEGs, alternation give s priority to the left. Optional elements of a production are suffixed by a ques tion mark like so: \code{anElephant?}. Appending a star to an element of a prod uction means it may be repeated zero or more times. Appending a plus sign to a production means it occurs one or more times. Parentheses are used for grouping. Negation is represented by prefixing an element of a production with a tilde. Negation is similar to the not combinator of PEGs, but it consumes input if it m atches. In the context of a lexical production it consumes a single character if there is one; otherwise, a single token if there is one. 87 Grammar productions are given in a common variant of EBNF. The left hand side o f a production ends with a colon. On the right hand side, alternation is repres ented by vertical bars, and sequencing by spacing. As in PEGs, alternation give s priority to the left. Optional elements of a production are suffixed by a ques tion mark like so: \code{anElephant?}. Appending a star to an element of a prod uction means it may be repeated zero or more times. Appending a plus sign to a production means it occurs one or more times. Parentheses are used for grouping. Negation is represented by prefixing an element of a production with a tilde. Negation is similar to the not combinator of PEGs, but it consumes input if it m atches. In the context of a lexical production it consumes a single character if there is one; otherwise, a single token if there is one.
73 88
74 \commentary{ An example would be:} 89 \commentary{ An example would be:}
75 90
76 \begin{grammar} 91 \begin{grammar}
77 {\sf 92 {\sf
78 {\bf AProduction:}AnAlternative; 93 {\bf AProduction:}AnAlternative;
79 AnotherAlternative; 94 AnotherAlternative;
80 OneThing After Another; 95 OneThing After Another;
81 ZeroOrMoreThings*; 96 ZeroOrMoreThings*;
82 OneOrMoreThings+; 97 OneOrMoreThings+;
83 AnOptionalThing?; 98 AnOptionalThing?;
84 (Some Grouped Things); 99 (Some Grouped Things);
85 \~{}NotAThing; 100 \~{}NotAThing;
86 A\_LEXICAL\_THING 101 A\_LEXICAL\_THING
87 . 102 .
88 } 103 }
89 \end{grammar} 104 \end{grammar}
90 105
91 % need a match anything or a production that does that, so we can correct bugs w rt use 106 % need a match anything or a production that does that, so we can correct bugs w rt use
92 % ~. ~ does not actually parse stuff - it just looks ahead and checks. To get th e effect of 107 % ~. ~ does not actually parse stuff - it just looks ahead and checks. To get th e effect of
93 % parsing anything but X, one needs ~X ANYTHING, not just ~X. There are bugs in the 108 % parsing anything but X, one needs ~X ANYTHING, not just ~X. There are bugs in the
94 % grammar related to this. 109 % grammar related to this.
95 % The alternative is to define ~X as anything but X, or to introduce an anthingB ut(X) 110 % The alternative is to define ~X as anything but X, or to introduce an anthingB ut(X)
96 % combinator, such as !X 111 % combinator, such as !X
97 112
113 \LMHash{}
98 Both syntactic and lexical productions are represented this way. Lexical product ions are distinguished by their names. The names of lexical productions consist exclusively of upper case characters and underscores. As always, within grammat ical productions, whitespace and comments between elements of the production are implicitly ignored unless stated otherwise. 114 Both syntactic and lexical productions are represented this way. Lexical product ions are distinguished by their names. The names of lexical productions consist exclusively of upper case characters and underscores. As always, within grammat ical productions, whitespace and comments between elements of the production are implicitly ignored unless stated otherwise.
99 Punctuation tokens appear in quotes. 115 Punctuation tokens appear in quotes.
100 116
117 \LMHash{}
101 Productions are embedded, as much as possible, in the discussion of the construc ts they represent. 118 Productions are embedded, as much as possible, in the discussion of the construc ts they represent.
102 119
120 \LMHash{}
103 A list $x_1, \ldots, x_n$ denotes any list of $n$ elements of the form $x_i, 1 \ le i \le n$. Note that $n$ may be zero, in which case the list is empty. We use such lists extensively throughout this specification. 121 A list $x_1, \ldots, x_n$ denotes any list of $n$ elements of the form $x_i, 1 \ le i \le n$. Note that $n$ may be zero, in which case the list is empty. We use such lists extensively throughout this specification.
104 122
123 \LMHash{}
105 The notation $[x_1, \ldots, x_n/y_1, \ldots, y_n]E$ denotes a copy of $E$ in whi ch all occurrences of $y_i, 1 \le i \le n$ have been replaced with $x_i$. 124 The notation $[x_1, \ldots, x_n/y_1, \ldots, y_n]E$ denotes a copy of $E$ in whi ch all occurrences of $y_i, 1 \le i \le n$ have been replaced with $x_i$.
106 125
126 \LMHash{}
107 We sometimes abuse list or map literal syntax, writing $[o_1, \ldots, o_n]$ (re spectively $\{k_1: o_1, \ldots, k_n: o_n\}$) where the $o_i$ and $k_i$ may be ob jects rather than expressions. The intent is to denote a list (respectively map) object whose elements are the $o_i$ (respectively, whose keys are the $k_i$ and values are the $o_i$). 127 We sometimes abuse list or map literal syntax, writing $[o_1, \ldots, o_n]$ (re spectively $\{k_1: o_1, \ldots, k_n: o_n\}$) where the $o_i$ and $k_i$ may be ob jects rather than expressions. The intent is to denote a list (respectively map) object whose elements are the $o_i$ (respectively, whose keys are the $k_i$ and values are the $o_i$).
108 128
129 \LMHash{}
109 The specifications of operators often involve statements such as $x$ $op$ $y$ is equivalent to the method invocation $x.op(y)$. Such specifications should be un derstood as a shorthand for: 130 The specifications of operators often involve statements such as $x$ $op$ $y$ is equivalent to the method invocation $x.op(y)$. Such specifications should be un derstood as a shorthand for:
110 \begin{itemize} 131 \begin{itemize}
111 \item 132 \item
112 $x$ $op$ $y$ is equivalent to the method invocation $x.op^\prime(y)$, assuming the class of $x$ actually declared a non-operator method named $op^\prime$ defin ing the same function as the operator $op$. 133 $x$ $op$ $y$ is equivalent to the method invocation $x.op^\prime(y)$, assuming the class of $x$ actually declared a non-operator method named $op^\prime$ defin ing the same function as the operator $op$.
113 \end{itemize} 134 \end{itemize}
114 135
115 \rationale{This circumlocution is required because x.op(y), where op is an oper ator, is not legal syntax. However, it is painfully verbose, and we prefer to st ate this rule once here, and use a concise and clear notation across the specifi cation. 136 \rationale{This circumlocution is required because x.op(y), where op is an oper ator, is not legal syntax. However, it is painfully verbose, and we prefer to st ate this rule once here, and use a concise and clear notation across the specifi cation.
116 } 137 }
117 138
139 \LMHash{}
118 When the specification refers to the order given in the program, it means the or der of the program source code text, scanning left-to-right and top-to-bottom. 140 When the specification refers to the order given in the program, it means the or der of the program source code text, scanning left-to-right and top-to-bottom.
119 141
142 \LMHash{}
120 References to otherwise unspecified names of program entities (such as classes o r functions) are interpreted as the names of members of the Dart core library. 143 References to otherwise unspecified names of program entities (such as classes o r functions) are interpreted as the names of members of the Dart core library.
121 144
122 \commentary{ 145 \commentary{
123 Examples would be the classes \code{Object} and \code{Type} representing the roo t of the class hierarchy and the reification of runtime types respectively. 146 Examples would be the classes \code{Object} and \code{Type} representing the roo t of the class hierarchy and the reification of runtime types respectively.
124 } 147 }
125 148
126 \section{Overview} 149 \section{Overview}
127 \label{overview} 150 \LMLabel{overview}
128 151
152 \LMHash{}
129 Dart is a class-based, single-inheritance, pure object-oriented programming lang uage. Dart is optionally typed (\ref{types}) and supports reified generics. The run-time type of every object is represented as an instance of class \code{Type} which can be obtained by calling the getter \code{runtimeType} declared in cl ass \code{Object}, the root of the Dart class hierarchy. 153 Dart is a class-based, single-inheritance, pure object-oriented programming lang uage. Dart is optionally typed (\ref{types}) and supports reified generics. The run-time type of every object is represented as an instance of class \code{Type} which can be obtained by calling the getter \code{runtimeType} declared in cl ass \code{Object}, the root of the Dart class hierarchy.
130 154
155 \LMHash{}
131 Dart programs may be statically checked. The static checker will report some vio lations of the type rules, but such violations do not abort compilation or precl ude execution. 156 Dart programs may be statically checked. The static checker will report some vio lations of the type rules, but such violations do not abort compilation or precl ude execution.
132 157
158 \LMHash{}
133 Dart programs may be executed in one of two modes: production mode or checked mo de. In production mode, static type annotations (\ref{staticTypes}) have absolut ely no effect on execution with the exception of reflection and structural type tests. 159 Dart programs may be executed in one of two modes: production mode or checked mo de. In production mode, static type annotations (\ref{staticTypes}) have absolut ely no effect on execution with the exception of reflection and structural type tests.
134 160
135 \commentary{ 161 \commentary{
136 Reflection, by definition, examines the program structure. If we provide reflect ive access to the type of a declaration, or to source code, it will inevitably p roduce results that depend on the types used in the underlying code. 162 Reflection, by definition, examines the program structure. If we provide reflect ive access to the type of a declaration, or to source code, it will inevitably p roduce results that depend on the types used in the underlying code.
137 163
138 Type tests also examine the types in a program explicitly. Nevertheless, in most cases, these will not depend on type annotations. The exceptions to this rule a re type tests involving function types. Function types are structural, and so de pend on the types declared for their parameters and on their return types. 164 Type tests also examine the types in a program explicitly. Nevertheless, in most cases, these will not depend on type annotations. The exceptions to this rule a re type tests involving function types. Function types are structural, and so de pend on the types declared for their parameters and on their return types.
139 } 165 }
140 166
167 \LMHash{}
141 In checked mode, assignments are dynamically checked, and certain violations of the type system raise exceptions at run time. 168 In checked mode, assignments are dynamically checked, and certain violations of the type system raise exceptions at run time.
142 169
143 \commentary{ 170 \commentary{
144 The coexistence between optional typing and reification is based on the followin g: 171 The coexistence between optional typing and reification is based on the followin g:
145 \begin{enumerate} 172 \begin{enumerate}
146 \item Reified type information reflects the types of objects at runtime and may always be queried by dynamic typechecking constructs (the analogs of instanceOf, casts, typecase etc. in other languages). Reified type information includes cla ss declarations, the runtime type (aka class) of an object, and type arguments t o constructors. 173 \item Reified type information reflects the types of objects at runtime and may always be queried by dynamic typechecking constructs (the analogs of instanceOf, casts, typecase etc. in other languages). Reified type information includes cla ss declarations, the runtime type (aka class) of an object, and type arguments t o constructors.
147 \item Static type annotations determine the types of variables and function decl arations (including methods and constructors). 174 \item Static type annotations determine the types of variables and function decl arations (including methods and constructors).
148 \item Production mode respects optional typing. Static type annotations do not a ffect runtime behavior. 175 \item Production mode respects optional typing. Static type annotations do not a ffect runtime behavior.
149 \item Checked mode utilizes static type annotations and dynamic type information aggressively yet selectively to provide early error detection during developmen t. 176 \item Checked mode utilizes static type annotations and dynamic type information aggressively yet selectively to provide early error detection during developmen t.
150 \end{enumerate} 177 \end{enumerate}
151 } 178 }
152 179
180 \LMHash{}
153 Dart programs are organized in a modular fashion into units called {\em librarie s} (\ref{librariesAndScripts}). Libraries are units of encapsulation and may be mutually recursive. 181 Dart programs are organized in a modular fashion into units called {\em librarie s} (\ref{librariesAndScripts}). Libraries are units of encapsulation and may be mutually recursive.
154 182
155 \commentary{However they are not first class. To get multiple copies of a libra ry running simultaneously, one needs to spawn an isolate. 183 \commentary{However they are not first class. To get multiple copies of a libra ry running simultaneously, one needs to spawn an isolate.
156 } 184 }
157 185
158 \subsection{Scoping} 186 \subsection{Scoping}
159 \label{scoping} 187 \LMLabel{scoping}
160 188
189 \LMHash{}
161 A {\em namespace} is a mapping of names denoting declarations to actual declarat ions. Let $NS$ be a namespace. We say that a name $n$ {\em is in }$NS$ if $n$ i s a key of $NS$. We say a declaration $d$ {\em is in }$NS$ if a key of $NS$ maps to $d$. 190 A {\em namespace} is a mapping of names denoting declarations to actual declarat ions. Let $NS$ be a namespace. We say that a name $n$ {\em is in }$NS$ if $n$ i s a key of $NS$. We say a declaration $d$ {\em is in }$NS$ if a key of $NS$ maps to $d$.
162 191
192 \LMHash{}
163 A scope $S_0$ induces a namespace $NS_0$ that maps the simple name of each varia ble, type or function declaration $d$ declared in $S_0$ to $d$. Labels are not i ncluded in the induced namespace of a scope; instead they have their own dedicat ed namespace. 193 A scope $S_0$ induces a namespace $NS_0$ that maps the simple name of each varia ble, type or function declaration $d$ declared in $S_0$ to $d$. Labels are not i ncluded in the induced namespace of a scope; instead they have their own dedicat ed namespace.
164 194
165 \commentary{It is therefore impossible, e.g., to define a class that declares a method and a field with the same name in Dart. Similarly one cannot declare a t op-level function with the same name as a library variable or class. 195 \commentary{It is therefore impossible, e.g., to define a class that declares a method and a field with the same name in Dart. Similarly one cannot declare a t op-level function with the same name as a library variable or class.
166 } 196 }
167 197
198 \LMHash{}
168 It is a compile-time error if there is more than one entity with the same name d eclared in the same scope. 199 It is a compile-time error if there is more than one entity with the same name d eclared in the same scope.
169 200
170 \commentary{ 201 \commentary{
171 In some cases, the name of the declaration differs from the identifier used to d eclare it. Setters have names that are distinct from the corresponding getters because they always have an = automatically added at the end, and unary minus ha s the special name unary-. 202 In some cases, the name of the declaration differs from the identifier used to d eclare it. Setters have names that are distinct from the corresponding getters because they always have an = automatically added at the end, and unary minus ha s the special name unary-.
172 } 203 }
173 204
205 \LMHash{}
174 Dart is lexically scoped. Scopes may nest. A name or declaration $d$ is {\em available in scope} $S$ if $d$ is in the namespace induced by $S$ or if $d$ is available in the lexically enclosing scope of $S$. We say that a name or declar ation $d$ is {\em in scope} if $d$ is available in the current scope. 206 Dart is lexically scoped. Scopes may nest. A name or declaration $d$ is {\em available in scope} $S$ if $d$ is in the namespace induced by $S$ or if $d$ is available in the lexically enclosing scope of $S$. We say that a name or declar ation $d$ is {\em in scope} if $d$ is available in the current scope.
175 207
176 208
209 \LMHash{}
177 If a declaration $d$ named $n$ is in the namespace induced by a scope $S$, then $d$ {\em hides} any declaration named $n$ that is available in the lexically en closing scope of $S$. 210 If a declaration $d$ named $n$ is in the namespace induced by a scope $S$, then $d$ {\em hides} any declaration named $n$ that is available in the lexically en closing scope of $S$.
178 211
179 \commentary { 212 \commentary {
180 A consequence of these rules is that it is possible to hide a type with a method or variable. 213 A consequence of these rules is that it is possible to hide a type with a method or variable.
181 Naming conventions usually prevent such abuses. Nevertheless,the following progr am is legal: 214 Naming conventions usually prevent such abuses. Nevertheless,the following progr am is legal:
182 } 215 }
183 216
184 \begin{dartCode} 217 \begin{dartCode}
185 \CLASS{} HighlyStrung \{ 218 \CLASS{} HighlyStrung \{
186 String() $=>$ "?"; 219 String() $=>$ "?";
187 \} 220 \}
188 \end{dartCode} 221 \end{dartCode}
189 222
223 \LMHash{}
190 Names may be introduced into a scope by declarations within the scope or by ot her mechanisms such as imports or inheritance. 224 Names may be introduced into a scope by declarations within the scope or by ot her mechanisms such as imports or inheritance.
191 225
192 \rationale{ 226 \rationale{
193 The interaction of lexical scoping and inheritance is a subtle one. Ultimately, the question is whether lexical scoping takes precedence over inheritance or vi ce versa. Dart chooses the former. 227 The interaction of lexical scoping and inheritance is a subtle one. Ultimately, the question is whether lexical scoping takes precedence over inheritance or vi ce versa. Dart chooses the former.
194 228
195 Allowing inherited names to take precedence over locally declared names can crea te unexpected situations as code evolves. Specifically, the behavior of code in a subclass can change without warning if a new name is introduced in a supercla ss. Consider: 229 Allowing inherited names to take precedence over locally declared names can crea te unexpected situations as code evolves. Specifically, the behavior of code in a subclass can change without warning if a new name is introduced in a supercla ss. Consider:
196 } 230 }
197 231
198 \begin{dartCode} 232 \begin{dartCode}
199 \LIBRARY{} L1; 233 \LIBRARY{} L1;
(...skipping 20 matching lines...) Expand all
220 These considerations become even more important if one introduces constructs suc h as nested classes, which might be considered in future versions of the languag e. 254 These considerations become even more important if one introduces constructs suc h as nested classes, which might be considered in future versions of the languag e.
221 255
222 Good tooling should of course endeavor to inform programmers of such situations (discreetly). For example, an identifier that is both inherited and lexically vi sible could be highlighted (via underlining or colorization). Better yet, tight integration of source control with language aware tools would detect such change s when they occur. 256 Good tooling should of course endeavor to inform programmers of such situations (discreetly). For example, an identifier that is both inherited and lexically vi sible could be highlighted (via underlining or colorization). Better yet, tight integration of source control with language aware tools would detect such change s when they occur.
223 257
224 } 258 }
225 259
226 260
227 261
228 262
229 \subsection{Privacy} 263 \subsection{Privacy}
230 \label{privacy} 264 \LMLabel{privacy}
231 265
266 \LMHash{}
232 Dart supports two levels of privacy: {\em public} and {\em private}. A declarat ion is {\em private} iff its name is private, otherwise it is {\em public.} A name $q$ is private iff any one of the identifiers that comprise $q$ is private, otherwise it is {\em public.} An identifier is private iff it 267 Dart supports two levels of privacy: {\em public} and {\em private}. A declarat ion is {\em private} iff its name is private, otherwise it is {\em public.} A name $q$ is private iff any one of the identifiers that comprise $q$ is private, otherwise it is {\em public.} An identifier is private iff it
233 begins with an underscore (the \_ character) otherwise it is {\em public.} 268 begins with an underscore (the \_ character) otherwise it is {\em public.}
234 269
270 \LMHash{}
235 A declaration $m$ is {\em accessible to library $L$} if $m$ is declared in $L$ or if $m$ is public. 271 A declaration $m$ is {\em accessible to library $L$} if $m$ is declared in $L$ or if $m$ is public.
236 272
237 \commentary{ 273 \commentary{
238 This means private declarations may only be accessed within the library in which they are declared. 274 This means private declarations may only be accessed within the library in which they are declared.
239 } 275 }
240 276
277 \LMHash{}
241 Privacy applies only to declarations within a library, not to library declaratio ns themselves. 278 Privacy applies only to declarations within a library, not to library declaratio ns themselves.
242 279
243 \rationale{Libraries do not reference each other by name and so the idea of a pr ivate library is meaningless. 280 \rationale{Libraries do not reference each other by name and so the idea of a pr ivate library is meaningless.
244 Thus, if the name of a library begins with an underscore, it has no effect on th e accessibility of the library or its members. 281 Thus, if the name of a library begins with an underscore, it has no effect on th e accessibility of the library or its members.
245 } 282 }
246 283
247 \rationale{Privacy is, at this point, a static notion tied to a particular piece of code (a library). It is designed to support software engineering concerns ra ther than security concerns. Untrusted code should always run in an another isol ate. It is possible that libraries will become first class objects and privacy will be a dynamic notion tied to a library instance. 284 \rationale{Privacy is, at this point, a static notion tied to a particular piece of code (a library). It is designed to support software engineering concerns ra ther than security concerns. Untrusted code should always run in an another isol ate. It is possible that libraries will become first class objects and privacy will be a dynamic notion tied to a library instance.
248 285
249 Privacy is indicated by the name of a declaration - hence privacy and naming are not orthogonal. This has the advantage that both humans and machines can recogn ize access to private declarations at the point of use without knowledge of the context from which the declaration is derived.} 286 Privacy is indicated by the name of a declaration - hence privacy and naming are not orthogonal. This has the advantage that both humans and machines can recogn ize access to private declarations at the point of use without knowledge of the context from which the declaration is derived.}
250 287
251 \subsection{Concurrency} 288 \subsection{Concurrency}
252 289
290 \LMHash{}
253 Dart code is always single threaded. There is no shared-state concurrency in Dar t. Concurrency is supported via actor-like entities called {\em isolates}. 291 Dart code is always single threaded. There is no shared-state concurrency in Dar t. Concurrency is supported via actor-like entities called {\em isolates}.
254 292
293 \LMHash{}
255 An isolate is a unit of concurrency. It has its own memory and its own thread of control. Isolates communicate by message passing (\ref{sendingMessages}). No st ate is ever shared between isolates. Isolates are created by spawning (\ref{spaw ningAnIsolate}). 294 An isolate is a unit of concurrency. It has its own memory and its own thread of control. Isolates communicate by message passing (\ref{sendingMessages}). No st ate is ever shared between isolates. Isolates are created by spawning (\ref{spaw ningAnIsolate}).
256 295
257 296
258 \section{Errors and Warnings} 297 \section{Errors and Warnings}
259 \label{errorsAndWarnings} 298 \LMLabel{errorsAndWarnings}
260 299
300 \LMHash{}
261 This specification distinguishes between several kinds of errors. 301 This specification distinguishes between several kinds of errors.
262 302
303 \LMHash{}
263 {\em Compile-time errors} are errors that preclude execution. A compile-time err or must be reported by a Dart compiler before the erroneous code is executed. 304 {\em Compile-time errors} are errors that preclude execution. A compile-time err or must be reported by a Dart compiler before the erroneous code is executed.
264 305
265 \rationale{A Dart implementation has considerable freedom as to when compilation takes place. Modern programming language implementations often interleave compi lation and execution, so that compilation of a method may be delayed, e.g., unt il it is first invoked. Consequently, compile-time errors in a method $m$ may be reported as late as the time of $m$'s first invocation. 306 \rationale{A Dart implementation has considerable freedom as to when compilation takes place. Modern programming language implementations often interleave compi lation and execution, so that compilation of a method may be delayed, e.g., unt il it is first invoked. Consequently, compile-time errors in a method $m$ may be reported as late as the time of $m$'s first invocation.
266 307
267 As a web language, Dart is often loaded directly from source, with no intermedia te binary representation. In the interests of rapid loading, Dart implementation s may choose to avoid full parsing of method bodies, for example. This can be do ne by tokenizing the input and checking for balanced curly braces on method body entry. In such an implementation, even syntax errors will be detected only when the method needs to be executed, at which time it will be compiled (JITed). 308 As a web language, Dart is often loaded directly from source, with no intermedia te binary representation. In the interests of rapid loading, Dart implementation s may choose to avoid full parsing of method bodies, for example. This can be do ne by tokenizing the input and checking for balanced curly braces on method body entry. In such an implementation, even syntax errors will be detected only when the method needs to be executed, at which time it will be compiled (JITed).
268 309
269 In a development environment a compiler should of course report compilation erro rs eagerly so as to best serve the programmer. 310 In a development environment a compiler should of course report compilation erro rs eagerly so as to best serve the programmer.
270 } 311 }
271 312
313 \LMHash{}
272 If an uncaught compile-time error occurs within the code of a running isolate $A $, $A$ is immediately suspended. The only circumstance where a compile-time err or could be caught would be via code run reflectively, where the mirror system c an catch it. 314 If an uncaught compile-time error occurs within the code of a running isolate $A $, $A$ is immediately suspended. The only circumstance where a compile-time err or could be caught would be via code run reflectively, where the mirror system c an catch it.
273 315
274 \rationale{Typically, once a compile-time error is thrown and $A$ is suspended, $A$ will then be terminated. However, this depends on the overall environment. 316 \rationale{Typically, once a compile-time error is thrown and $A$ is suspended, $A$ will then be terminated. However, this depends on the overall environment.
275 A Dart engine runs in the context of an {\em embedder}, 317 A Dart engine runs in the context of an {\em embedder},
276 a program that interfaces between the engine and the surrounding computing envir onment. The embedder will often be a web browser, but need not be; it may be a C ++ program on the server for example. When an isolate fails with a compile-time error as described above, control returns to the embedder, along with an excepti on describing the problem. This is necessary so that the embedder can clean up resources etc. It is then the embedder's decision whether to terminate the isola te or not. 318 a program that interfaces between the engine and the surrounding computing envir onment. The embedder will often be a web browser, but need not be; it may be a C ++ program on the server for example. When an isolate fails with a compile-time error as described above, control returns to the embedder, along with an excepti on describing the problem. This is necessary so that the embedder can clean up resources etc. It is then the embedder's decision whether to terminate the isola te or not.
277 } 319 }
278 320
321 \LMHash{}
279 {\em Static warnings} are those errors reported by the static checker. They hav e no effect on execution. Many, but not all, static warnings relate to types, in which case they are known as {\em static type warnings.} Static warnings must b e provided by Dart compilers used during development such as those incorporated in IDEs or otherwise intended to be used by developers for developing code. Comp ilers that are part of runtime execution environments such as virtual machines s hould not issue static warnings. 322 {\em Static warnings} are those errors reported by the static checker. They hav e no effect on execution. Many, but not all, static warnings relate to types, in which case they are known as {\em static type warnings.} Static warnings must b e provided by Dart compilers used during development such as those incorporated in IDEs or otherwise intended to be used by developers for developing code. Comp ilers that are part of runtime execution environments such as virtual machines s hould not issue static warnings.
280 323
324 \LMHash{}
281 {\em Dynamic type errors} are type errors reported in checked mode. 325 {\em Dynamic type errors} are type errors reported in checked mode.
282 326
327 \LMHash{}
283 {\em Run-time errors} are exceptions raised during execution. Whenever we say th at an exception $ex$ is {\em raised} or {\em thrown}, we mean that a throw expre ssion (\ref{throw}) of the form: \code{\THROW{} $ex$;} was implicitly evaluated or that a rethrow statement (\ref{rethrow}) of the form \code{\RETHROW} was exe cuted. When we say that {\em a} $C$ {\em is thrown}, where $C$ is a class, we me an that an instance of class $C$ is thrown. 328 {\em Run-time errors} are exceptions raised during execution. Whenever we say th at an exception $ex$ is {\em raised} or {\em thrown}, we mean that a throw expre ssion (\ref{throw}) of the form: \code{\THROW{} $ex$;} was implicitly evaluated or that a rethrow statement (\ref{rethrow}) of the form \code{\RETHROW} was exe cuted. When we say that {\em a} $C$ {\em is thrown}, where $C$ is a class, we me an that an instance of class $C$ is thrown.
284 329
330 \LMHash{}
285 If an uncaught exception is thrown by a running isolate $A$, $A$ is immediately suspended. 331 If an uncaught exception is thrown by a running isolate $A$, $A$ is immediately suspended.
286 332
287 333
288 \section{Variables} 334 \section{Variables}
289 \label{variables} 335 \LMLabel{variables}
290 336
337 \LMHash{}
291 Variables are storage locations in memory. 338 Variables are storage locations in memory.
292 339
293 \begin{grammar} 340 \begin{grammar}
294 {\bf variableDeclaration:} 341 {\bf variableDeclaration:}
295 declaredIdentifier (`,' identifier)* 342 declaredIdentifier (`,' identifier)*
296 . 343 .
297 344
298 {\bf declaredIdentifier:} 345 {\bf declaredIdentifier:}
299 metadata finalConstVarOrType identifier 346 metadata finalConstVarOrType identifier
300 . 347 .
(...skipping 17 matching lines...) Expand all
318 365
319 {\bf initializedIdentifierList:} 366 {\bf initializedIdentifierList:}
320 initializedIdentifier (`,' initializedIdentifier)* 367 initializedIdentifier (`,' initializedIdentifier)*
321 . 368 .
322 369
323 370
324 371
325 372
326 \end{grammar} 373 \end{grammar}
327 374
375 \LMHash{}
328 A variable that has not been initialized has the initial value \NULL{} (\ref{nul l}). 376 A variable that has not been initialized has the initial value \NULL{} (\ref{nul l}).
329 377
378 \LMHash{}
330 A variable declared at the top-level of a library is referred to as either a {\e m library variable} or simply a top-level variable. 379 A variable declared at the top-level of a library is referred to as either a {\e m library variable} or simply a top-level variable.
331 380
381 \LMHash{}
332 A {\em static variable} is a variable that is not associated with a particular i nstance, but rather with an entire library or class. Static variables include l ibrary variables and class variables. Class variables are variables whose declar ation is immediately nested inside a class declaration and includes the modifier \STATIC{}. A library variable is implicitly static. It is a compile-time error to preface a top-level variable declaration with the built-in identifier (\ref{ identifierReference}) \STATIC{}. 382 A {\em static variable} is a variable that is not associated with a particular i nstance, but rather with an entire library or class. Static variables include l ibrary variables and class variables. Class variables are variables whose declar ation is immediately nested inside a class declaration and includes the modifier \STATIC{}. A library variable is implicitly static. It is a compile-time error to preface a top-level variable declaration with the built-in identifier (\ref{ identifierReference}) \STATIC{}.
333 383
384 \LMHash{}
334 Static variable declarations are initialized lazily. When a static variable $v$ is read, iff it has not yet been assigned, it is set to the result of evaluatin g its initializer. The precise rules are given in section \ref{evaluationOfImpli citVariableGetters}. 385 Static variable declarations are initialized lazily. When a static variable $v$ is read, iff it has not yet been assigned, it is set to the result of evaluatin g its initializer. The precise rules are given in section \ref{evaluationOfImpli citVariableGetters}.
335 386
336 \rationale{The lazy semantics are given because we do not want a language where one tends to define expensive initialization computations, causing long applicat ion startup times. This is especially crucial for Dart, which must support the c oding of client applications. 387 \rationale{The lazy semantics are given because we do not want a language where one tends to define expensive initialization computations, causing long applicat ion startup times. This is especially crucial for Dart, which must support the c oding of client applications.
337 } 388 }
338 389
390 \LMHash{}
339 A {\em final variable} is a variable whose binding is fixed upon initialization; a final variable $v$ will always refer to the same object after $v$ has been in itialized. The declaration of a final variable must include the modifier \FINAL {}. 391 A {\em final variable} is a variable whose binding is fixed upon initialization; a final variable $v$ will always refer to the same object after $v$ has been in itialized. The declaration of a final variable must include the modifier \FINAL {}.
340 392
393 \LMHash{}
341 It is a static warning if a final instance variable that has been initialized at its point of declaration is also initialized in a constructor. 394 It is a static warning if a final instance variable that has been initialized at its point of declaration is also initialized in a constructor.
342 % It is a static warning if a final instance variable that has been initialized by means of an initializing formal of a constructor is also initialized elsewhe re in the same constructor. 395 % It is a static warning if a final instance variable that has been initialized by means of an initializing formal of a constructor is also initialized elsewhe re in the same constructor.
343 It is a compile-time error if a local variable $v$ is final and $v$ is not initi alized at its point of declaration. 396 It is a compile-time error if a local variable $v$ is final and $v$ is not initi alized at its point of declaration.
344 397
345 \commentary{ 398 \commentary{
346 399
347 A library or static variable is guaranteed to have an initializer at its declara tion by the grammar. 400 A library or static variable is guaranteed to have an initializer at its declara tion by the grammar.
348 401
349 Attempting to assign to a final variable anywhere except in its declaration or i n a constructor header will cause a runtime error to be thrown as discussed bel ow. The assignment will also give rise to a static warning. Any repeated assignm ent to a final variable will also lead to a runtime error. 402 Attempting to assign to a final variable anywhere except in its declaration or i n a constructor header will cause a runtime error to be thrown as discussed bel ow. The assignment will also give rise to a static warning. Any repeated assignm ent to a final variable will also lead to a runtime error.
350 403
351 Taken as a whole, the rules ensure that any attempt to execute multiple assignme nts to a final variable will yield static warnings and repeated assignments will fail dynamically. 404 Taken as a whole, the rules ensure that any attempt to execute multiple assignme nts to a final variable will yield static warnings and repeated assignments will fail dynamically.
352 } 405 }
353 406
407 \LMHash{}
354 A {\em constant variable} is a variable whose declaration includes the modifier \CONST{}. A constant variable is always implicitly final. A constant variable mu st be initialized to a compile-time constant (\ref{constants}) or a compile-time error occurs. 408 A {\em constant variable} is a variable whose declaration includes the modifier \CONST{}. A constant variable is always implicitly final. A constant variable mu st be initialized to a compile-time constant (\ref{constants}) or a compile-time error occurs.
355 409
410 \LMHash{}
356 We say that a variable $v$ is {\em potentially mutated} in some scope $s$ if $v$ is not final or constant and an assignment to $v$ occurs in $s$. 411 We say that a variable $v$ is {\em potentially mutated} in some scope $s$ if $v$ is not final or constant and an assignment to $v$ occurs in $s$.
357 412
413 \LMHash{}
358 If a variable declaration does not explicitly specify a type, the type of the de clared variable(s) is \DYNAMIC{}, the unknown type (\ref{typeDynamic}). 414 If a variable declaration does not explicitly specify a type, the type of the de clared variable(s) is \DYNAMIC{}, the unknown type (\ref{typeDynamic}).
359 415
416 \LMHash{}
360 A variable is {\em mutable} if it is not final. 417 A variable is {\em mutable} if it is not final.
361 Static and instance variable declarations always induce implicit getters. If the variable is mutable it also introduces an implicit setter. 418 Static and instance variable declarations always induce implicit getters. If the variable is mutable it also introduces an implicit setter.
362 The scope into which the implicit getters and setters are introduced depends on the kind of variable declaration involved. 419 The scope into which the implicit getters and setters are introduced depends on the kind of variable declaration involved.
363 420
421 \LMHash{}
364 A library variable introduces a getter into the top level scope of the enclosing library. A static class variable introduces a static getter into the immediatel y enclosing class. An instance variable introduces an instance getter into the i mmediately enclosing class. 422 A library variable introduces a getter into the top level scope of the enclosing library. A static class variable introduces a static getter into the immediatel y enclosing class. An instance variable introduces an instance getter into the i mmediately enclosing class.
365 423
424 \LMHash{}
366 A mutable library variable introduces a setter into the top level scope of the e nclosing library. A mutable static class variable introduces a static setter int o the immediately enclosing class. A mutable instance variable introduces an ins tance setter into the immediately enclosing class. 425 A mutable library variable introduces a setter into the top level scope of the e nclosing library. A mutable static class variable introduces a static setter int o the immediately enclosing class. A mutable instance variable introduces an ins tance setter into the immediately enclosing class.
367 426
427 \LMHash{}
368 Local variables are added to the innermost enclosing scope. They do not induce getters and setters. A local variable may only be referenced at a source code l ocation that is after its initializer, if any, is complete, or a compile-time er ror occurs. The error may be reported either at the point where the premature r eference occurs, or at the variable declaration. 428 Local variables are added to the innermost enclosing scope. They do not induce getters and setters. A local variable may only be referenced at a source code l ocation that is after its initializer, if any, is complete, or a compile-time er ror occurs. The error may be reported either at the point where the premature r eference occurs, or at the variable declaration.
369 429
370 \rationale { 430 \rationale {
371 We allow the error to be reported at the declaration to allow implementations to avoid an extra processing phase. 431 We allow the error to be reported at the declaration to allow implementations to avoid an extra processing phase.
372 } 432 }
373 433
374 \commentary{ 434 \commentary{
375 The example below illustrates the expected behavior. A variable $x$ is declared at the library level, and another $x$ is declared inside the function $f$. 435 The example below illustrates the expected behavior. A variable $x$ is declared at the library level, and another $x$ is declared inside the function $f$.
376 } 436 }
377 437
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 475
416 \rationale{ 476 \rationale{
417 As a rule, type annotations are ignored in production mode. However, we do 477 As a rule, type annotations are ignored in production mode. However, we do
418 not want to allow programs to compile legally in one mode and not another, and in this extremely odd situation, that consideration takes precedence. 478 not want to allow programs to compile legally in one mode and not another, and in this extremely odd situation, that consideration takes precedence.
419 } 479 }
420 480
421 \end{dartCode} 481 \end{dartCode}
422 482
423 % the grammar does not support local getters and setters. The local var discussi on does not seem to mention getters and setters based semantics. It simply discu sses the creation of the variable, not its access. Access is either assignment o r identifiers. Identifiers ignore the getter story. 483 % the grammar does not support local getters and setters. The local var discussi on does not seem to mention getters and setters based semantics. It simply discu sses the creation of the variable, not its access. Access is either assignment o r identifiers. Identifiers ignore the getter story.
424 484
485 \LMHash{}
425 The following rules apply to all static and instance variables. 486 The following rules apply to all static and instance variables.
426 487
488 \LMHash{}
427 A variable declaration of one of the forms \code{$T$ $v$;}, \code{$T$ $v$ = $ e$;} , \code{\CONST{} $T$ $v$ = $e$;}, \code{\FINAL{} $T$ $v$;} or \code{\FINA L{} $T$ $v$ = $e$;} always induces an implicit getter function (\ref{getters}) with signature 489 A variable declaration of one of the forms \code{$T$ $v$;}, \code{$T$ $v$ = $ e$;} , \code{\CONST{} $T$ $v$ = $e$;}, \code{\FINAL{} $T$ $v$;} or \code{\FINA L{} $T$ $v$ = $e$;} always induces an implicit getter function (\ref{getters}) with signature
428 490
429 $T$ \GET{} $v$ 491 $T$ \GET{} $v$
430 492
431 whose invocation evaluates as described below (\ref{evaluationOfImplicitVariable Getters}). 493 whose invocation evaluates as described below (\ref{evaluationOfImplicitVariable Getters}).
432 494
433 495
496 \LMHash{}
434 A variable declaration of one of the forms \code{\VAR{} $v$;}, \code{\VAR{} $ v$ = $e$;} , \code{\CONST{} $v$ = $e$;}, \code{\FINAL{} $v$;} or \code{\FINAL{} $v$ = $e$;} always induces an implicit getter function with signature 497 A variable declaration of one of the forms \code{\VAR{} $v$;}, \code{\VAR{} $ v$ = $e$;} , \code{\CONST{} $v$ = $e$;}, \code{\FINAL{} $v$;} or \code{\FINAL{} $v$ = $e$;} always induces an implicit getter function with signature
435 498
436 \GET{} $v$ 499 \GET{} $v$
437 500
438 whose invocation evaluates as described below (\ref{evaluationOfImplicitVariabl eGetters}). 501 whose invocation evaluates as described below (\ref{evaluationOfImplicitVariabl eGetters}).
439 502
503 \LMHash{}
440 A non-final variable declaration of the form \code{{} $T$ $v$;} or the form \ code{$T$ $v$ = $e$;} always induces an implicit setter function (\ref{setters }) with signature 504 A non-final variable declaration of the form \code{{} $T$ $v$;} or the form \ code{$T$ $v$ = $e$;} always induces an implicit setter function (\ref{setters }) with signature
441 505
442 \VOID{} \SET{} $v=(T$ $x)$ 506 \VOID{} \SET{} $v=(T$ $x)$
443 507
444 whose execution sets the value of $v$ to the incoming argument $x$. 508 whose execution sets the value of $v$ to the incoming argument $x$.
445 509
510 \LMHash{}
446 A non-final variable declaration of the form \code{\VAR{} $v$;} or the form \ code{\VAR{} $v$ = $e$;} always induces an implicit setter function with signa ture 511 A non-final variable declaration of the form \code{\VAR{} $v$;} or the form \ code{\VAR{} $v$ = $e$;} always induces an implicit setter function with signa ture
447 512
448 \SET{} $v=(x)$ 513 \SET{} $v=(x)$
449 514
450 whose execution sets the value of $v$ to the incoming argument $x$. 515 whose execution sets the value of $v$ to the incoming argument $x$.
451 516
452 517
453 \subsection{Evaluation of Implicit Variable Getters} 518 \subsection{Evaluation of Implicit Variable Getters}
454 \label{evaluationOfImplicitVariableGetters} 519 \LMLabel{evaluationOfImplicitVariableGetters}
455 520
521 \LMHash{}
456 Let $d$ be the declaration of a static or instance variable $v$. If $d$ is an i nstance variable, then the invocation of the implicit getter of $v$ evaluates t o the value stored in $v$. 522 Let $d$ be the declaration of a static or instance variable $v$. If $d$ is an i nstance variable, then the invocation of the implicit getter of $v$ evaluates t o the value stored in $v$.
457 If $d$ is a static or library variable then the implicit getter method of $v$ ex ecutes as follows: 523 If $d$ is a static or library variable then the implicit getter method of $v$ ex ecutes as follows:
458 \begin{itemize} 524 \begin{itemize}
459 \item {\bf Non-constant variable declaration with initializer}. If $d$ is of one of the forms \code{\VAR{} $v$ = $e$;} , \code{$T$ $v$ = $e$;} , \code{\FINAL {} $v$ = $e$;} , \code{\FINAL{} $T$ $v$ = $e$;}, \code{\STATIC{} $v$ = $e$; }, \code{\STATIC{} $T$ $v$ = $e$; }, \code{\STATIC{} \FINAL{} $v$ = $e$; } or \code {\STATIC{} \FINAL{} $T$ $v$ = $e$;} and no value has yet been stored into $v$ th en the initializer expression $e$ is evaluated. If, during the evaluation of $e$ , the getter for $v$ is invoked, a \code{CyclicInitializationError} is thrown. I f the evaluation succeeded yielding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$ is stored into $v$. The result of executing the ge tter is $r$. 525 \item {\bf Non-constant variable declaration with initializer}. If $d$ is of one of the forms \code{\VAR{} $v$ = $e$;} , \code{$T$ $v$ = $e$;} , \code{\FINAL {} $v$ = $e$;} , \code{\FINAL{} $T$ $v$ = $e$;}, \code{\STATIC{} $v$ = $e$; }, \code{\STATIC{} $T$ $v$ = $e$; }, \code{\STATIC{} \FINAL{} $v$ = $e$; } or \code {\STATIC{} \FINAL{} $T$ $v$ = $e$;} and no value has yet been stored into $v$ th en the initializer expression $e$ is evaluated. If, during the evaluation of $e$ , the getter for $v$ is invoked, a \code{CyclicInitializationError} is thrown. I f the evaluation succeeded yielding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$ is stored into $v$. The result of executing the ge tter is $r$.
460 \item {\bf Constant variable declaration}. If $d$ is of one of the forms \code{ \CONST{} $v$ = $e$; } , \code{\CONST{} $T$ $v$ = $e$; }, \code{\STATIC{} \CON ST{} $v$ = $e$; } or \code{\STATIC{} \CONST{} $T$ $v$ = $e$;} the result of the getter is the value of the compile time constant $e$. \commentary{Note that a c ompile time constant cannot depend on itself, so no cyclic references can occur. } 526 \item {\bf Constant variable declaration}. If $d$ is of one of the forms \code{ \CONST{} $v$ = $e$; } , \code{\CONST{} $T$ $v$ = $e$; }, \code{\STATIC{} \CON ST{} $v$ = $e$; } or \code{\STATIC{} \CONST{} $T$ $v$ = $e$;} the result of the getter is the value of the compile time constant $e$. \commentary{Note that a c ompile time constant cannot depend on itself, so no cyclic references can occur. }
461 Otherwise 527 Otherwise
462 \item {\bf Variable declaration without initializer}. The result of executing th e getter method is the value stored in $v$. 528 \item {\bf Variable declaration without initializer}. The result of executing th e getter method is the value stored in $v$.
463 \end{itemize} 529 \end{itemize}
464 530
465 531
466 532
467 533
468 534
469 \section{Functions} 535 \section{Functions}
470 \label{functions} 536 \LMLabel{functions}
471 537
538 \LMHash{}
472 Functions abstract over executable actions. 539 Functions abstract over executable actions.
473 540
474 \begin{grammar} 541 \begin{grammar}
475 {\bf functionSignature:} 542 {\bf functionSignature:}
476 metadata returnType? identifier formalParameterList 543 metadata returnType? identifier formalParameterList
477 . 544 .
478 545
479 {\bf returnType:} 546 {\bf returnType:}
480 \VOID{}; 547 \VOID{};
481 type 548 type
482 . 549 .
483 550
484 {\bf functionBody:} \ASYNC{}? `={\escapegrammar \gt}' expression `{\escapegramm ar ;}'; 551 {\bf functionBody:} \ASYNC{}? `={\escapegrammar \gt}' expression `{\escapegramm ar ;}';
485 (\ASYNC{} $|$ \ASYNC* $|$ \SYNC*)? block 552 (\ASYNC{} $|$ \ASYNC* $|$ \SYNC*)? block
486 . 553 .
487 554
488 {\bf block:} 555 {\bf block:}
489 `\{' statements `\}' 556 `\{' statements `\}'
490 . 557 .
491 558
492 \end{grammar} 559 \end{grammar}
493 560
561 \LMHash{}
494 Functions include function declarations (\ref{functionDeclarations}), methods ( \ref{instanceMethods}, \ref{staticMethods}), getters (\ref{getters}), setters (\ref{setters}), constructors (\ref{constructors}) and function literals (\re f{functionExpressions}). 562 Functions include function declarations (\ref{functionDeclarations}), methods ( \ref{instanceMethods}, \ref{staticMethods}), getters (\ref{getters}), setters (\ref{setters}), constructors (\ref{constructors}) and function literals (\re f{functionExpressions}).
495 563
564 \LMHash{}
496 All functions have a signature and a body. The signature describes the formal pa rameters of the function, and possibly its name and return type. A function bod y is either: 565 All functions have a signature and a body. The signature describes the formal pa rameters of the function, and possibly its name and return type. A function bod y is either:
497 \begin{itemize} 566 \begin{itemize}
498 \item A block statement (\ref{blocks}) containing the statements (\ref{stateme nts}) executed by the function, optionally marked with one of the modifiers: \AS YNC, \ASYNC* or \SYNC*. In this case, if the last statement of a function is not a return statement (\ref{return}), the statement \code{\RETURN{};} is implicitl y appended to the function body. 567 \item A block statement (\ref{blocks}) containing the statements (\ref{stateme nts}) executed by the function, optionally marked with one of the modifiers: \AS YNC, \ASYNC* or \SYNC*. In this case, if the last statement of a function is not a return statement (\ref{return}), the statement \code{\RETURN{};} is implicitl y appended to the function body.
499 568
500 \rationale{ 569 \rationale{
501 Because Dart is optionally typed, we cannot guarantee that a function that does not return a value will not be used in the context of an expression. Therefore, every function must return a value. A \RETURN{} without an expression returns \N ULL{}. For generator functions, the situation is more subtle. See further discus sion in section \ref{return}. 570 Because Dart is optionally typed, we cannot guarantee that a function that does not return a value will not be used in the context of an expression. Therefore, every function must return a value. A \RETURN{} without an expression returns \N ULL{}. For generator functions, the situation is more subtle. See further discus sion in section \ref{return}.
502 } 571 }
503 572
504 OR 573 OR
505 \item of the form \code{=$>$ $e$} which is equivalent to a body of the form \c ode{\{\RETURN{} $e$;\}} or the form \code{\ASYNC{} =$>$ $e$} which is equivalent to a body of the form \code{\ASYNC{} \{\RETURN{} $e$;\}}. \rationale{The other modifiers do not apply here, because they apply only to generators, discussed be low, and generators do not allow the form \code{\RETURN{} $e$}; values are added to the generated stream or iterable using \YIELD{} instead.} 574 \item of the form \code{=$>$ $e$} which is equivalent to a body of the form \c ode{\{\RETURN{} $e$;\}} or the form \code{\ASYNC{} =$>$ $e$} which is equivalent to a body of the form \code{\ASYNC{} \{\RETURN{} $e$;\}}. \rationale{The other modifiers do not apply here, because they apply only to generators, discussed be low, and generators do not allow the form \code{\RETURN{} $e$}; values are added to the generated stream or iterable using \YIELD{} instead.}
506 575
507 \end{itemize} 576 \end{itemize}
508 577
578 \LMHash{}
509 A function is {\em asynchronous} if its body is marked with the \ASYNC{} or \ASY NC* modifier. Otherwise the function is {\em synchronous}. A function is a {\em generator} if its body is marked with the \SYNC* or \ASYNC* modifier. 579 A function is {\em asynchronous} if its body is marked with the \ASYNC{} or \ASY NC* modifier. Otherwise the function is {\em synchronous}. A function is a {\em generator} if its body is marked with the \SYNC* or \ASYNC* modifier.
510 580
511 \commentary{ 581 \commentary{
512 Whether a function is synchronous or asynchronous is orthogonal to whether it is a generator or not. Generator functions are a sugar for functions that produce collections in a systematic way, by lazily applying a function that {\em generat es} individual elements of a collection. Dart provides such a sugar in both the synchronous case, where one returns an iterable, and in the asynchronous case, w here one returns a stream. Dart also allows both synchronous and asynchronous fu nctions that produce a single value. 582 Whether a function is synchronous or asynchronous is orthogonal to whether it is a generator or not. Generator functions are a sugar for functions that produce collections in a systematic way, by lazily applying a function that {\em generat es} individual elements of a collection. Dart provides such a sugar in both the synchronous case, where one returns an iterable, and in the asynchronous case, w here one returns a stream. Dart also allows both synchronous and asynchronous fu nctions that produce a single value.
513 } 583 }
514 584
585 \LMHash{}
515 It is a compile-time error if an \ASYNC, \ASYNC* or \SYNC* modifier is attached to the body of a setter or constructor. 586 It is a compile-time error if an \ASYNC, \ASYNC* or \SYNC* modifier is attached to the body of a setter or constructor.
516 587
517 \rationale{ 588 \rationale{
518 An asynchronous setter would be of little use, since setters can only be used in the context of an assignment (\ref{assignment}), and an assignment expression a lways evaluates to the value of the assignment's right hand side. If the setter actually did its work asynchronously, one might imagine that one would return a future that resolved to the assignment's right hand side after the setter did it s work. However, this would require dynamic tests at every assignment, and so wo uld be prohibitively expensive. 589 An asynchronous setter would be of little use, since setters can only be used in the context of an assignment (\ref{assignment}), and an assignment expression a lways evaluates to the value of the assignment's right hand side. If the setter actually did its work asynchronously, one might imagine that one would return a future that resolved to the assignment's right hand side after the setter did it s work. However, this would require dynamic tests at every assignment, and so wo uld be prohibitively expensive.
519 590
520 An asynchronous constructor would, by definition, never return an instance of th e class it purports to construct, but instead return a future. Calling such a be ast via \NEW{} would be very confusing. If you need to produce an object asynchr onously, use a method. 591 An asynchronous constructor would, by definition, never return an instance of th e class it purports to construct, but instead return a future. Calling such a be ast via \NEW{} would be very confusing. If you need to produce an object asynchr onously, use a method.
521 592
522 One could allow modifiers for factories. A factory for \code{Future} could be mo dified by \ASYNC{}, a factory for \code{Stream} could be modified by \ASYNC* and a factory for \code{Iterable} could be modified by \SYNC*. No other scenario ma kes sense because the object returned by the factory would be of the wrong type. This situation is very unusual so it is not worth making an exception to the ge neral rule for constructors in order to allow it. 593 One could allow modifiers for factories. A factory for \code{Future} could be mo dified by \ASYNC{}, a factory for \code{Stream} could be modified by \ASYNC* and a factory for \code{Iterable} could be modified by \SYNC*. No other scenario ma kes sense because the object returned by the factory would be of the wrong type. This situation is very unusual so it is not worth making an exception to the ge neral rule for constructors in order to allow it.
523 } 594 }
524 595
525 596
526 \subsection{Function Declarations} 597 \subsection{Function Declarations}
527 \label{functionDeclarations} 598 \LMLabel{functionDeclarations}
528 599
600 \LMHash{}
529 A {\em function declaration} is a function that is neither a member of a class n or a function literal. Function declarations include {\em library functions}, wh ich are function declarations 601 A {\em function declaration} is a function that is neither a member of a class n or a function literal. Function declarations include {\em library functions}, wh ich are function declarations
530 %(including getters and setters) 602 %(including getters and setters)
531 at the top level of a library, and {\em local functions}, which are function dec larations declared inside other functions. Library functions are often referred to simply as top-level functions. 603 at the top level of a library, and {\em local functions}, which are function dec larations declared inside other functions. Library functions are often referred to simply as top-level functions.
532 604
605 \LMHash{}
533 A function declaration consists of an identifier indicating the function's name, possibly prefaced by a return type. The function name is followed by a signatur e and body. For getters, the signature is empty. The body is empty for function s that are external. 606 A function declaration consists of an identifier indicating the function's name, possibly prefaced by a return type. The function name is followed by a signatur e and body. For getters, the signature is empty. The body is empty for function s that are external.
534 607
608 \LMHash{}
535 The scope of a library function is the scope of the enclosing library. The scope of a local function is described in section \ref{localFunctionDeclaration}. In both cases, the name of the function is in scope in its formal parameter scope (\ref{formalParameters}). 609 The scope of a library function is the scope of the enclosing library. The scope of a local function is described in section \ref{localFunctionDeclaration}. In both cases, the name of the function is in scope in its formal parameter scope (\ref{formalParameters}).
536 610
537 %A function declaration of the form $T_0$ $id(T_1$ $a_1, \ldots, T_n$ $a_n, [T_ {n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k])\{s\}$ is equivalent to a variable declaration of the form \code{\FINAL{} $F$ $id$ = $(T_1$ $a_1, \ldots , T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k}= d_k])\{s\}$}, where $F$ is the function type alias (\ref{typedef}) \code{\TYPEDEF{} $T_0$ $F(T _1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}])$}. Likewise, a function declaration of the form $id(T_1$ $a_1, \ldots, T_n$ $a_n , [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k])\{s\}$ is equivalen t to a variable declaration of the form \code{\FINAL{} $F$ $id$ = $(T_1$ $a_1, \ ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k])\{s \}$}, where $F$ is the function type alias \code{\TYPEDEF{} $F(T_1$ $a_1, \ldot s, T_n$ $a_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}])$}. 611 %A function declaration of the form $T_0$ $id(T_1$ $a_1, \ldots, T_n$ $a_n, [T_ {n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k])\{s\}$ is equivalent to a variable declaration of the form \code{\FINAL{} $F$ $id$ = $(T_1$ $a_1, \ldots , T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k}= d_k])\{s\}$}, where $F$ is the function type alias (\ref{typedef}) \code{\TYPEDEF{} $T_0$ $F(T _1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}])$}. Likewise, a function declaration of the form $id(T_1$ $a_1, \ldots, T_n$ $a_n , [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k])\{s\}$ is equivalen t to a variable declaration of the form \code{\FINAL{} $F$ $id$ = $(T_1$ $a_1, \ ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k])\{s \}$}, where $F$ is the function type alias \code{\TYPEDEF{} $F(T_1$ $a_1, \ldot s, T_n$ $a_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}])$}.
538 612
539 %\Q{We need to cover library getters as well.} 613 %\Q{We need to cover library getters as well.}
540 614
541 %\Q{ The definition in terms of variables is untrue, because the code would be i llegal. The initializer cannot refer to the function name in this case. I belie ve the best fix is to relax this 615 %\Q{ The definition in terms of variables is untrue, because the code would be i llegal. The initializer cannot refer to the function name in this case. I belie ve the best fix is to relax this
542 %requirement in the case of closures. See bug 315. 616 %requirement in the case of closures. See bug 315.
543 %} 617 %}
544 618
545 %\commentary{ 619 %\commentary{
546 %Some obvious conclusions: 620 %Some obvious conclusions:
547 621
548 %A function declaration of the form $id(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k]) => e$ is equivalent to a varia ble declaration of the form \code{\FINAL{} $id$ = ($(T_1$ $a_1, \ldots, T_n$ $a _n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k])=> e$}. 622 %A function declaration of the form $id(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k]) => e$ is equivalent to a varia ble declaration of the form \code{\FINAL{} $id$ = ($(T_1$ $a_1, \ldots, T_n$ $a _n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k])=> e$}.
549 623
550 %A function literal of the form $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+ 1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k]) => e$ is equivalent to a function li teral of the form \code{$(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_ 1, \ldots, T_{n+k}$ $x_{n+k} = d_k])\{$ \RETURN{} $e$;\}}. 624 %A function literal of the form $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+ 1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k]) => e$ is equivalent to a function li teral of the form \code{$(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_ 1, \ldots, T_{n+k}$ $x_{n+k} = d_k])\{$ \RETURN{} $e$;\}}.
551 %} 625 %}
552 626
553 %A function declaration of the form $T_0$ $id(T_1$ $a_1, \ldots, T_n$ $a_n, \{T _{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_{n+k} : d_k\})\{s\}$ is equivalent t o a variable declaration of the form \code{\FINAL{} $F$ $id$ = $(T_1$ $a_1, \ldo ts, T_n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_{n+k} : d_k\})\{s\ }$}, where $F$ is the function type alias (\ref{typedef}) \code{\TYPEDEF{} $T_0$ $F(T_1$ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k} ]\}$}. Likewise, a function declaration of the form $id(T_1$ $a_1, \ldots, T_ n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_{n+k} : d_k\})\{s\}$ is equivalent to a variable declaration of the form \code{\FINAL{} $F$ $id$ = $(T_1 $ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_{n+k} : d_k\})\{s\}$}, where $F$ is the function type alias \code{\TYPEDEF{} $F(T_1$ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\})$}. 627 %A function declaration of the form $T_0$ $id(T_1$ $a_1, \ldots, T_n$ $a_n, \{T _{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_{n+k} : d_k\})\{s\}$ is equivalent t o a variable declaration of the form \code{\FINAL{} $F$ $id$ = $(T_1$ $a_1, \ldo ts, T_n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_{n+k} : d_k\})\{s\ }$}, where $F$ is the function type alias (\ref{typedef}) \code{\TYPEDEF{} $T_0$ $F(T_1$ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k} ]\}$}. Likewise, a function declaration of the form $id(T_1$ $a_1, \ldots, T_ n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_{n+k} : d_k\})\{s\}$ is equivalent to a variable declaration of the form \code{\FINAL{} $F$ $id$ = $(T_1 $ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_{n+k} : d_k\})\{s\}$}, where $F$ is the function type alias \code{\TYPEDEF{} $F(T_1$ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\})$}.
554 628
629 \LMHash{}
555 It is a compile-time error to preface a function declaration with the built-in i dentifier \STATIC{}. 630 It is a compile-time error to preface a function declaration with the built-in i dentifier \STATIC{}.
556 631
632 \LMHash{}
557 When we say that a function $f_1$ {\em forwards} to another function $f_2$, we m ean that invoking $f_1$ causes $f_2$ to be executed with the same arguments an d/or receiver as $f_1$, and returns the result of executing $f_2$ to the caller of $f_1$, unless $f_2$ throws an exception, in which case $f_1$ throws the same exception. Furthermore, we only use the term for synthetic functions introduced by the specification. 633 When we say that a function $f_1$ {\em forwards} to another function $f_2$, we m ean that invoking $f_1$ causes $f_2$ to be executed with the same arguments an d/or receiver as $f_1$, and returns the result of executing $f_2$ to the caller of $f_1$, unless $f_2$ throws an exception, in which case $f_1$ throws the same exception. Furthermore, we only use the term for synthetic functions introduced by the specification.
558 634
559 635
560 \subsection{Formal Parameters} 636 \subsection{Formal Parameters}
561 \label{formalParameters} 637 \LMLabel{formalParameters}
562 638
639 \LMHash{}
563 Every function includes a {\em formal parameter list}, which consists of a list of required positional parameters (\ref{requiredFormals}), followed by any optio nal parameters (\ref{optionalFormals}). The optional parameters may be specified either as a set of named parameters or as a list of positional parameters, but not both. 640 Every function includes a {\em formal parameter list}, which consists of a list of required positional parameters (\ref{requiredFormals}), followed by any optio nal parameters (\ref{optionalFormals}). The optional parameters may be specified either as a set of named parameters or as a list of positional parameters, but not both.
564 641
642 \LMHash{}
565 The formal parameter list of a function introduces a new scope known as the func tion's {\em formal parameter scope}. The formal parameter scope of a function $f $ is enclosed in the scope where $f$ is declared. Every formal parameter intr oduces a local variable into the formal parameter scope. However, the scope of a function's signature is the function's enclosing scope, not the formal paramete r scope. 643 The formal parameter list of a function introduces a new scope known as the func tion's {\em formal parameter scope}. The formal parameter scope of a function $f $ is enclosed in the scope where $f$ is declared. Every formal parameter intr oduces a local variable into the formal parameter scope. However, the scope of a function's signature is the function's enclosing scope, not the formal paramete r scope.
566 644
645 \LMHash{}
567 The body of a function introduces a new scope known as the function's {\em body scope}. The body scope of a function $f$ is enclosed in the scope introduced by the formal parameter scope of $f$. 646 The body of a function introduces a new scope known as the function's {\em body scope}. The body scope of a function $f$ is enclosed in the scope introduced by the formal parameter scope of $f$.
568 647
569 648
570 %The formal parameter scope of a function maps the name of each formal parameter $p$ to the value $p$ is bound to. 649 %The formal parameter scope of a function maps the name of each formal parameter $p$ to the value $p$ is bound to.
571 650
572 % The formal parameters of a function are processed in the enclosing scope of th e function. 651 % The formal parameters of a function are processed in the enclosing scope of th e function.
573 % \commentary{this means that the parameters themselves may not be referenced wi thin the formal parameter list.} 652 % \commentary{this means that the parameters themselves may not be referenced wi thin the formal parameter list.}
574 653
654 \LMHash{}
575 It is a compile-time error if a formal parameter is declared as a constant varia ble (\ref{variables}). 655 It is a compile-time error if a formal parameter is declared as a constant varia ble (\ref{variables}).
576 656
577 \begin{grammar} 657 \begin{grammar}
578 {\bf formalParameterList:}`(' `)'; 658 {\bf formalParameterList:}`(' `)';
579 `(' normalFormalParameters ( `,' optionalFormalParameters)? `)'; 659 `(' normalFormalParameters ( `,' optionalFormalParameters)? `)';
580 `(' optionalFormalParameters `)' 660 `(' optionalFormalParameters `)'
581 . 661 .
582 %\end{grammar} 662 %\end{grammar}
583 %} 663 %}
584 664
(...skipping 19 matching lines...) Expand all
604 `\{' defaultNamedParameter (`,' defaultNamedParameter)* `\}' 684 `\{' defaultNamedParameter (`,' defaultNamedParameter)* `\}'
605 . 685 .
606 \end{grammar} 686 \end{grammar}
607 687
608 %Formal parameters are always \FINAL{}. 688 %Formal parameters are always \FINAL{}.
609 %\Q{We're awaiting some data on whether enforcing this would cause widespread pa in.} 689 %\Q{We're awaiting some data on whether enforcing this would cause widespread pa in.}
610 %A formal parameter is always considered to be initialized. \rationale{This is because it will always be initialized by the call - even if it is optional.} 690 %A formal parameter is always considered to be initialized. \rationale{This is because it will always be initialized by the call - even if it is optional.}
611 691
612 692
613 \subsubsection{Required Formals} 693 \subsubsection{Required Formals}
614 \label{requiredFormals} 694 \LMLabel{requiredFormals}
615 695
696 \LMHash{}
616 A {\em required formal parameter} may be specified in one of three ways: 697 A {\em required formal parameter} may be specified in one of three ways:
617 \begin{itemize} 698 \begin{itemize}
618 \item By means of a function signature that names the parameter and describes it s type as a function type (\ref{functionTypes}). It is a compile-time error if any default values are specified in the signature of such a function type.% expl ain what the type is in this case? Where is this described in general? 699 \item By means of a function signature that names the parameter and describes it s type as a function type (\ref{functionTypes}). It is a compile-time error if any default values are specified in the signature of such a function type.% expl ain what the type is in this case? Where is this described in general?
619 \item As an initializing formal, which is only valid as a parameter to a generat ive constructor (\ref{generativeConstructors}). % do we need to say this, or any thing more? 700 \item As an initializing formal, which is only valid as a parameter to a generat ive constructor (\ref{generativeConstructors}). % do we need to say this, or any thing more?
620 \item Via an ordinary variable declaration (\ref{variables}). 701 \item Via an ordinary variable declaration (\ref{variables}).
621 \end{itemize} 702 \end{itemize}
622 703
623 \begin{grammar} 704 \begin{grammar}
624 {\bf normalFormalParameter:}functionSignature; 705 {\bf normalFormalParameter:}functionSignature;
625 fieldFormalParameter; 706 fieldFormalParameter;
(...skipping 12 matching lines...) Expand all
638 %\subsubsection{Rest Formals} 719 %\subsubsection{Rest Formals}
639 720
640 %A rest formal $R$ must be the last parameter in a formal parameter list. If a type $T$ is specified for $R$, it signifies that the type of $R$ is $T[]$. 721 %A rest formal $R$ must be the last parameter in a formal parameter list. If a type $T$ is specified for $R$, it signifies that the type of $R$ is $T[]$.
641 722
642 %\begin{grammar} 723 %\begin{grammar}
643 %restFormalParameter: 724 %restFormalParameter:
644 % finalConstVarOrType? '{\escapegrammar ...}' identifier 725 % finalConstVarOrType? '{\escapegrammar ...}' identifier
645 %\end{grammar} 726 %\end{grammar}
646 727
647 \subsubsection{Optional Formals} 728 \subsubsection{Optional Formals}
648 \label{optionalFormals} 729 \LMLabel{optionalFormals}
649 730
731 \LMHash{}
650 Optional parameters may be specified and provided with default values. 732 Optional parameters may be specified and provided with default values.
651 733
652 \begin{grammar} 734 \begin{grammar}
653 {\bf defaultFormalParameter:} 735 {\bf defaultFormalParameter:}
654 normalFormalParameter ('=' expression)? 736 normalFormalParameter ('=' expression)?
655 . 737 .
656 738
657 {\bf defaultNamedParameter:} 739 {\bf defaultNamedParameter:}
658 normalFormalParameter ( `{\escapegrammar :}' expression)? 740 normalFormalParameter ( `{\escapegrammar :}' expression)?
659 . 741 .
660 \end{grammar} 742 \end{grammar}
661 743
744 \LMHash{}
662 It is a compile-time error if the default value of an optional parameter is not a compile-time constant (\ref{constants}). If no default is explicitly specified for an optional parameter an implicit default of \NULL{} is provided. 745 It is a compile-time error if the default value of an optional parameter is not a compile-time constant (\ref{constants}). If no default is explicitly specified for an optional parameter an implicit default of \NULL{} is provided.
663 746
747 \LMHash{}
664 It is a compile-time error if the name of a named optional parameter begins with an `\_' character. 748 It is a compile-time error if the name of a named optional parameter begins with an `\_' character.
665 749
666 \rationale{ 750 \rationale{
667 The need for this restriction is a direct consequence of the fact that naming a nd privacy are not orthogonal. 751 The need for this restriction is a direct consequence of the fact that naming a nd privacy are not orthogonal.
668 If we allowed named parameters to begin with an underscore, they would be consid ered private and inaccessible to callers from outside the library where it was d efined. If a method outside the library overrode a method with a private optiona l name, it would not be a subtype of the original method. The static checker wou ld of course flag such situations, but the consequence would be that adding a pr ivate named formal would break clients outside the library in a way they could n ot easily correct. 752 If we allowed named parameters to begin with an underscore, they would be consid ered private and inaccessible to callers from outside the library where it was d efined. If a method outside the library overrode a method with a private optiona l name, it would not be a subtype of the original method. The static checker wou ld of course flag such situations, but the consequence would be that adding a pr ivate named formal would break clients outside the library in a way they could n ot easily correct.
669 } 753 }
670 754
671 \subsection{Type of a Function} 755 \subsection{Type of a Function}
672 \label{typeOfAFunction} 756 \LMLabel{typeOfAFunction}
673 757
758 \LMHash{}
674 If a function does not declare a return type explicitly, its return type is \DYN AMIC{} (\ref{typeDynamic}). 759 If a function does not declare a return type explicitly, its return type is \DYN AMIC{} (\ref{typeDynamic}).
675 760
761 \LMHash{}
676 Let $F$ be a function with required formal parameters $T_1$ $p_1 \ldots, T_n$ $p _n$, return type $T_0$ and no optional parameters. Then the type of $F$ is $(T_1 ,\ldots, T_n) \rightarrow T_0$. 762 Let $F$ be a function with required formal parameters $T_1$ $p_1 \ldots, T_n$ $p _n$, return type $T_0$ and no optional parameters. Then the type of $F$ is $(T_1 ,\ldots, T_n) \rightarrow T_0$.
677 763
764 \LMHash{}
678 Let $F$ be a function with required formal parameters $T_1$ $p_1 \ldots, T_n$ $p _n$, return type $T_0$ and positional optional parameters $T_{n+1}$ $p_{n+1}, \l dots, T_{n+k}$ $ p_{n+k}$. Then the type of $F$ is $(T_1 ,\ldots, T_n, [T_{n+1}$ $p_{n+1}, \ldots, T_{n+k}$ $p_{n+k}]) \rightarrow T_0$. 765 Let $F$ be a function with required formal parameters $T_1$ $p_1 \ldots, T_n$ $p _n$, return type $T_0$ and positional optional parameters $T_{n+1}$ $p_{n+1}, \l dots, T_{n+k}$ $ p_{n+k}$. Then the type of $F$ is $(T_1 ,\ldots, T_n, [T_{n+1}$ $p_{n+1}, \ldots, T_{n+k}$ $p_{n+k}]) \rightarrow T_0$.
679 766
767 \LMHash{}
680 Let $F$ be a function with required formal parameters $T_1$ $p_1 \ldots, T_n$ $p _n$, return type $T_0$ and named optional parameters $T_{n+1}$ $p_{n+1}, \ldots, T_{n+k}$ $ p_{n+k}$. Then the type of $F$ is $(T_1 ,\ldots, T_n, \{T_{n+1}$ $p_ {n+1}, \ldots, T_{n+k}$ $p_{n+k}\}) \rightarrow T_0$. 768 Let $F$ be a function with required formal parameters $T_1$ $p_1 \ldots, T_n$ $p _n$, return type $T_0$ and named optional parameters $T_{n+1}$ $p_{n+1}, \ldots, T_{n+k}$ $ p_{n+k}$. Then the type of $F$ is $(T_1 ,\ldots, T_n, \{T_{n+1}$ $p_ {n+1}, \ldots, T_{n+k}$ $p_{n+k}\}) \rightarrow T_0$.
681 769
770 \LMHash{}
682 The run time type of a function object always implements the class \cd{Function} . 771 The run time type of a function object always implements the class \cd{Function} .
683 772
684 \commentary{ 773 \commentary{
685 One cannot assume, based on the above, that given a function \cd{f}, \cd{f.runt imeType} will actually be \cd{Function}, or that any two distinct function objec ts necessarily have the same runtime type. 774 One cannot assume, based on the above, that given a function \cd{f}, \cd{f.runt imeType} will actually be \cd{Function}, or that any two distinct function objec ts necessarily have the same runtime type.
686 } 775 }
687 776
688 \rationale{ 777 \rationale{
689 It is up to the implementation to choose an appropriate representation for funct ions. 778 It is up to the implementation to choose an appropriate representation for funct ions.
690 For example, consider that a closure produced via property extraction treats equ ality different from ordinary closures, and is therefore likely a different clas s. Implementations may also use different classes for functions based on arity a nd or type. Arity may be implicitly affected by whether a function is an instanc e method (with an implicit receiver parameter) or not. The variations are manifo ld, and so this specification only guarantees that function objects are instance s of some class that is considered to implement \cd{Function}. 779 For example, consider that a closure produced via property extraction treats equ ality different from ordinary closures, and is therefore likely a different clas s. Implementations may also use different classes for functions based on arity a nd or type. Arity may be implicitly affected by whether a function is an instanc e method (with an implicit receiver parameter) or not. The variations are manifo ld, and so this specification only guarantees that function objects are instance s of some class that is considered to implement \cd{Function}.
691 780
692 } 781 }
693 782
694 \subsection{External Functions} 783 \subsection{External Functions}
695 \label{externalFunctions} 784 \LMLabel{externalFunctions}
696 785
786 \LMHash{}
697 An {\em external function} is a function whose body is provided separately from its declaration. An external function may be a top-level function (\ref{librarie sAndScripts}), a method (\ref{instanceMethods}, \ref{staticMethods}), a getter ( \ref{getters}), a setter (\ref{setters}) or a non-redirecting constructor (\ref{ generativeConstructors}, \ref{factories}). External functions are introduced via the built-in identifier \EXTERNAL{} (\ref{identifierReference}) followed by th e function signature. 787 An {\em external function} is a function whose body is provided separately from its declaration. An external function may be a top-level function (\ref{librarie sAndScripts}), a method (\ref{instanceMethods}, \ref{staticMethods}), a getter ( \ref{getters}), a setter (\ref{setters}) or a non-redirecting constructor (\ref{ generativeConstructors}, \ref{factories}). External functions are introduced via the built-in identifier \EXTERNAL{} (\ref{identifierReference}) followed by th e function signature.
698 788
699 \rationale{ 789 \rationale{
700 External functions allow us to introduce type information for code that is not statically known to the Dart compiler. 790 External functions allow us to introduce type information for code that is not statically known to the Dart compiler.
701 } 791 }
702 792
703 \commentary{ 793 \commentary{
704 Examples of external functions might be foreign functions (defined in C, or Java script etc.), primitives of the implementation (as defined by the Dart runtime), or code that was dynamically generated but whose interface is statically known. However, an abstract method is different from an external function, as it has { \em no} body. 794 Examples of external functions might be foreign functions (defined in C, or Java script etc.), primitives of the implementation (as defined by the Dart runtime), or code that was dynamically generated but whose interface is statically known. However, an abstract method is different from an external function, as it has { \em no} body.
705 } 795 }
706 796
797 \LMHash{}
707 An external function is connected to its body by an implementation specific mech anism. Attempting to invoke an external function that has not been connected to its body will raise a \code{NoSuchMethodError} or some subclass thereof. 798 An external function is connected to its body by an implementation specific mech anism. Attempting to invoke an external function that has not been connected to its body will raise a \code{NoSuchMethodError} or some subclass thereof.
708 799
800 \LMHash{}
709 The actual syntax is given in sections \ref{classes} and \ref{librariesAndScript s} below. 801 The actual syntax is given in sections \ref{classes} and \ref{librariesAndScript s} below.
710 802
711 \section{Classes} 803 \section{Classes}
712 \label{classes} 804 \LMLabel{classes}
713 805
806 \LMHash{}
714 A {\em class} defines the form and behavior of a set of objects which are its {\ em instances}. Classes may be defined by class declarations as described below, or via mixin applications (\ref{mixinApplication}). 807 A {\em class} defines the form and behavior of a set of objects which are its {\ em instances}. Classes may be defined by class declarations as described below, or via mixin applications (\ref{mixinApplication}).
715 808
716 \begin{grammar} 809 \begin{grammar}
717 {\bf classDefinition:} 810 {\bf classDefinition:}
718 metadata \ABSTRACT{}? \CLASS{} identifier typeParameters? (superclass mixins?)? interfaces? \\ 811 metadata \ABSTRACT{}? \CLASS{} identifier typeParameters? (superclass mixins?)? interfaces? \\
719 `\{' (metadata classMemberDefinition)* `\}'; 812 `\{' (metadata classMemberDefinition)* `\}';
720 813
721 metadata \ABSTRACT{}? \CLASS{} mixinApplicationClass 814 metadata \ABSTRACT{}? \CLASS{} mixinApplicationClass
722 . 815 .
723 816
(...skipping 30 matching lines...) Expand all
754 {\bf staticFinalDeclarationList:} 847 {\bf staticFinalDeclarationList:}
755 staticFinalDeclaration (`,' staticFinalDeclaration)* 848 staticFinalDeclaration (`,' staticFinalDeclaration)*
756 . 849 .
757 850
758 {\bf staticFinalDeclaration:} 851 {\bf staticFinalDeclaration:}
759 identifier `=' expression 852 identifier `=' expression
760 . 853 .
761 854
762 \end{grammar} 855 \end{grammar}
763 856
857 \LMHash{}
764 A class has constructors, instance members and static members. The instance mem bers of a class are its instance methods, getters, setters and instance variable s. The static members of a class are its static methods, getters, setters and st atic variables. The members of a class are its static and instance members. 858 A class has constructors, instance members and static members. The instance mem bers of a class are its instance methods, getters, setters and instance variable s. The static members of a class are its static methods, getters, setters and st atic variables. The members of a class are its static and instance members.
765 859
766 % A class has a static scope and an instance scope. The enclosing scope of the s tatic scope of a non-generic class is the enclosing scope of the class declarati on. The enclosing scope of the static scope of a generic class is the type param eter scope (\ref{}) of the generic class declaration. 860 % A class has a static scope and an instance scope. The enclosing scope of the s tatic scope of a non-generic class is the enclosing scope of the class declarati on. The enclosing scope of the static scope of a generic class is the type param eter scope (\ref{}) of the generic class declaration.
767 %The enclosing scope of a class' instance scope is the class' static scope. 861 %The enclosing scope of a class' instance scope is the class' static scope.
768 862
769 %The enclosing scope of an instance member declaration is the instance scope of the class in which it is declared. 863 %The enclosing scope of an instance member declaration is the instance scope of the class in which it is declared.
770 864
771 %The enclosing scope of a static member declaration is the static scope of the c lass in which it is declared. 865 %The enclosing scope of a static member declaration is the static scope of the c lass in which it is declared.
772 866
773 867
868 \LMHash{}
774 Every class has a single superclass except class \code{Object} which has no sup erclass. A class may implement a number of interfaces 869 Every class has a single superclass except class \code{Object} which has no sup erclass. A class may implement a number of interfaces
775 %, either 870 %, either
776 by declaring them in its implements clause (\ref{superinterfaces}). 871 by declaring them in its implements clause (\ref{superinterfaces}).
777 % or via interface injection declarations (\ref{interfaceInjection}) outside the class declaration 872 % or via interface injection declarations (\ref{interfaceInjection}) outside the class declaration
778 873
779 874
875 \LMHash{}
780 An {\em abstract class} is 876 An {\em abstract class} is
781 %either 877 %either
782 a class that is explicitly declared with the \ABSTRACT{} modifier, either by m eans of a class declaration or via a type alias (\ref{typedef}) for a mixin appl ication (\ref{mixinApplication}). A {\em concrete class} is a class that is not abstract. 878 a class that is explicitly declared with the \ABSTRACT{} modifier, either by m eans of a class declaration or via a type alias (\ref{typedef}) for a mixin appl ication (\ref{mixinApplication}). A {\em concrete class} is a class that is not abstract.
783 %, or a class that declares at least one abstract method (\ref{abstractInstance Members}). 879 %, or a class that declares at least one abstract method (\ref{abstractInstance Members}).
784 880
785 \rationale{ 881 \rationale{
786 %The abstract modifier for classes is intended to be used in scenarios where an abstract class $A$ inherits from another abstract class $B$. In such a situation , it may be that A$ $itself does not declare any abstract methods. In the absenc e of an abstract modifier on the class, the class would be interpreted as a conc rete class. However, w 882 %The abstract modifier for classes is intended to be used in scenarios where an abstract class $A$ inherits from another abstract class $B$. In such a situation , it may be that A$ $itself does not declare any abstract methods. In the absenc e of an abstract modifier on the class, the class would be interpreted as a conc rete class. However, w
787 We want different behavior for concrete classes and abstract classes. If $A$ is intended to be abstract, we want the static checker to warn about any attempt to instantiate $A$, and we do not want the checker to complain about unimplemented methods in $A$. In contrast, if $A$ is intended to be concrete, the checker sho uld warn about all unimplemented methods, but allow clients to instantiate it fr eely. 883 We want different behavior for concrete classes and abstract classes. If $A$ is intended to be abstract, we want the static checker to warn about any attempt to instantiate $A$, and we do not want the checker to complain about unimplemented methods in $A$. In contrast, if $A$ is intended to be concrete, the checker sho uld warn about all unimplemented methods, but allow clients to instantiate it fr eely.
788 } 884 }
789 885
886 \LMHash{}
790 The {\em interface of class $C$} is an implicit interface that declares instance members that correspond to the instance members declared by $C$, and whose dire ct superinterfaces are the direct superinterfaces of $C$ (\ref{superinterfaces}) . When a class name appears as a type, that name denotes the interface of the cl ass. 887 The {\em interface of class $C$} is an implicit interface that declares instance members that correspond to the instance members declared by $C$, and whose dire ct superinterfaces are the direct superinterfaces of $C$ (\ref{superinterfaces}) . When a class name appears as a type, that name denotes the interface of the cl ass.
791 888
792 % making an exception for the setters generated for final fields is tempting but problematic. 889 % making an exception for the setters generated for final fields is tempting but problematic.
793 % If a super type defines a setter, it will be overridden yet have no impact on the interface. 890 % If a super type defines a setter, it will be overridden yet have no impact on the interface.
794 % Maybe the final field hides the setter in scope? 891 % Maybe the final field hides the setter in scope?
795 % I think the original rules were best. 892 % I think the original rules were best.
796 893
894 \LMHash{}
797 It is a compile-time error if a class declares two members of the same name. 895 It is a compile-time error if a class declares two members of the same name.
798 %, except that a getter and a setter may be declared with the same name provide d both are instance members or both are static members. 896 %, except that a getter and a setter may be declared with the same name provide d both are instance members or both are static members.
799 It is a compile-time error if a class has an instance member and a static member with the same name. 897 It is a compile-time error if a class has an instance member and a static member with the same name.
800 % It is a compile-time error if a generic (\ref{generics}) class declares a memb er with the same name as one of its type parameters. 898 % It is a compile-time error if a generic (\ref{generics}) class declares a memb er with the same name as one of its type parameters.
801 899
802 \commentary{Here are simple examples, that illustrate the difference between ``h as a member'' and ``declares a member''. For example, \code{B} {\em declares} on e member named \code{f}, but {\em has} two such members. The rules of inheritanc e determine what members a class has. 900 \commentary{Here are simple examples, that illustrate the difference between ``h as a member'' and ``declares a member''. For example, \code{B} {\em declares} on e member named \code{f}, but {\em has} two such members. The rules of inheritanc e determine what members a class has.
803 } 901 }
804 902
805 \begin{dartCode} 903 \begin{dartCode}
806 \CLASS{} A \{ 904 \CLASS{} A \{
807 \VAR{} i = 0; 905 \VAR{} i = 0;
808 \VAR{} j; 906 \VAR{} j;
809 f(x) =$>$ 3; 907 f(x) =$>$ 3;
810 \} 908 \}
811 909
812 \CLASS{} B \EXTENDS{} A \{ 910 \CLASS{} B \EXTENDS{} A \{
813 int i = 1; // getter i and setter i= override versions from A 911 int i = 1; // getter i and setter i= override versions from A
814 \STATIC{} j; // compile-time error: static getter \& setter conflict with 912 \STATIC{} j; // compile-time error: static getter \& setter conflict with
815 //instance getter \& setter 913 //instance getter \& setter
816 914
817 /* compile-time error: static method conflicts with instance method */ 915 /* compile-time error: static method conflicts with instance method */
818 \STATIC{} f(x) =$>$ 3; 916 \STATIC{} f(x) =$>$ 3;
819 \} 917 \}
820 \end{dartCode} 918 \end{dartCode}
821 919
920 \LMHash{}
822 It is a compile time error if a class $C$ declares a member with the same name a s $C$. It is a compile time error if a generic class declares a type variable wi th the same name as the class or any of its members or constructors. 921 It is a compile time error if a class $C$ declares a member with the same name a s $C$. It is a compile time error if a generic class declares a type variable wi th the same name as the class or any of its members or constructors.
823 922
824 \subsection{Instance Methods} 923 \subsection{Instance Methods}
825 \label{instanceMethods} 924 \LMLabel{instanceMethods}
826 925
926 \LMHash{}
827 Instance methods are functions (\ref{functions}) whose declarations are immediat ely contained within a class declaration and that are not declared \STATIC{}. Th e instance methods of a class $C$ are those instance methods declared by $C$ and the instance methods inherited by $C$ from its superclass. 927 Instance methods are functions (\ref{functions}) whose declarations are immediat ely contained within a class declaration and that are not declared \STATIC{}. Th e instance methods of a class $C$ are those instance methods declared by $C$ and the instance methods inherited by $C$ from its superclass.
828 928
829 %make these warnings if possible 929 %make these warnings if possible
830 930
931 \LMHash{}
831 It is a static warning if an instance method $m_1$ overrides (\ref{inheritanceA ndOverriding}) an instance member $m_2$ and $m_1$ has a greater number of requi red parameters than $m_2$. It is a static warning if an instance method $m_1$ ov errides an instance member $m_2$ and $m_1$ has fewer positional parameters tha n $m_2$. It is a static warning if an instance method $m_1$ overrides an insta nce member $m_2$ and $m_1$ does not declare all the named parameters declared b y $m_2$. 932 It is a static warning if an instance method $m_1$ overrides (\ref{inheritanceA ndOverriding}) an instance member $m_2$ and $m_1$ has a greater number of requi red parameters than $m_2$. It is a static warning if an instance method $m_1$ ov errides an instance member $m_2$ and $m_1$ has fewer positional parameters tha n $m_2$. It is a static warning if an instance method $m_1$ overrides an insta nce member $m_2$ and $m_1$ does not declare all the named parameters declared b y $m_2$.
832 933
833 % not quite right. It should be ok to override a method that requires N paramete rs with one that requires M < N but accepts the others as optional. 934 % not quite right. It should be ok to override a method that requires N paramete rs with one that requires M < N but accepts the others as optional.
834 935
936 \LMHash{}
835 It is a static warning if an instance method $m_1$ overrides an instance member $m_2$ and the type of $m_1$ is not a subtype of the type of $m_2$. It is a stati c warning if an instance method $m_1$ overrides an instance member $m_2$, the s ignature of $m_2$ explicitly specifies a default value for a formal parameter $p $ and the signature of $m_1$ implies a different default value for $p$. It is a static warning if a class $C$ declares an instance method named $n$ and has a se tter named $n=$. It is a static warning if a class $C$ declares an instance meth od named $n$ and an accessible static member named $n$ is declared in a supercla ss of $C$. 937 It is a static warning if an instance method $m_1$ overrides an instance member $m_2$ and the type of $m_1$ is not a subtype of the type of $m_2$. It is a stati c warning if an instance method $m_1$ overrides an instance member $m_2$, the s ignature of $m_2$ explicitly specifies a default value for a formal parameter $p $ and the signature of $m_1$ implies a different default value for $p$. It is a static warning if a class $C$ declares an instance method named $n$ and has a se tter named $n=$. It is a static warning if a class $C$ declares an instance meth od named $n$ and an accessible static member named $n$ is declared in a supercla ss of $C$.
836 938
837 % Works. If the name is public, no issue. If it's private, if a subclass has a c onflicting inst var, it either is in the same lib and will be flagged, or is in another and is not an issue. 939 % Works. If the name is public, no issue. If it's private, if a subclass has a c onflicting inst var, it either is in the same lib and will be flagged, or is in another and is not an issue.
838 940
839 941
840 \subsubsection{Operators} 942 \subsubsection{Operators}
841 \label{operators} 943 \LMLabel{operators}
842 944
945 \LMHash{}
843 {\em Operators} are instance methods with special names. 946 {\em Operators} are instance methods with special names.
844 947
845 \begin{grammar} 948 \begin{grammar}
846 {\bf operatorSignature:} 949 {\bf operatorSignature:}
847 returnType? \OPERATOR{} operator formalParameterList 950 returnType? \OPERATOR{} operator formalParameterList
848 . 951 .
849 952
850 {\bf operator:}`\~{}'; 953 {\bf operator:}`\~{}';
851 binaryOperator; 954 binaryOperator;
852 `[' `]' ; 955 `[' `]' ;
853 `[' `]' `=' 956 `[' `]' `='
854 . 957 .
855 958
856 {\bf binaryOperator:}multiplicativeOperator; 959 {\bf binaryOperator:}multiplicativeOperator;
857 additiveOperator; 960 additiveOperator;
858 shiftOperator; 961 shiftOperator;
859 relationalOperator; 962 relationalOperator;
860 `=='; 963 `==';
861 bitwiseOperator 964 bitwiseOperator
862 . 965 .
863 \end{grammar} 966 \end{grammar}
864 967
968 \LMHash{}
865 An operator declaration is identified using the built-in identifier (\ref{identi fierReference}) \OPERATOR{}. 969 An operator declaration is identified using the built-in identifier (\ref{identi fierReference}) \OPERATOR{}.
866 970
971 \LMHash{}
867 The following names are allowed for user-defined operators: \code{$<$, $>$, $<$= , $>$=, ==, -, +, /, \~{}/, *, \%, $|$, \^{}, \&, $<<$, $>>$, []=, [], \~{}.} 972 The following names are allowed for user-defined operators: \code{$<$, $>$, $<$= , $>$=, ==, -, +, /, \~{}/, *, \%, $|$, \^{}, \&, $<<$, $>>$, []=, [], \~{}.}
868 973
869 974
975 \LMHash{}
870 It is a compile-time error if the arity of the user-declared operator \code{[]=} is not 2. It is a compile-time error if the arity of a user-declared operator w ith one of the names: \code{ $<$, $>$, $<$=, $>$=, ==, -, +, \~{}/, /, *, \%, $|$, \^{}, \&, $<<$, $>>$, []} is not 1. It is a compile-time error if the arity of the user-declared operator \code{-} is not 0 or 1. 976 It is a compile-time error if the arity of the user-declared operator \code{[]=} is not 2. It is a compile-time error if the arity of a user-declared operator w ith one of the names: \code{ $<$, $>$, $<$=, $>$=, ==, -, +, \~{}/, /, *, \%, $|$, \^{}, \&, $<<$, $>>$, []} is not 1. It is a compile-time error if the arity of the user-declared operator \code{-} is not 0 or 1.
871 977
872 \commentary{ 978 \commentary{
873 The \code{-} operator is unique in that two overloaded versions are permitted. I f the operator has no arguments, it denotes unary minus. If it has an argument, it denotes binary subtraction. 979 The \code{-} operator is unique in that two overloaded versions are permitted. I f the operator has no arguments, it denotes unary minus. If it has an argument, it denotes binary subtraction.
874 } 980 }
875 981
982 \LMHash{}
876 The name of the unary operator \code{-} is \code{unary-}. 983 The name of the unary operator \code{-} is \code{unary-}.
877 984
878 \rationale{ 985 \rationale{
879 This device allows the two methods to be distinguished for purposes of method lo okup, override and reflection. 986 This device allows the two methods to be distinguished for purposes of method lo okup, override and reflection.
880 } 987 }
881 988
989 \LMHash{}
882 It is a compile-time error if the arity of the user-declared operator \code{ \~ {}} is not 0. 990 It is a compile-time error if the arity of the user-declared operator \code{ \~ {}} is not 0.
883 991
992 \LMHash{}
884 It is a compile-time error to declare an optional parameter in an operator. 993 It is a compile-time error to declare an optional parameter in an operator.
885 994
995 \LMHash{}
886 It is a static warning if the return type of the user-declared operator \code{[] =} is explicitly declared and not \VOID{}. 996 It is a static warning if the return type of the user-declared operator \code{[] =} is explicitly declared and not \VOID{}.
887 997
888 998
889 \subsection{Getters} 999 \subsection{Getters}
890 \label{getters} 1000 \LMLabel{getters}
891 1001
1002 \LMHash{}
892 Getters are functions (\ref{functions}) that are used to retrieve the values of object properties. 1003 Getters are functions (\ref{functions}) that are used to retrieve the values of object properties.
893 1004
894 \begin{grammar} 1005 \begin{grammar}
895 {\bf getterSignature:} 1006 {\bf getterSignature:}
896 returnType? \GET{} identifier 1007 returnType? \GET{} identifier
897 . 1008 .
898 \end{grammar} 1009 \end{grammar}
899 1010
900 %\Q{Why does a getter have a formal parameter list at all?} 1011 %\Q{Why does a getter have a formal parameter list at all?}
901 1012
1013 \LMHash{}
902 If no return type is specified, the return type of the getter is \DYNAMIC{}. 1014 If no return type is specified, the return type of the getter is \DYNAMIC{}.
903 1015
1016 \LMHash{}
904 A getter definition that is prefixed with the \STATIC{} modifier defines a stati c getter. Otherwise, it defines an instance getter. The name of the getter is gi ven by the identifier in the definition. The effect of a static getter declarati on in class $C$ is to add an instance getter with the same name and signature to the \code{Type} object for class $C$ that forwards (\ref{functionDeclarations}) to the static getter. 1017 A getter definition that is prefixed with the \STATIC{} modifier defines a stati c getter. Otherwise, it defines an instance getter. The name of the getter is gi ven by the identifier in the definition. The effect of a static getter declarati on in class $C$ is to add an instance getter with the same name and signature to the \code{Type} object for class $C$ that forwards (\ref{functionDeclarations}) to the static getter.
905 1018
906 %It is a compile-time error if a getter`s formal parameter list is not empty. 1019 %It is a compile-time error if a getter`s formal parameter list is not empty.
907 1020
1021 \LMHash{}
908 The instance getters of a class $C$ are those instance getters declared by $C$, either implicitly or explicitly, and the instance getters inherited by $C$ from its superclass. The static getters of a class $C$ are those static getters decla red by $C$. 1022 The instance getters of a class $C$ are those instance getters declared by $C$, either implicitly or explicitly, and the instance getters inherited by $C$ from its superclass. The static getters of a class $C$ are those static getters decla red by $C$.
909 1023
1024 \LMHash{}
910 It is a compile-time error if a class has both a getter and a method with the sa me name. This restriction holds regardless of whether the getter is defined expl icitly or implicitly, or whether the getter or the method are inherited or not. 1025 It is a compile-time error if a class has both a getter and a method with the sa me name. This restriction holds regardless of whether the getter is defined expl icitly or implicitly, or whether the getter or the method are inherited or not.
911 1026
912 \commentary{ 1027 \commentary{
913 This implies that a getter can never override a method, and a method can never o verride a getter or field. 1028 This implies that a getter can never override a method, and a method can never o verride a getter or field.
914 } 1029 }
915 1030
1031 \LMHash{}
916 It is a static warning if the return type of a getter is \VOID. 1032 It is a static warning if the return type of a getter is \VOID.
917 It is a static warning if a getter $m_1$ overrides (\ref{inheritanceAndOverridi ng}) a getter 1033 It is a static warning if a getter $m_1$ overrides (\ref{inheritanceAndOverridi ng}) a getter
918 $m_2$ and the type of $m_1$ is not a subtype of the type of $m_2$. 1034 $m_2$ and the type of $m_1$ is not a subtype of the type of $m_2$.
919 1035
1036 \LMHash{}
920 It is a static warning if a class declares a static getter named $v$ and also h as a non-static setter named $v=$. It is a static warning if a class $C$ declare s an instance getter named $v$ and an accessible static member named $v$ or $v=$ is declared in a superclass of $C$. These warnings must be issued regardless of whether the getters or setters are declared explicitly or implicitly. 1037 It is a static warning if a class declares a static getter named $v$ and also h as a non-static setter named $v=$. It is a static warning if a class $C$ declare s an instance getter named $v$ and an accessible static member named $v$ or $v=$ is declared in a superclass of $C$. These warnings must be issued regardless of whether the getters or setters are declared explicitly or implicitly.
921 1038
922 \subsection{Setters} 1039 \subsection{Setters}
923 \label{setters} 1040 \LMLabel{setters}
924 1041
1042 \LMHash{}
925 Setters are functions (\ref{functions}) that are used to set the values of objec t properties. 1043 Setters are functions (\ref{functions}) that are used to set the values of objec t properties.
926 1044
927 % what about top level ones? Same for getters 1045 % what about top level ones? Same for getters
928 1046
929 \begin{grammar} 1047 \begin{grammar}
930 {\bf setterSignature:} 1048 {\bf setterSignature:}
931 returnType? \SET{} identifier formalParameterList 1049 returnType? \SET{} identifier formalParameterList
932 . 1050 .
933 \end{grammar} 1051 \end{grammar}
934 1052
1053 \LMHash{}
935 If no return type is specified, the return type of the setter is \DYNAMIC{}. 1054 If no return type is specified, the return type of the setter is \DYNAMIC{}.
936 1055
1056 \LMHash{}
937 A setter definition that is prefixed with the \STATIC{} modifier defines a stati c setter. Otherwise, it defines an instance setter. The name of a setter is obt ained by appending the string `=' to the identifier given in its signature. Th e effect of a static setter declaration in class $C$ is to add an instance sette r with the same name and signature to the \code{Type} object for class $C$ that forwards (\ref{functionDeclarations}) to the static setter. 1057 A setter definition that is prefixed with the \STATIC{} modifier defines a stati c setter. Otherwise, it defines an instance setter. The name of a setter is obt ained by appending the string `=' to the identifier given in its signature. Th e effect of a static setter declaration in class $C$ is to add an instance sette r with the same name and signature to the \code{Type} object for class $C$ that forwards (\ref{functionDeclarations}) to the static setter.
938 1058
939 \commentary{Hence, a setter name can never conflict with, override or be overrid den by a getter or method.} 1059 \commentary{Hence, a setter name can never conflict with, override or be overrid den by a getter or method.}
940 1060
1061 \LMHash{}
941 The instance setters of a class $C$ are those instance setters declared by $C$ e ither implicitly or explicitly, and the instance setters inherited by $C$ from i ts superclass. The static setters of a class $C$ are those static setters declar ed by $C$. 1062 The instance setters of a class $C$ are those instance setters declared by $C$ e ither implicitly or explicitly, and the instance setters inherited by $C$ from i ts superclass. The static setters of a class $C$ are those static setters declar ed by $C$.
942 1063
1064 \LMHash{}
943 It is a compile-time error if a setter's formal parameter list does not consist of exactly one required formal parameter $p$. \rationale{We could enforce this via the grammar, but we'd have to specify the evaluation rules in that case.} 1065 It is a compile-time error if a setter's formal parameter list does not consist of exactly one required formal parameter $p$. \rationale{We could enforce this via the grammar, but we'd have to specify the evaluation rules in that case.}
944 1066
945 %It is a compile-time error if a class has both a setter and a method with the s ame name. This restriction holds regardless of whether the setter is defined exp licitly or implicitly, or whether the setter or the method are inherited or not. 1067 %It is a compile-time error if a class has both a setter and a method with the s ame name. This restriction holds regardless of whether the setter is defined exp licitly or implicitly, or whether the setter or the method are inherited or not.
946 1068
1069 \LMHash{}
947 It is a static warning if a setter declares a return type other than \VOID{}. 1070 It is a static warning if a setter declares a return type other than \VOID{}.
948 It is a static warning if a setter $m_1$ overrides (\ref{inheritanceAndOverridi ng}) a setter $m_2$ and the type of $m_1$ is not a subtype of the type of $m_2$. It is a static warning if a class has a setter named $v=$ with argument type $T $ and a getter named $v$ with return type $S$, and $T$ may not be assigned to $S $. 1071 It is a static warning if a setter $m_1$ overrides (\ref{inheritanceAndOverridi ng}) a setter $m_2$ and the type of $m_1$ is not a subtype of the type of $m_2$. It is a static warning if a class has a setter named $v=$ with argument type $T $ and a getter named $v$ with return type $S$, and $T$ may not be assigned to $S $.
949 1072
1073 \LMHash{}
950 It is a static warning if a class declares a static setter named $v=$ and also has a non-static member named $v$. It is a static warning if a class $C$ declare s an instance setter named $v=$ and an accessible static member named $v=$ or $v $ is declared in a superclass of $C$. 1074 It is a static warning if a class declares a static setter named $v=$ and also has a non-static member named $v$. It is a static warning if a class $C$ declare s an instance setter named $v=$ and an accessible static member named $v=$ or $v $ is declared in a superclass of $C$.
951 1075
1076 \LMHash{}
952 These warnings must be issued regardless of whether the getters or setters are d eclared explicitly or implicitly. 1077 These warnings must be issued regardless of whether the getters or setters are d eclared explicitly or implicitly.
953 1078
954 \subsection{Abstract Instance Members} 1079 \subsection{Abstract Instance Members}
955 \label{abstractInstanceMembers} 1080 \LMLabel{abstractInstanceMembers}
956 1081
1082 \LMHash{}
957 An {\em abstract method} (respectively, {\em abstract getter} or {\em abstract s etter)} is an instance method, getter or setter that is not declared \EXTERNAL{} and does not provide an implementation. A {\em concrete method} (respectively, {\em concrete getter} or {\em concrete setter)} is an instance method, getter o r setter that is not abstract. 1083 An {\em abstract method} (respectively, {\em abstract getter} or {\em abstract s etter)} is an instance method, getter or setter that is not declared \EXTERNAL{} and does not provide an implementation. A {\em concrete method} (respectively, {\em concrete getter} or {\em concrete setter)} is an instance method, getter o r setter that is not abstract.
958 %The declaration of an abstract method is prefixed by the built-in identifier (\ ref{identifierReference}) \ABSTRACT{}. 1084 %The declaration of an abstract method is prefixed by the built-in identifier (\ ref{identifierReference}) \ABSTRACT{}.
959 1085
960 \rationale{ 1086 \rationale{
961 Earlier versions of Dart required that abstract members be identified by prefixi ng them with the modifier \ABSTRACT{}. The elimination of this requirement is m otivated by the desire to use abstract classes as interfaces. Every Dart class i nduces an implicit interface. 1087 Earlier versions of Dart required that abstract members be identified by prefixi ng them with the modifier \ABSTRACT{}. The elimination of this requirement is m otivated by the desire to use abstract classes as interfaces. Every Dart class i nduces an implicit interface.
962 1088
963 Using an abstract class instead of an interface has important advantages. An abs tract class can provide default implementations; it can also provide static meth ods, obviating the need for service classes such as \code{Collections} or \code{ Lists}, whose entire purpose is to group utilities related to a given type. 1089 Using an abstract class instead of an interface has important advantages. An abs tract class can provide default implementations; it can also provide static meth ods, obviating the need for service classes such as \code{Collections} or \code{ Lists}, whose entire purpose is to group utilities related to a given type.
964 1090
965 Eliminating the requirement for an explicit modifier on members makes abstract c lasses more concise, making abstract classes an attractive substitute for inter face declarations. 1091 Eliminating the requirement for an explicit modifier on members makes abstract c lasses more concise, making abstract classes an attractive substitute for inter face declarations.
966 } 1092 }
967 1093
968 \commentary {Invoking an abstract method, getter or setter results in an invocat ion of \cd{noSuchMethod} exactly as if the declaration did not exist, unless a suitable member $a$ is available in a superclass, in which case $a$ is invoked. The normative specification for this appears under the definitions of lookup fo r methods, getters and setters. 1094 \commentary {Invoking an abstract method, getter or setter results in an invocat ion of \cd{noSuchMethod} exactly as if the declaration did not exist, unless a suitable member $a$ is available in a superclass, in which case $a$ is invoked. The normative specification for this appears under the definitions of lookup fo r methods, getters and setters.
969 } 1095 }
970 1096
971 % so does an abstract method override a method in a superclass or not? Does the superclass method get inherited or not? This generally makes the spec inconsist ent, as there is no simple answer. 1097 % so does an abstract method override a method in a superclass or not? Does the superclass method get inherited or not? This generally makes the spec inconsist ent, as there is no simple answer.
972 % For example - if we say it does not override, then the superclass member is in herited, in which case the rules for warning break down, and also there is quest ion of whether there are two definitions of the same name. 1098 % For example - if we say it does not override, then the superclass member is in herited, in which case the rules for warning break down, and also there is quest ion of whether there are two definitions of the same name.
973 % But if we do override, method lookup rules break down. So several things need revisiting. 1099 % But if we do override, method lookup rules break down. So several things need revisiting.
974 1100
975 \rationale{ 1101 \rationale{
976 The purpose of an abstract method is to provide a declaration for purposes such as type checking and reflection. In classes used as mixins, it is often useful t o introduce such declarations for methods that the mixin expects will be provide d by the superclass the mixin is applied to. 1102 The purpose of an abstract method is to provide a declaration for purposes such as type checking and reflection. In classes used as mixins, it is often useful t o introduce such declarations for methods that the mixin expects will be provide d by the superclass the mixin is applied to.
977 } 1103 }
978 %always results in a run-time error. This must be \code{NoSuchMethodError} or an instance of a subclass of \code{NoSuchMethodError}, such as \code{AbstractMetho dError}. 1104 %always results in a run-time error. This must be \code{NoSuchMethodError} or an instance of a subclass of \code{NoSuchMethodError}, such as \code{AbstractMetho dError}.
979 1105
1106 \LMHash{}
980 It is a static warning if an abstract member is declared or inherited in a concr ete class unless that member overrides a concrete one. 1107 It is a static warning if an abstract member is declared or inherited in a concr ete class unless that member overrides a concrete one.
981 1108
982 \rationale { 1109 \rationale {
983 We wish to warn if one declares a concrete class with abstract members. However, code like the following should work without warnings: 1110 We wish to warn if one declares a concrete class with abstract members. However, code like the following should work without warnings:
984 } 1111 }
985 1112
986 \begin{dartCode} 1113 \begin{dartCode}
987 class Base \{ 1114 class Base \{
988 int get one =$>$ 1; 1115 int get one =$>$ 1;
989 \} 1116 \}
990 1117
991 abstract class Mix \{ 1118 abstract class Mix \{
992 int get one; 1119 int get one;
993 int get two =$>$ one + one; 1120 int get two =$>$ one + one;
994 \} 1121 \}
995 1122
996 class C extends Base with Mix \{ 1123 class C extends Base with Mix \{
997 \} 1124 \}
998 \} 1125 \}
999 \end{dartCode} 1126 \end{dartCode}
1000 1127
1001 \rationale{At run time, the concrete method \cd{one} declared in \cd{Base} will be executed, and no problem should arise. Therefore no warning should be issued and so we suppress warnings if a corresponding concrete member exists in the hie rarchy. } 1128 \rationale{At run time, the concrete method \cd{one} declared in \cd{Base} will be executed, and no problem should arise. Therefore no warning should be issued and so we suppress warnings if a corresponding concrete member exists in the hie rarchy. }
1002 1129
1003 \subsection{Instance Variables} 1130 \subsection{Instance Variables}
1004 \label{instanceVariables} 1131 \LMLabel{instanceVariables}
1005 1132
1133 \LMHash{}
1006 Instance variables are variables whose declarations are immediately contained wi thin a class declaration and that are not declared \STATIC{}. The instance varia bles of a class $C$ are those instance variables declared by $C$ and the instanc e variables inherited by $C$ from its superclass. 1134 Instance variables are variables whose declarations are immediately contained wi thin a class declaration and that are not declared \STATIC{}. The instance varia bles of a class $C$ are those instance variables declared by $C$ and the instanc e variables inherited by $C$ from its superclass.
1007 1135
1136 \LMHash{}
1008 It is a compile-time error if an instance variable is declared to be constant. 1137 It is a compile-time error if an instance variable is declared to be constant.
1009 1138
1010 \rationale{ 1139 \rationale{
1011 The notion of a constant instance variable is subtle and confusing to programmer s. 1140 The notion of a constant instance variable is subtle and confusing to programmer s.
1012 An instance variable is intended to vary per instance. A constant instance varia ble would have the same value for all instances, and as such is already a dubiou s idea. 1141 An instance variable is intended to vary per instance. A constant instance varia ble would have the same value for all instances, and as such is already a dubiou s idea.
1013 1142
1014 The language could interpret const instance variable declarations as instance ge tters that return a constant. However, a constant instance variable could not b e treated as a true compile time constant, as its getter would be subject to ove rriding. 1143 The language could interpret const instance variable declarations as instance ge tters that return a constant. However, a constant instance variable could not b e treated as a true compile time constant, as its getter would be subject to ove rriding.
1015 1144
1016 Given that the value does not depend on the instance, it is better to use a sta tic class variable. 1145 Given that the value does not depend on the instance, it is better to use a sta tic class variable.
1017 An instance getter for it can always be defined manually if desired. 1146 An instance getter for it can always be defined manually if desired.
(...skipping 23 matching lines...) Expand all
1041 %A non-final instance variable declaration of the form \code{\VAR{} $v$;} or th e form \code{\VAR{} $v$ = $e$;} always induces an implicit setter function wi th signature 1170 %A non-final instance variable declaration of the form \code{\VAR{} $v$;} or th e form \code{\VAR{} $v$ = $e$;} always induces an implicit setter function wi th signature
1042 1171
1043 %\SET{} $v=(x)$ 1172 %\SET{} $v=(x)$
1044 1173
1045 %whose execution sets the value of $v$ to the incoming argument $x$. 1174 %whose execution sets the value of $v$ to the incoming argument $x$.
1046 1175
1047 % It is a compile-time error/warning if a class $C$ declares a final instance va riable $v$ and $C$ inherits a setter $v=$. 1176 % It is a compile-time error/warning if a class $C$ declares a final instance va riable $v$ and $C$ inherits a setter $v=$.
1048 1177
1049 1178
1050 \subsection{Constructors} 1179 \subsection{Constructors}
1051 \label{constructors} 1180 \LMLabel{constructors}
1052 1181
1182 \LMHash{}
1053 A {\em constructor} is a special function that is used in instance creation expr essions (\ref{instanceCreation}) to produce objects. Constructors may be generat ive (\ref{generativeConstructors}) or they may be factories (\ref{factories}). 1183 A {\em constructor} is a special function that is used in instance creation expr essions (\ref{instanceCreation}) to produce objects. Constructors may be generat ive (\ref{generativeConstructors}) or they may be factories (\ref{factories}).
1054 1184
1185 \LMHash{}
1055 A {\em constructor name} always begins with the name of its immediately enclosin g class, and may optionally be followed by a dot and an identifier $id$. It is a compile-time error if $id$ is the name of a member declared in the immediately enclosing class. It is a compile-time error if the name of a constructor is no t a constructor name. 1186 A {\em constructor name} always begins with the name of its immediately enclosin g class, and may optionally be followed by a dot and an identifier $id$. It is a compile-time error if $id$ is the name of a member declared in the immediately enclosing class. It is a compile-time error if the name of a constructor is no t a constructor name.
1056 1187
1057 1188
1058 % In what scope do constructors go? The simple names of named constructors go i n the static scope of the class. Unnamed ones go nowhere, but we use the class n ame to refer to them; the class name could also in the static scope of the class as well to prevent weird errors, or we could ban it explicitly and avoiding dup lication. Similarly, the instance scope could contain the constructor names and class name, or we could have special rules to prevent collisions between instanc e members and constructors or the class. 1189 % In what scope do constructors go? The simple names of named constructors go i n the static scope of the class. Unnamed ones go nowhere, but we use the class n ame to refer to them; the class name could also in the static scope of the class as well to prevent weird errors, or we could ban it explicitly and avoiding dup lication. Similarly, the instance scope could contain the constructor names and class name, or we could have special rules to prevent collisions between instanc e members and constructors or the class.
1059 1190
1060 % The enclosing scope of a generative constructor is the instance scope of the c lass in which it is declared (but what about redirecting?) 1191 % The enclosing scope of a generative constructor is the instance scope of the c lass in which it is declared (but what about redirecting?)
1061 1192
1193 \LMHash{}
1062 Iff no constructor is specified for a class $C$, it implicitly has a default con structor \code{C() : \SUPER{}() \{\}}, unless $C$ is class \code{Object}. 1194 Iff no constructor is specified for a class $C$, it implicitly has a default con structor \code{C() : \SUPER{}() \{\}}, unless $C$ is class \code{Object}.
1063 1195
1064 \subsubsection{Generative Constructors} 1196 \subsubsection{Generative Constructors}
1065 \label{generativeConstructors} 1197 \LMLabel{generativeConstructors}
1066 1198
1199 \LMHash{}
1067 A {\em generative constructor} consists of a constructor name, a constructor par ameter list, and either a redirect clause or an initializer list and an optiona l body. 1200 A {\em generative constructor} consists of a constructor name, a constructor par ameter list, and either a redirect clause or an initializer list and an optiona l body.
1068 1201
1069 \begin{grammar} 1202 \begin{grammar}
1070 {\bf constructorSignature:} 1203 {\bf constructorSignature:}
1071 identifier (`{\escapegrammar .}' identifier)? formalParameterList 1204 identifier (`{\escapegrammar .}' identifier)? formalParameterList
1072 . 1205 .
1073 \end{grammar} 1206 \end{grammar}
1074 1207
1208 \LMHash{}
1075 A {\em constructor parameter list} is a parenthesized, comma-separated list of f ormal constructor parameters. A {\em formal constructor parameter} is either a f ormal parameter (\ref{formalParameters}) or an initializing formal. An {\em init ializing formal} has the form \code{\THIS{}.id}, where \code{id} is the name of an instance variable of the immediately enclosing class. It is a compile-time e rror if \code{id} is not an instance variable of the immediately enclosing class . It is a compile-time error if an initializing formal is used by a function oth er than a non-redirecting generative constructor. 1209 A {\em constructor parameter list} is a parenthesized, comma-separated list of f ormal constructor parameters. A {\em formal constructor parameter} is either a f ormal parameter (\ref{formalParameters}) or an initializing formal. An {\em init ializing formal} has the form \code{\THIS{}.id}, where \code{id} is the name of an instance variable of the immediately enclosing class. It is a compile-time e rror if \code{id} is not an instance variable of the immediately enclosing class . It is a compile-time error if an initializing formal is used by a function oth er than a non-redirecting generative constructor.
1076 1210
1211 \LMHash{}
1077 If an explicit type is attached to the initializing formal, that is its static t ype. Otherwise, the type of an initializing formal named \code{id} is $T_{id}$, where $T_{id}$ is the type of the field named \code{id} in the immediately enclo sing class. It is a static warning if the static type of \code{id} is not assign able to $T_{id}$. 1212 If an explicit type is attached to the initializing formal, that is its static t ype. Otherwise, the type of an initializing formal named \code{id} is $T_{id}$, where $T_{id}$ is the type of the field named \code{id} in the immediately enclo sing class. It is a static warning if the static type of \code{id} is not assign able to $T_{id}$.
1078 1213
1214 \LMHash{}
1079 Using an initializing formal \code{\THIS{}.id} in a formal parameter list does n ot introduce a formal parameter name into the scope of the constructor. However, the initializing formal does effect the type of the constructor function exactl y as if a formal parameter named \code{id} of the same type were introduced in the same position. 1215 Using an initializing formal \code{\THIS{}.id} in a formal parameter list does n ot introduce a formal parameter name into the scope of the constructor. However, the initializing formal does effect the type of the constructor function exactl y as if a formal parameter named \code{id} of the same type were introduced in the same position.
1080 1216
1217 \LMHash{}
1081 Initializing formals are executed during the execution of generative constructor s detailed below. Executing an initializing formal \code{\THIS{}.id} causes the field \code{id} of the immediately surrounding class to be assigned the value o f the corresponding actual parameter, unless $id$ is a final variable that has a lready been initialized, in which case a runtime error occurs. 1218 Initializing formals are executed during the execution of generative constructor s detailed below. Executing an initializing formal \code{\THIS{}.id} causes the field \code{id} of the immediately surrounding class to be assigned the value o f the corresponding actual parameter, unless $id$ is a final variable that has a lready been initialized, in which case a runtime error occurs.
1082 1219
1083 1220
1084 \commentary{ 1221 \commentary{
1085 The above rule allows initializing formals to be used as optional parameters: 1222 The above rule allows initializing formals to be used as optional parameters:
1086 } 1223 }
1087 1224
1088 \begin{dartCode} 1225 \begin{dartCode}
1089 class A \{ 1226 class A \{
1090 int x; 1227 int x;
1091 A([this.x]); 1228 A([this.x]);
1092 \} 1229 \}
1093 \end{dartCode} 1230 \end{dartCode}
1094 1231
1095 \commentary{is legal, and has the same effect as} 1232 \commentary{is legal, and has the same effect as}
1096 1233
1097 \begin{dartCode} 1234 \begin{dartCode}
1098 class A \{ 1235 class A \{
1099 int x; 1236 int x;
1100 A([int x]): this.x = x; 1237 A([int x]): this.x = x;
1101 \} 1238 \}
1102 \end{dartCode} 1239 \end{dartCode}
1103 1240
1241 \LMHash{}
1104 A {\em fresh instance} is an instance whose identity is distinct from any previ ously allocated instance of its class. A generative constructor always operates on a fresh instance of its immediately enclosing class. 1242 A {\em fresh instance} is an instance whose identity is distinct from any previ ously allocated instance of its class. A generative constructor always operates on a fresh instance of its immediately enclosing class.
1105 1243
1106 \commentary{ 1244 \commentary{
1107 The above holds if the constructor is actually run, as it is by \NEW{}. If a con structor $c$ is referenced by \CONST{}, $c$ may not be run; instead, a canonical object may be looked up. See the section on instance creation (\ref{instanceCre ation}). 1245 The above holds if the constructor is actually run, as it is by \NEW{}. If a con structor $c$ is referenced by \CONST{}, $c$ may not be run; instead, a canonical object may be looked up. See the section on instance creation (\ref{instanceCre ation}).
1108 } 1246 }
1109 1247
1248 \LMHash{}
1110 If a generative constructor $c$ is not a redirecting constructor and no body is provided, then $c$ implicitly has an empty body \code{\{\}}. 1249 If a generative constructor $c$ is not a redirecting constructor and no body is provided, then $c$ implicitly has an empty body \code{\{\}}.
1111 1250
1112 1251
1113 \paragraph{Redirecting Constructors} 1252 \paragraph{Redirecting Constructors}
1114 \label{redirectingConstructors} 1253 \LMLabel{redirectingConstructors}
1115 1254
1255 \LMHash{}
1116 A generative constructor may be {\em redirecting}, in which case its only action is to invoke another generative constructor. A redirecting constructor has no body; instead, it has a redirect clause that specifies which constructor the inv ocation is redirected to, and with what arguments. 1256 A generative constructor may be {\em redirecting}, in which case its only action is to invoke another generative constructor. A redirecting constructor has no body; instead, it has a redirect clause that specifies which constructor the inv ocation is redirected to, and with what arguments.
1117 1257
1118 \begin{grammar} 1258 \begin{grammar}
1119 {\bf redirection:} 1259 {\bf redirection:}
1120 `{\escapegrammar :}' \THIS{} (`{\escapegrammar .}' identifier)? arguments 1260 `{\escapegrammar :}' \THIS{} (`{\escapegrammar .}' identifier)? arguments
1121 . 1261 .
1122 \end{grammar} 1262 \end{grammar}
1123 1263
1124 % Need to specify exactly how executing a redirecting constructor works 1264 % Need to specify exactly how executing a redirecting constructor works
1125 1265
1126 1266
1127 %\Q{We now have generative constructors with no bodies as well.} 1267 %\Q{We now have generative constructors with no bodies as well.}
1128 1268
1129 \paragraph{Initializer Lists} 1269 \paragraph{Initializer Lists}
1130 1270
1271 \LMHash{}
1131 An initializer list begins with a colon, and consists of a comma-separated list of individual {\em initializers}. There are two kinds of initializers. 1272 An initializer list begins with a colon, and consists of a comma-separated list of individual {\em initializers}. There are two kinds of initializers.
1132 \begin{itemize} 1273 \begin{itemize}
1133 \item A {\em superinitializer} identifies a {\em superconstructor} - that is, a specific constructor of the superclass. Execution of the superinitializer caus es the initializer list of the superconstructor to be executed. 1274 \item A {\em superinitializer} identifies a {\em superconstructor} - that is, a specific constructor of the superclass. Execution of the superinitializer caus es the initializer list of the superconstructor to be executed.
1134 1275
1135 \item An {\em instance variable initializer} assigns a value to an individual in stance variable. 1276 \item An {\em instance variable initializer} assigns a value to an individual in stance variable.
1136 \end{itemize} 1277 \end{itemize}
1137 1278
1138 \begin{grammar} 1279 \begin{grammar}
1139 {\bf initializers:} 1280 {\bf initializers:}
1140 `{\escapegrammar :}' superCallOrFieldInitializer (`,' superCallOrFieldInit ializer)* 1281 `{\escapegrammar :}' superCallOrFieldInitializer (`,' superCallOrFieldInit ializer)*
1141 . 1282 .
1142 1283
1143 1284
1144 {\bf superCallOrFieldInitializer:}\SUPER{} arguments; 1285 {\bf superCallOrFieldInitializer:}\SUPER{} arguments;
1145 \SUPER{} `{\escapegrammar .}' identifier arguments; 1286 \SUPER{} `{\escapegrammar .}' identifier arguments;
1146 fieldInitializer 1287 fieldInitializer
1147 . 1288 .
1148 1289
1149 {\bf fieldInitializer:} 1290 {\bf fieldInitializer:}
1150 (\THIS{} `{\escapegrammar .}')? identifier `=' conditionalExpression casca deSection* 1291 (\THIS{} `{\escapegrammar .}')? identifier `=' conditionalExpression casca deSection*
1151 . 1292 .
1152 1293
1153 \end{grammar} 1294 \end{grammar}
1154 1295
1296 \LMHash{}
1155 Let $k$ be a generative constructor. Then $k$ may include at most one superini tializer in its initializer list or a compile-time error occurs. If no superinit ializer is provided, an implicit superinitializer of the form \SUPER{}() is adde d at the end of $k$'s initializer list, unless the enclosing class is class \cod e{Object}. It is a compile-time error if more than one initializer corresponding to a given instance variable appears in $k$'s initializer list. It is a compile -time error if $k$'s initializer list contains an initializer for a variable tha t is initialized by means of an initializing formal of $k$. % It is a compile-ti me error if $k$'s initializer list contains an initializer for a final variable $f$ whose declaration includes an initialization expression. 1297 Let $k$ be a generative constructor. Then $k$ may include at most one superini tializer in its initializer list or a compile-time error occurs. If no superinit ializer is provided, an implicit superinitializer of the form \SUPER{}() is adde d at the end of $k$'s initializer list, unless the enclosing class is class \cod e{Object}. It is a compile-time error if more than one initializer corresponding to a given instance variable appears in $k$'s initializer list. It is a compile -time error if $k$'s initializer list contains an initializer for a variable tha t is initialized by means of an initializing formal of $k$. % It is a compile-ti me error if $k$'s initializer list contains an initializer for a final variable $f$ whose declaration includes an initialization expression.
1156 1298
1299 \LMHash{}
1157 Each final instance variable $f$ declared in the immediately enclosing class mus t have an initializer in $k$'s initializer list unless it has already been initi alized by one of the following means: 1300 Each final instance variable $f$ declared in the immediately enclosing class mus t have an initializer in $k$'s initializer list unless it has already been initi alized by one of the following means:
1158 \begin{itemize} 1301 \begin{itemize}
1159 \item Initialization at the declaration of $f$. 1302 \item Initialization at the declaration of $f$.
1160 \item Initialization by means of an initializing formal of $k$. 1303 \item Initialization by means of an initializing formal of $k$.
1161 \end{itemize} 1304 \end{itemize}
1162 1305
1163 or a static warning occurs. It is a compile-time error if $k$'s initializer list contains an initializer for a variable that is not an instance variable declare d in the immediately surrounding class. 1306 or a static warning occurs. It is a compile-time error if $k$'s initializer list contains an initializer for a variable that is not an instance variable declare d in the immediately surrounding class.
1164 1307
1165 1308
1166 \commentary{The initializer list may of course contain an initializer for any instance variable declared by the immediately surrounding class, even if it is n ot final. 1309 \commentary{The initializer list may of course contain an initializer for any instance variable declared by the immediately surrounding class, even if it is n ot final.
1167 } 1310 }
1168 1311
1312 \LMHash{}
1169 It is a compile-time error if a generative constructor of class \code{Object} includes a superinitializer. 1313 It is a compile-time error if a generative constructor of class \code{Object} includes a superinitializer.
1170 1314
1315 \LMHash{}
1171 Execution of a generative constructor $k$ is always done with respect to a set o f bindings for its formal parameters and with \THIS{} bound to a fresh instance $i$ and the type parameters of the immediately enclosing class bound to a set o f actual type arguments $V_1, \ldots , V_m$. 1316 Execution of a generative constructor $k$ is always done with respect to a set o f bindings for its formal parameters and with \THIS{} bound to a fresh instance $i$ and the type parameters of the immediately enclosing class bound to a set o f actual type arguments $V_1, \ldots , V_m$.
1172 1317
1173 \commentary{These bindings are usually determined by the instance creation expre ssion that invoked the constructor (directly or indirectly). However, they may a lso be determined by a reflective call,. 1318 \commentary{These bindings are usually determined by the instance creation expre ssion that invoked the constructor (directly or indirectly). However, they may a lso be determined by a reflective call,.
1174 } 1319 }
1175 1320
1321 \LMHash{}
1176 If $k$ is redirecting then its redirect clause has the form 1322 If $k$ is redirecting then its redirect clause has the form
1177 1323
1178 \THIS{}$.g(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 1324 \THIS{}$.g(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
1179 1325
1180 where $g$ identifies another generative constructor of the immediately surround ing class. Then execution of $k$ proceeds by evaluating the argument list $(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, and then executing $g$ with respect to the bindings resulting from the evaluation of $(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ and with \THIS{} bound to $i$ and the type parameters of the immediately enclosing class bound to $V_1, \ ldots , V_m$. 1326 where $g$ identifies another generative constructor of the immediately surround ing class. Then execution of $k$ proceeds by evaluating the argument list $(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, and then executing $g$ with respect to the bindings resulting from the evaluation of $(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ and with \THIS{} bound to $i$ and the type parameters of the immediately enclosing class bound to $V_1, \ ldots , V_m$.
1181 1327
1328 \LMHash{}
1182 Otherwise, execution proceeds as follows: 1329 Otherwise, execution proceeds as follows:
1183 1330
1331 \LMHash{}
1184 %First, a fresh instance (\ref{generativeConstructors}) $i$ of the immediately e nclosing class is allocated. Next, the instance variable declarations of the im mediately enclosing class are visited in the order they appear in the program te xt. For each such declaration $d$, if $d$ has the form \code{$finalConstVarOrTy pe$ $v$ = $e$; } then the instance variable $v$ of $i$ is bound to the value of $e$ (which is necessarily a compile-time constant). 1332 %First, a fresh instance (\ref{generativeConstructors}) $i$ of the immediately e nclosing class is allocated. Next, the instance variable declarations of the im mediately enclosing class are visited in the order they appear in the program te xt. For each such declaration $d$, if $d$ has the form \code{$finalConstVarOrTy pe$ $v$ = $e$; } then the instance variable $v$ of $i$ is bound to the value of $e$ (which is necessarily a compile-time constant).
1185 %Next, a 1333 %Next, a
1186 Any initializing formals declared in $k$'s parameter list are executed in the or der they appear in the program text. 1334 Any initializing formals declared in $k$'s parameter list are executed in the or der they appear in the program text.
1187 % In fact, this order is unobservable; this could be done any time prior to runn ing the body, since 1335 % In fact, this order is unobservable; this could be done any time prior to runn ing the body, since
1188 % these only effect \THIS{}. 1336 % these only effect \THIS{}.
1189 Then, $k$'s initializers are executed in the order they appear in the program. 1337 Then, $k$'s initializers are executed in the order they appear in the program.
1190 1338
1191 \rationale {We could observe the order by side effecting external routines call ed. So we need to specify the order.} 1339 \rationale {We could observe the order by side effecting external routines call ed. So we need to specify the order.}
1192 1340
1341 \LMHash{}
1193 After all the initializers have completed, the body of $k$ is executed in a sc ope where \THIS{} is bound to $i$. Execution of the body begins with execution o f the body of the superconstructor with \THIS{} bound to $i$, the type paramete rs of the immediately enclosing class bound to a set of actual type arguments $V _1, \ldots , V_m$ and the formal parameters bindings determined by the argument list of the superinitializer of $k$. 1342 After all the initializers have completed, the body of $k$ is executed in a sc ope where \THIS{} is bound to $i$. Execution of the body begins with execution o f the body of the superconstructor with \THIS{} bound to $i$, the type paramete rs of the immediately enclosing class bound to a set of actual type arguments $V _1, \ldots , V_m$ and the formal parameters bindings determined by the argument list of the superinitializer of $k$.
1194 1343
1195 \rationale{ 1344 \rationale{
1196 This process ensures that no uninitialized final field is ever seen by code. Not e that \THIS{} is not in scope on the right hand side of an initializer (see \re f{this}) so no instance method can execute during initialization: an instance me thod cannot be directly invoked, nor can \THIS{} be passed into any other code being invoked in the initializer. 1345 This process ensures that no uninitialized final field is ever seen by code. Not e that \THIS{} is not in scope on the right hand side of an initializer (see \re f{this}) so no instance method can execute during initialization: an instance me thod cannot be directly invoked, nor can \THIS{} be passed into any other code being invoked in the initializer.
1197 } 1346 }
1198 1347
1348 \LMHash{}
1199 Execution of an initializer of the form \code{\THIS{}.$v$ = $e$} proceeds as fol lows: 1349 Execution of an initializer of the form \code{\THIS{}.$v$ = $e$} proceeds as fol lows:
1200 1350
1351 \LMHash{}
1201 First, the expression $e$ is evaluated to an object $o$. Then, the instance vari able $v$ of the object denoted by \THIS{} is bound to $o$, unless $v$ is a final variable that has already been initialized, in which case a runtime error occur s. In checked mode, it is a dynamic type error if $o$ is not \NULL{} and the int erface of the class of $o$ is not a subtype of the actual type of the field $v$. 1352 First, the expression $e$ is evaluated to an object $o$. Then, the instance vari able $v$ of the object denoted by \THIS{} is bound to $o$, unless $v$ is a final variable that has already been initialized, in which case a runtime error occur s. In checked mode, it is a dynamic type error if $o$ is not \NULL{} and the int erface of the class of $o$ is not a subtype of the actual type of the field $v$.
1202 1353
1354 \LMHash{}
1203 An initializer of the form \code{$v$ = $e$} is equivalent to an initializer of t he form \code{\THIS{}.$v$ = $e$}. 1355 An initializer of the form \code{$v$ = $e$} is equivalent to an initializer of t he form \code{\THIS{}.$v$ = $e$}.
1204 1356
1357 \LMHash{}
1205 Execution of a superinitializer of the form 1358 Execution of a superinitializer of the form
1206 1359
1207 \SUPER{}$(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$ 1360 \SUPER{}$(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$
1208 1361
1209 (respectively \SUPER{}$.id(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$ 1362 (respectively \SUPER{}$.id(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$
1210 1363
1211 proceeds as follows: 1364 proceeds as follows:
1212 1365
1366 \LMHash{}
1213 First, the argument list $(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$ is evaluated. 1367 First, the argument list $(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$ is evaluated.
1214 1368
1369 \LMHash{}
1215 Let $C$ be the class in which the superinitializer appears and let $S$ be the su perclass of $C$. If $S$ is generic (\ref{generics}), let $U_1, , \ldots, U_m$ b e the actual type arguments passed to $S$ in the superclass clause of $C$. 1370 Let $C$ be the class in which the superinitializer appears and let $S$ be the su perclass of $C$. If $S$ is generic (\ref{generics}), let $U_1, , \ldots, U_m$ b e the actual type arguments passed to $S$ in the superclass clause of $C$.
1216 1371
1372 \LMHash{}
1217 Then, the initializer list of the constructor $S$ (respectively $S.id$) is execu ted with respect to the bindings that resulted from the evaluation of the argume nt list, with \THIS{} bound to the current binding of \THIS{}, and the type pa rameters (if any) of class $S$ bound to the current bindings of $U_1, , \ldots, U_m$. 1373 Then, the initializer list of the constructor $S$ (respectively $S.id$) is execu ted with respect to the bindings that resulted from the evaluation of the argume nt list, with \THIS{} bound to the current binding of \THIS{}, and the type pa rameters (if any) of class $S$ bound to the current bindings of $U_1, , \ldots, U_m$.
1218 1374
1375 \LMHash{}
1219 It is a compile-time error if class $S$ does not declare a generative constructo r named $S$ (respectively $S.id$). 1376 It is a compile-time error if class $S$ does not declare a generative constructo r named $S$ (respectively $S.id$).
1220 1377
1221 \subsubsection{Factories} 1378 \subsubsection{Factories}
1222 \label{factories} 1379 \LMLabel{factories}
1223 1380
1381 \LMHash{}
1224 A {\em factory} is a constructor prefaced by the built-in identifier (\ref{iden tifierReference}) \FACTORY{}. 1382 A {\em factory} is a constructor prefaced by the built-in identifier (\ref{iden tifierReference}) \FACTORY{}.
1225 1383
1226 \begin{grammar} 1384 \begin{grammar}
1227 {\bf factoryConstructorSignature:} 1385 {\bf factoryConstructorSignature:}
1228 \FACTORY{} identifier (`{\escapegrammar .}' identifier)? formalParameter List 1386 \FACTORY{} identifier (`{\escapegrammar .}' identifier)? formalParameter List
1229 . 1387 .
1230 \end{grammar} 1388 \end{grammar}
1231 1389
1232 1390
1233 %The enclosing scope of a factory constructor is the static scope \ref{} of the class in which it is declared. 1391 %The enclosing scope of a factory constructor is the static scope \ref{} of the class in which it is declared.
1234 1392
1393 \LMHash{}
1235 The {\em return type} of a factory whose signature is of the form \FACTORY{} $M$ or the form \FACTORY{} $M.id$ is $M$ if $M$ is not a generic type; otherwise th e return type is $M <T_1, \ldots, T_n>$ where $T_1, \ldots, T_n$ are the type p arameters of the enclosing class 1394 The {\em return type} of a factory whose signature is of the form \FACTORY{} $M$ or the form \FACTORY{} $M.id$ is $M$ if $M$ is not a generic type; otherwise th e return type is $M <T_1, \ldots, T_n>$ where $T_1, \ldots, T_n$ are the type p arameters of the enclosing class
1236 1395
1396 \LMHash{}
1237 It is a compile-time error if $M$ is not the name of the immediately enclosing c lass. 1397 It is a compile-time error if $M$ is not the name of the immediately enclosing c lass.
1238 1398
1399 \LMHash{}
1239 In checked mode, it is a dynamic type error if a factory returns a non-null obje ct whose type is not a subtype of its actual (\ref{actualTypeOfADeclaration}) re turn type. 1400 In checked mode, it is a dynamic type error if a factory returns a non-null obje ct whose type is not a subtype of its actual (\ref{actualTypeOfADeclaration}) re turn type.
1240 1401
1241 \rationale{It seems useless to allow a factory to return null. But it is more un iform to allow it, as the rules currently do.} 1402 \rationale{It seems useless to allow a factory to return null. But it is more un iform to allow it, as the rules currently do.}
1242 1403
1243 \rationale{Factories address classic weaknesses associated with constructors in other languages. 1404 \rationale{Factories address classic weaknesses associated with constructors in other languages.
1244 Factories can produce instances that are not freshly allocated: they can come fr om a cache. Likewise, factories can return instances of different classes. 1405 Factories can produce instances that are not freshly allocated: they can come fr om a cache. Likewise, factories can return instances of different classes.
1245 1406
1246 } 1407 }
1247 1408
1248 \paragraph{Redirecting Factory Constructors} 1409 \paragraph{Redirecting Factory Constructors}
1249 \label{redirectingFactoryConstructors} 1410 \LMLabel{redirectingFactoryConstructors}
1250 1411
1412 \LMHash{}
1251 A {\em redirecting factory constructor} specifies a call to a constructor of ano ther class that is to be used whenever the redirecting constructor is called. 1413 A {\em redirecting factory constructor} specifies a call to a constructor of ano ther class that is to be used whenever the redirecting constructor is called.
1252 1414
1253 \begin{grammar} 1415 \begin{grammar}
1254 {\bf redirectingFactoryConstructorSignature:} 1416 {\bf redirectingFactoryConstructorSignature:}
1255 \CONST{}? \FACTORY{} identifier (`{\escapegrammar .}' identifier)? formalP arameterList `=' type (`{\escapegrammar .}' identifier)? 1417 \CONST{}? \FACTORY{} identifier (`{\escapegrammar .}' identifier)? formalP arameterList `=' type (`{\escapegrammar .}' identifier)?
1256 . 1418 .
1257 \end{grammar} 1419 \end{grammar}
1258 1420
1421 \LMHash{}
1259 Calling a redirecting factory constructor $k$ causes the constructor $k^\prime$ denoted by $type$ (respectively, $type.identifier$) to be called with the actual arguments passed to $k$, and returns the result of $k^\prime$ as the result of $k$. The resulting constructor call is governed by the same rules as an instanc e creation expression using \NEW{} (\ref{instanceCreation}). 1422 Calling a redirecting factory constructor $k$ causes the constructor $k^\prime$ denoted by $type$ (respectively, $type.identifier$) to be called with the actual arguments passed to $k$, and returns the result of $k^\prime$ as the result of $k$. The resulting constructor call is governed by the same rules as an instanc e creation expression using \NEW{} (\ref{instanceCreation}).
1260 1423
1261 \commentary{ 1424 \commentary{
1262 It follows that if $type$ or $type.id$ are not defined, or do not refer to a cla ss or constructor, a dynamic error occurs, as with any other undefined construct or call. The same holds if $k$ is called with fewer required parameters or more positional parameters than $k^\prime$ expects, or if $k$ is called with a named parameter that is not declared by $k^\prime$. 1425 It follows that if $type$ or $type.id$ are not defined, or do not refer to a cla ss or constructor, a dynamic error occurs, as with any other undefined construct or call. The same holds if $k$ is called with fewer required parameters or more positional parameters than $k^\prime$ expects, or if $k$ is called with a named parameter that is not declared by $k^\prime$.
1263 } 1426 }
1264 1427
1428 \LMHash{}
1265 It is a compile-time error if $k$ explicitly specifies a default value for an op tional parameter.\commentary{ 1429 It is a compile-time error if $k$ explicitly specifies a default value for an op tional parameter.\commentary{
1266 Default values specified in $k$ would be ignored, since it is the {\em actual} p arameters that are passed to $k^\prime$. Hence, default values are disallowed. 1430 Default values specified in $k$ would be ignored, since it is the {\em actual} p arameters that are passed to $k^\prime$. Hence, default values are disallowed.
1267 } 1431 }
1268 1432
1433 \LMHash{}
1269 It is a run-time error if a redirecting factory constructor redirects to itself, either directly or indirectly via a sequence of redirections. %does not redirec t to a non-redirecting factory constructor or to a generative constructor in a f inite number of steps. 1434 It is a run-time error if a redirecting factory constructor redirects to itself, either directly or indirectly via a sequence of redirections. %does not redirec t to a non-redirecting factory constructor or to a generative constructor in a f inite number of steps.
1270 1435
1271 % Make this a runtime error so deferred loading works 1436 % Make this a runtime error so deferred loading works
1272 1437
1273 \rationale{ 1438 \rationale{
1274 If a redirecting factory $F_1$ redirects to another redirecting factory $F_2$ an d $F_2$ then redirects to $F_1$, then both $F_1$ and $F_2$ are ill-defined. Such cycles are therefore illegal. 1439 If a redirecting factory $F_1$ redirects to another redirecting factory $F_2$ an d $F_2$ then redirects to $F_1$, then both $F_1$ and $F_2$ are ill-defined. Such cycles are therefore illegal.
1275 } 1440 }
1276 1441
1277 1442
1443 \LMHash{}
1278 It is a static warning if $type$ does not denote a class accessible in the curre nt scope; if $type$ does denote such a class $C$ it is a static warning if the r eferenced constructor (be it $type$ or $type.id$) is not a constructor of $C$. 1444 It is a static warning if $type$ does not denote a class accessible in the curre nt scope; if $type$ does denote such a class $C$ it is a static warning if the r eferenced constructor (be it $type$ or $type.id$) is not a constructor of $C$.
1279 1445
1280 \commentary{ 1446 \commentary{
1281 Note that it is not possible to modify the arguments being passed to $k'$. 1447 Note that it is not possible to modify the arguments being passed to $k'$.
1282 } 1448 }
1283 % but we have the same issue with other redirecting constructors, no?) 1449 % but we have the same issue with other redirecting constructors, no?)
1284 \rationale{ 1450 \rationale{
1285 At first glance, one might think that ordinary factory constructors could simply create instances of other classes and return them, and that redirecting factori es are unnecessary. However, redirecting factories have several advantages: 1451 At first glance, one might think that ordinary factory constructors could simply create instances of other classes and return them, and that redirecting factori es are unnecessary. However, redirecting factories have several advantages:
1286 \begin{itemize} 1452 \begin{itemize}
1287 \item An abstract class may provide a constant constructor that utilizes the con stant constructor of another class. 1453 \item An abstract class may provide a constant constructor that utilizes the con stant constructor of another class.
(...skipping 21 matching lines...) Expand all
1309 1475
1310 %\CLASS{} A$<$T$>${ 1476 %\CLASS{} A$<$T$>${
1311 % \FACTORY{} A.idw(w) $=>$ F$<$T$>$.idw(w); 1477 % \FACTORY{} A.idw(w) $=>$ F$<$T$>$.idw(w);
1312 %// illegal - cannot pass type parameter to static method 1478 %// illegal - cannot pass type parameter to static method
1313 % \FACTORY{} A.idx(x) $=> \NEW{} $F$<$T$>$.idx(x); // works, but allocates a gr atuitous instance of F 1479 % \FACTORY{} A.idx(x) $=> \NEW{} $F$<$T$>$.idx(x); // works, but allocates a gr atuitous instance of F
1314 % \FACTORY{} A.idy(y) = Y$<$T$>$; // works 1480 % \FACTORY{} A.idy(y) = Y$<$T$>$; // works
1315 % \FACTORY{} A.idz(z) $=>$ F.idz(z); // wrong - returns Z$<$Dynamic$>$; no way to pass type argument 1481 % \FACTORY{} A.idz(z) $=>$ F.idz(z); // wrong - returns Z$<$Dynamic$>$; no way to pass type argument
1316 } 1482 }
1317 %\end{dartCode} 1483 %\end{dartCode}
1318 1484
1485 \LMHash{}
1319 It is a compile-time error if $k$ is prefixed with the \CONST{} modifier but $k^ \prime$ is not a constant constructor (\ref{constantConstructors}). 1486 It is a compile-time error if $k$ is prefixed with the \CONST{} modifier but $k^ \prime$ is not a constant constructor (\ref{constantConstructors}).
1320 1487
1488 \LMHash{}
1321 It is a static warning if the function type of $k^\prime$ is not a subtype of th e type of $k$. 1489 It is a static warning if the function type of $k^\prime$ is not a subtype of th e type of $k$.
1322 1490
1323 \commentary{ 1491 \commentary{
1324 This implies that the resulting object conforms to the interface of the immedia tely enclosing class of $k$. 1492 This implies that the resulting object conforms to the interface of the immedia tely enclosing class of $k$.
1325 } 1493 }
1326 1494
1495 \LMHash{}
1327 It is a static type warning if any of the type arguments to $k^\prime$ are not s ubtypes of the bounds of the corresponding formal type parameters of $type$. 1496 It is a static type warning if any of the type arguments to $k^\prime$ are not s ubtypes of the bounds of the corresponding formal type parameters of $type$.
1328 1497
1329 1498
1330 \subsubsection{Constant Constructors} 1499 \subsubsection{Constant Constructors}
1331 \label{constantConstructors} 1500 \LMLabel{constantConstructors}
1332 1501
1502 \LMHash{}
1333 A {\em constant constructor} may be used to create compile-time constant (\ref{ constants}) objects. A constant constructor is prefixed by the reserved word \CO NST{}. 1503 A {\em constant constructor} may be used to create compile-time constant (\ref{ constants}) objects. A constant constructor is prefixed by the reserved word \CO NST{}.
1334 1504
1335 \begin{grammar} 1505 \begin{grammar}
1336 {\bf constantConstructorSignature:} 1506 {\bf constantConstructorSignature:}
1337 \CONST{} qualified formalParameterList 1507 \CONST{} qualified formalParameterList
1338 . 1508 .
1339 \end{grammar} 1509 \end{grammar}
1340 1510
1341 1511
1342 %\commentary{Spell out subtleties: a constant constructor call within the initia lizer of a constant constructor is treated as a ordinary constructor call (a ne w), because the arguments cannot be assumed constant anymore. In practice, this means two versions are compiled and analyzed. One for new and one for const.} 1512 %\commentary{Spell out subtleties: a constant constructor call within the initia lizer of a constant constructor is treated as a ordinary constructor call (a ne w), because the arguments cannot be assumed constant anymore. In practice, this means two versions are compiled and analyzed. One for new and one for const.}
1343 1513
1344 % \Q{How to specify?} 1514 % \Q{How to specify?}
1345 1515
1346 \commentary{All the work of a constant constructor must be handled via its initi alizers.} 1516 \commentary{All the work of a constant constructor must be handled via its initi alizers.}
1347 1517
1518 \LMHash{}
1348 It is a compile-time error if a constant constructor is declared by a class that has a non-final instance variable. 1519 It is a compile-time error if a constant constructor is declared by a class that has a non-final instance variable.
1349 1520
1350 \commentary{ 1521 \commentary{
1351 The above refers to both locally declared and inherited instance variables. 1522 The above refers to both locally declared and inherited instance variables.
1352 } 1523 }
1353 1524
1525 \LMHash{}
1354 It is a compile-time error if a constant constructor is declared by a class $C$ if any instance variable declared in $C$ is initialized with an expression that is not a constant expression. 1526 It is a compile-time error if a constant constructor is declared by a class $C$ if any instance variable declared in $C$ is initialized with an expression that is not a constant expression.
1355 1527
1356 \commentary { 1528 \commentary {
1357 A superclass of $C$ cannot declare such an initializer either, because it must n ecessarily declare constant constructor as well (unless it is \code{Object}, whi ch declares no instance variables). 1529 A superclass of $C$ cannot declare such an initializer either, because it must n ecessarily declare constant constructor as well (unless it is \code{Object}, whi ch declares no instance variables).
1358 } 1530 }
1359 1531
1532 \LMHash{}
1360 The superinitializer that appears, explicitly or implicitly, in the initializer list of a constant constructor must specify a constant constructor of the superc lass of the immediately enclosing class or a compile-time error occurs. 1533 The superinitializer that appears, explicitly or implicitly, in the initializer list of a constant constructor must specify a constant constructor of the superc lass of the immediately enclosing class or a compile-time error occurs.
1361 1534
1535 \LMHash{}
1362 Any expression that appears within the initializer list of a constant constructo r must be a potentially constant expression, or a compile-time error occurs. 1536 Any expression that appears within the initializer list of a constant constructo r must be a potentially constant expression, or a compile-time error occurs.
1363 1537
1538 \LMHash{}
1364 A {\em potentially constant expression} is an expression $e$ that would be a val id constant expression if all formal parameters of $e$'s immediately enclosing c onstant constructor were treated as compile-time constants that were guaranteed to evaluate to an integer, boolean or string value as required by their immediat ely enclosing superexpression. 1539 A {\em potentially constant expression} is an expression $e$ that would be a val id constant expression if all formal parameters of $e$'s immediately enclosing c onstant constructor were treated as compile-time constants that were guaranteed to evaluate to an integer, boolean or string value as required by their immediat ely enclosing superexpression.
1365 1540
1366 \commentary{ 1541 \commentary{
1367 Note that a parameter that is not used in a superexpression that is restricted t o certain types can be a constant of any type. For example} 1542 Note that a parameter that is not used in a superexpression that is restricted t o certain types can be a constant of any type. For example}
1368 1543
1369 \begin{dartCode} 1544 \begin{dartCode}
1370 \CLASS{} A \{ 1545 \CLASS{} A \{
1371 \FINAL{} m; 1546 \FINAL{} m;
1372 \CONST{} A(this.m); 1547 \CONST{} A(this.m);
1373 \} 1548 \}
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 \commentary{ 1592 \commentary{
1418 The problem is not that the assignments to \code{w} are not potentially constant ; they are. However, all these run afoul of the rules for constant lists (\ref{ lists}), maps (\ref{maps}) and objects (\ref{const}), all of which independently require their subexpressions to be constant expressions. 1593 The problem is not that the assignments to \code{w} are not potentially constant ; they are. However, all these run afoul of the rules for constant lists (\ref{ lists}), maps (\ref{maps}) and objects (\ref{const}), all of which independently require their subexpressions to be constant expressions.
1419 } 1594 }
1420 1595
1421 \rationale{ 1596 \rationale{
1422 All of the illegal constructors of \code{D} above could not be sensibly invoked via \NEW{}, because an expression that must be constant cannot depend on a forma l parameter, which may or may not be constant. In contrast, the legal examples m ake sense regardless of whether the constructor is invoked via \CONST{} or via \ NEW{}. 1597 All of the illegal constructors of \code{D} above could not be sensibly invoked via \NEW{}, because an expression that must be constant cannot depend on a forma l parameter, which may or may not be constant. In contrast, the legal examples m ake sense regardless of whether the constructor is invoked via \CONST{} or via \ NEW{}.
1423 1598
1424 Careful readers will of course worry about cases where the actual arguments to \ code{C()} are constants, but are not numeric. This is precluded by the following rule, combined with the rules for evaluating constant objects (\ref{const}). 1599 Careful readers will of course worry about cases where the actual arguments to \ code{C()} are constants, but are not numeric. This is precluded by the following rule, combined with the rules for evaluating constant objects (\ref{const}).
1425 } 1600 }
1426 1601
1602 \LMHash{}
1427 When invoked from a constant object expression, a constant constructor must thro w an exception if any of its actual parameters is a value that would prevent one of the potentially constant expressions within it from being a valid compile-ti me constant. 1603 When invoked from a constant object expression, a constant constructor must thro w an exception if any of its actual parameters is a value that would prevent one of the potentially constant expressions within it from being a valid compile-ti me constant.
1428 1604
1429 %Discuss External Constructors in ne subsubsection here 1605 %Discuss External Constructors in ne subsubsection here
1430 1606
1431 \subsection{Static Methods} 1607 \subsection{Static Methods}
1432 \label{staticMethods} 1608 \LMLabel{staticMethods}
1433 1609
1610 \LMHash{}
1434 {\em Static methods} are functions, other than getters or setters, whose declara tions are immediately contained within a class declaration and that are declared \STATIC{}. The static methods of a class $C$ are those static methods declared by $C$. 1611 {\em Static methods} are functions, other than getters or setters, whose declara tions are immediately contained within a class declaration and that are declared \STATIC{}. The static methods of a class $C$ are those static methods declared by $C$.
1435 1612
1613 \LMHash{}
1436 The effect of a static method declaration in class $C$ is to add an instance met hod with the same name and signature to the \code{Type} object for class $C$ tha t forwards (\ref{functionDeclarations}) to the static method. 1614 The effect of a static method declaration in class $C$ is to add an instance met hod with the same name and signature to the \code{Type} object for class $C$ tha t forwards (\ref{functionDeclarations}) to the static method.
1437 1615
1438 \rationale{ 1616 \rationale{
1439 Inheritance of static methods has little utility in Dart. Static methods cannot be overridden. Any required static function can be obtained from its declaring l ibrary, and there is no need to bring it into scope via inheritance. Experience shows that developers are confused by the idea of inherited methods that are not instance methods. 1617 Inheritance of static methods has little utility in Dart. Static methods cannot be overridden. Any required static function can be obtained from its declaring l ibrary, and there is no need to bring it into scope via inheritance. Experience shows that developers are confused by the idea of inherited methods that are not instance methods.
1440 1618
1441 Of course, the entire notion of static methods is debatable, but it is retained here because so many programmers are familiar with it. Dart static methods may b e seen as functions of the enclosing library. 1619 Of course, the entire notion of static methods is debatable, but it is retained here because so many programmers are familiar with it. Dart static methods may b e seen as functions of the enclosing library.
1442 } 1620 }
1443 1621
1622 \LMHash{}
1444 It is a static warning if a class $C$ declares a static method named $n$ and has a setter named $n=$. 1623 It is a static warning if a class $C$ declares a static method named $n$ and has a setter named $n=$.
1445 %It is a static warning if a class has a static method with the same name as a s tatic member of one of its superclasses. 1624 %It is a static warning if a class has a static method with the same name as a s tatic member of one of its superclasses.
1446 1625
1447 %\rationale{ 1626 %\rationale{
1448 %This last restriction makes classes more brittle with respect to changes in the class hierarchy. It stems from a general observation that shadowing of names in the same scope is questionable and should elicit a warning. 1627 %This last restriction makes classes more brittle with respect to changes in the class hierarchy. It stems from a general observation that shadowing of names in the same scope is questionable and should elicit a warning.
1449 %} 1628 %}
1450 %\commentary{ 1629 %\commentary{
1451 %There is no hiding of static methods, or of static variables. 1630 %There is no hiding of static methods, or of static variables.
1452 %} 1631 %}
1453 1632
1454 1633
1455 \subsection{Static Variables} 1634 \subsection{Static Variables}
1456 \label{staticVariables} 1635 \LMLabel{staticVariables}
1457 1636
1637 \LMHash{}
1458 {\em Static variables} are variables whose declarations are immediately containe d within a class declaration and that are declared \STATIC{}. The static variabl es of a class $C$ are those static variables declared by $C$. 1638 {\em Static variables} are variables whose declarations are immediately containe d within a class declaration and that are declared \STATIC{}. The static variabl es of a class $C$ are those static variables declared by $C$.
1459 1639
1460 %A static variable declaration of one of the forms \code{\STATIC{} $T$ $v$;}, \code{\STATIC{} $T$ $v$ = $e$;} , \code{\STATIC{} \CONST{} $T$ $v$ = $e$;} or \code{\STATIC{} \FINAL{} $T$ $v$ = $e$;} always induces an implicit static gette r function (\ref{getters}) with signature 1640 %A static variable declaration of one of the forms \code{\STATIC{} $T$ $v$;}, \code{\STATIC{} $T$ $v$ = $e$;} , \code{\STATIC{} \CONST{} $T$ $v$ = $e$;} or \code{\STATIC{} \FINAL{} $T$ $v$ = $e$;} always induces an implicit static gette r function (\ref{getters}) with signature
1461 1641
1462 %\STATIC{} $T$ \GET{} $v$ 1642 %\STATIC{} $T$ \GET{} $v$
1463 1643
1464 %whose invocation evaluates as described below (\ref{evaluationOfStaticVariableG etters}).%to the value stored in $v$. 1644 %whose invocation evaluates as described below (\ref{evaluationOfStaticVariableG etters}).%to the value stored in $v$.
1465 1645
1466 1646
1467 %A static variable declaration of one of the forms \code{\STATIC{} \VAR{} $v$;} , \code{\STATIC{} \VAR{} $v$ = $e$;} , \code{\STATIC{} \CONST{} $v$ = $e$;} or \code{\STATIC{} \FINAL{} $v$ = $e$;} always induces an implicit static getter function with signature 1647 %A static variable declaration of one of the forms \code{\STATIC{} \VAR{} $v$;} , \code{\STATIC{} \VAR{} $v$ = $e$;} , \code{\STATIC{} \CONST{} $v$ = $e$;} or \code{\STATIC{} \FINAL{} $v$ = $e$;} always induces an implicit static getter function with signature
(...skipping 10 matching lines...) Expand all
1478 1658
1479 %A static variable declaration of the form \code{\STATIC{} \VAR{} $v$;} or the form \code{\STATIC{} \VAR{} $v$ = $e$;} always induces an implicit static set ter function with signature 1659 %A static variable declaration of the form \code{\STATIC{} \VAR{} $v$;} or the form \code{\STATIC{} \VAR{} $v$ = $e$;} always induces an implicit static set ter function with signature
1480 1660
1481 %\STATIC{} \SET{} $v=(x)$ 1661 %\STATIC{} \SET{} $v=(x)$
1482 1662
1483 %whose execution sets the value of $v$ to the incoming argument $x$. 1663 %whose execution sets the value of $v$ to the incoming argument $x$.
1484 1664
1485 %Extrernal static functions, getters, setters 1665 %Extrernal static functions, getters, setters
1486 1666
1487 %\subsubsection{Evaluation of Implicit Static Variable Getters} 1667 %\subsubsection{Evaluation of Implicit Static Variable Getters}
1488 %\label{evaluationOfStaticVariableGetters} 1668 %\LMLabel{evaluationOfStaticVariableGetters}
1489 1669
1490 %Let $d$ be the declaration of a static variable $v$. The implicit getter method of $v$ executes as follows: 1670 %Let $d$ be the declaration of a static variable $v$. The implicit getter method of $v$ executes as follows:
1491 %\begin{itemize} 1671 %\begin{itemize}
1492 %\item If $d$ is of one of the forms \code{\STATIC{} \VAR{} $v$ = $e$;} , \code{ \STATIC{} $T$ $v$ = $e$; }, \code{\STATIC{} \FINAL{} $v$ = $e$; } or \code{\STAT IC{} \FINAL{} $T$ $v$ = $e$;} and no value has yet been stored into $v$ then the initializer expression $e$ is evaluated. If, during the evaluation of $e$, the getter for $v$ is referenced, a \code{CyclicInitializationError} is thrown. If t he evaluation succeeded yielding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$ is stored into $v$. The result of executing the gette r is $r$. 1672 %\item If $d$ is of one of the forms \code{\STATIC{} \VAR{} $v$ = $e$;} , \code{ \STATIC{} $T$ $v$ = $e$; }, \code{\STATIC{} \FINAL{} $v$ = $e$; } or \code{\STAT IC{} \FINAL{} $T$ $v$ = $e$;} and no value has yet been stored into $v$ then the initializer expression $e$ is evaluated. If, during the evaluation of $e$, the getter for $v$ is referenced, a \code{CyclicInitializationError} is thrown. If t he evaluation succeeded yielding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$ is stored into $v$. The result of executing the gette r is $r$.
1493 %\item If $d$ is of one of the forms \code{\STATIC{} \CONST{} $v$ = $e$; } or \ code{\STATIC{} \CONST{} $T$ $v$ = $e$;} the result of the getter is the value of the compile time constant $e$. 1673 %\item If $d$ is of one of the forms \code{\STATIC{} \CONST{} $v$ = $e$; } or \ code{\STATIC{} \CONST{} $T$ $v$ = $e$;} the result of the getter is the value of the compile time constant $e$.
1494 %Otherwise 1674 %Otherwise
1495 %\item The result of executing the getter method is the value stored in $v$. 1675 %\item The result of executing the getter method is the value stored in $v$.
1496 %\end{itemize} 1676 %\end{itemize}
1497 1677
1498 1678
1499 1679
1500 \subsection{Superclasses} 1680 \subsection{Superclasses}
1501 \label{superclasses} 1681 \LMLabel{superclasses}
1502 1682
1683 \LMHash{}
1503 The superclass of a class $C$ that has a with clause \code{\WITH{} $M_1, \ldots, M_k$} and an extends clause \code{\EXTENDS{} S} is the application of mixin (\r ef{mixins}) $M_k* \cdots * M_1$ to S. If no \WITH{} clause is specified then the \EXTENDS{} clause of a class $C$ specifies its superclass. If no \EXTENDS{} clause is specified, then either: 1684 The superclass of a class $C$ that has a with clause \code{\WITH{} $M_1, \ldots, M_k$} and an extends clause \code{\EXTENDS{} S} is the application of mixin (\r ef{mixins}) $M_k* \cdots * M_1$ to S. If no \WITH{} clause is specified then the \EXTENDS{} clause of a class $C$ specifies its superclass. If no \EXTENDS{} clause is specified, then either:
1504 \begin{itemize} 1685 \begin{itemize}
1505 \item $C$ is \code{Object}, which has no superclass. OR 1686 \item $C$ is \code{Object}, which has no superclass. OR
1506 \item Class $C$ is deemed to have an \EXTENDS{} clause of the form \code{\EXTEN DS{} Object}, and the rules above apply. 1687 \item Class $C$ is deemed to have an \EXTENDS{} clause of the form \code{\EXTEN DS{} Object}, and the rules above apply.
1507 \end{itemize} 1688 \end{itemize}
1508 1689
1690 \LMHash{}
1509 It is a compile-time error to specify an \EXTENDS{} clause for class \code{Objec t}. 1691 It is a compile-time error to specify an \EXTENDS{} clause for class \code{Objec t}.
1510 1692
1511 \begin{grammar} 1693 \begin{grammar}
1512 {\bf superclass:} 1694 {\bf superclass:}
1513 \EXTENDS{} type 1695 \EXTENDS{} type
1514 . 1696 .
1515 \end{grammar} 1697 \end{grammar}
1516 1698
1517 %The superclass clause of a class C is processed within the enclosing scope of t he static scope of C. 1699 %The superclass clause of a class C is processed within the enclosing scope of t he static scope of C.
1518 %\commentary{ 1700 %\commentary{
1519 %This means that in a generic class, the type parameters of the generic are avai lable in the superclass clause. 1701 %This means that in a generic class, the type parameters of the generic are avai lable in the superclass clause.
1520 %} 1702 %}
1521 1703
1704 \LMHash{}
1522 %It is a compile-time error if the \EXTENDS{} clause of a class $C$ includes a type expression that does not denote a class available in the lexical scope of $ C$. 1705 %It is a compile-time error if the \EXTENDS{} clause of a class $C$ includes a type expression that does not denote a class available in the lexical scope of $ C$.
1523 It is a compile-time error if the \EXTENDS{} clause of a class $C$ specifies an enumerated type (\ref{enums}), a malformed type or a deferred type (\ref{stati cTypes}) as a superclass. 1706 It is a compile-time error if the \EXTENDS{} clause of a class $C$ specifies an enumerated type (\ref{enums}), a malformed type or a deferred type (\ref{stati cTypes}) as a superclass.
1524 % too strict? Do we e want extends List<Undeclared> to work as List<dynamic>? 1707 % too strict? Do we e want extends List<Undeclared> to work as List<dynamic>?
1525 1708
1526 \commentary{ The type parameters of a generic class are available in the lexical scope of the superclass clause, potentially shadowing classes in the surroundin g scope. The following code is therefore illegal and should cause a compile-time error: 1709 \commentary{ The type parameters of a generic class are available in the lexical scope of the superclass clause, potentially shadowing classes in the surroundin g scope. The following code is therefore illegal and should cause a compile-time error:
1527 } 1710 }
1528 1711
1529 \begin{dartCode} 1712 \begin{dartCode}
1530 class T \{\} 1713 class T \{\}
1531 1714
1532 /* Compilation error: Attempt to subclass a type parameter */ 1715 /* Compilation error: Attempt to subclass a type parameter */
1533 class G$<$T$>$ extends T \{\} 1716 class G$<$T$>$ extends T \{\}
1534 1717
1535 \end{dartCode} 1718 \end{dartCode}
1536 1719
1537 1720
1721 \LMHash{}
1538 A class $S$ is {\em a superclass} of a class $C$ iff either: 1722 A class $S$ is {\em a superclass} of a class $C$ iff either:
1539 \begin{itemize} 1723 \begin{itemize}
1540 \item $S$ is the superclass of $C$, or 1724 \item $S$ is the superclass of $C$, or
1541 \item $S$ is a superclass of a class $S^{\prime}$ and $S^{\prime}$ is a supercla ss of $C$. 1725 \item $S$ is a superclass of a class $S^{\prime}$ and $S^{\prime}$ is a supercla ss of $C$.
1542 \end{itemize} 1726 \end{itemize}
1543 1727
1728 \LMHash{}
1544 It is a compile-time error if a class $C$ is a superclass of itself. 1729 It is a compile-time error if a class $C$ is a superclass of itself.
1545 1730
1546 1731
1547 1732
1548 1733
1549 \subsubsection{Inheritance and Overriding} 1734 \subsubsection{Inheritance and Overriding}
1550 \label{inheritanceAndOverriding} 1735 \LMLabel{inheritanceAndOverriding}
1551 1736
1552 1737
1553 %A class $C$ {\em inherits} any accessible instance members of its superclass t hat are not overridden by members declared in $C$. 1738 %A class $C$ {\em inherits} any accessible instance members of its superclass t hat are not overridden by members declared in $C$.
1554 1739
1740 \LMHash{}
1555 Let $C$ be a class, let $A$ be a superclass of $C$, and let $S_1 \ldots S_k$ b e superclasses of $C$ that are also subclasses of $A$. $C$ {\em inherits} all ac cessible instance members of $A$ that have not been overridden by a declaratio n in $C$ or in at least one of $S_1 \ldots S_k$. 1741 Let $C$ be a class, let $A$ be a superclass of $C$, and let $S_1 \ldots S_k$ b e superclasses of $C$ that are also subclasses of $A$. $C$ {\em inherits} all ac cessible instance members of $A$ that have not been overridden by a declaratio n in $C$ or in at least one of $S_1 \ldots S_k$.
1556 1742
1557 \rationale { 1743 \rationale {
1558 It would be more attractive to give a purely local definition of inheritance, t hat depended only on the members of the direct superclass $S$. However, a class $C$ can inherit a member $m$ that is not a member of its superclass $S$. This can occur when the member $m$ is private 1744 It would be more attractive to give a purely local definition of inheritance, t hat depended only on the members of the direct superclass $S$. However, a class $C$ can inherit a member $m$ that is not a member of its superclass $S$. This can occur when the member $m$ is private
1559 to the library $L_1$ of $C$, whereas $S$ comes from a different library $L_2$, b ut 1745 to the library $L_1$ of $C$, whereas $S$ comes from a different library $L_2$, b ut
1560 the superclass chain of $S$ includes a class declared in $L_1$. 1746 the superclass chain of $S$ includes a class declared in $L_1$.
1561 } 1747 }
1562 1748
1749 \LMHash{}
1563 A class may override instance members that would otherwise have been inherited f rom its superclass. 1750 A class may override instance members that would otherwise have been inherited f rom its superclass.
1564 1751
1752 \LMHash{}
1565 Let $C = S_0$ be a class declared in library $L$, and let $\{S_1 \ldots S_k\}$ b e the set of all superclasses of $C$, where $S_i$ is the superclass of $S_{i-1}$ for $i \in 1 .. k$. Let $C$ declare a member $m$, and let $m^\prime$ be a memb er of $S_j, j \in 1 .. k$, that has the same name as $m$, such that $m^\prime$ is accessible to $L$. Then $m$ overrides $m^\prime$ if $m^\prime$ is not alrea dy overridden by a member of at least one of $S_1 \ldots S_{j-1}$ and neither $m $ nor $m^\prime$ are fields. 1753 Let $C = S_0$ be a class declared in library $L$, and let $\{S_1 \ldots S_k\}$ b e the set of all superclasses of $C$, where $S_i$ is the superclass of $S_{i-1}$ for $i \in 1 .. k$. Let $C$ declare a member $m$, and let $m^\prime$ be a memb er of $S_j, j \in 1 .. k$, that has the same name as $m$, such that $m^\prime$ is accessible to $L$. Then $m$ overrides $m^\prime$ if $m^\prime$ is not alrea dy overridden by a member of at least one of $S_1 \ldots S_{j-1}$ and neither $m $ nor $m^\prime$ are fields.
1566 1754
1567 %Let $C$ be a class declared in library $L$, with superclass $S$ and let $C$ dec lare an instance member $m$, and assume $S$ declares an instance member $m^\pri me$ with the same name as $m$. Then $m$ {\em overrides} $m^\prime$ iff $m^\prime $ is accessible (\ref{privacy}) to $L$, $m$ has the same name as $m^\prime$ an d neither $m$ nor $m^\prime$ are fields. 1755 %Let $C$ be a class declared in library $L$, with superclass $S$ and let $C$ dec lare an instance member $m$, and assume $S$ declares an instance member $m^\pri me$ with the same name as $m$. Then $m$ {\em overrides} $m^\prime$ iff $m^\prime $ is accessible (\ref{privacy}) to $L$, $m$ has the same name as $m^\prime$ an d neither $m$ nor $m^\prime$ are fields.
1568 1756
1569 \commentary{Fields never override each other. The getters and setters induced by fields do.} 1757 \commentary{Fields never override each other. The getters and setters induced by fields do.}
1570 1758
1571 \rationale{Again, a local definition of overriding would be preferable, but fail s to account for library privacy. 1759 \rationale{Again, a local definition of overriding would be preferable, but fail s to account for library privacy.
1572 } 1760 }
1573 1761
1762 \LMHash{}
1574 Whether an override is legal or not is described elsewhere in this specification (see \ref{instanceMethods}, \ref{getters} and \ref{setters}). 1763 Whether an override is legal or not is described elsewhere in this specification (see \ref{instanceMethods}, \ref{getters} and \ref{setters}).
1575 1764
1576 \commentary{For example getters may not legally override methods and vice versa. Setters never override methods or getters, and vice versa, because their names always differ. 1765 \commentary{For example getters may not legally override methods and vice versa. Setters never override methods or getters, and vice versa, because their names always differ.
1577 } 1766 }
1578 1767
1579 \rationale{ 1768 \rationale{
1580 It is nevertheless convenient to define the override relation between members in this way, so that we can concisely describe the illegal cases. 1769 It is nevertheless convenient to define the override relation between members in this way, so that we can concisely describe the illegal cases.
1581 } 1770 }
1582 1771
1583 \commentary{ 1772 \commentary{
1584 Note that instance variables do not participate in the override relation, but th e getters and setters they induce do. Also, getters don't override setters and v ice versa. Finally, static members never override anything. 1773 Note that instance variables do not participate in the override relation, but th e getters and setters they induce do. Also, getters don't override setters and v ice versa. Finally, static members never override anything.
1585 } 1774 }
1586 1775
1776 \LMHash{}
1587 It is a static warning if a non-abstract class inherits an abstract method. 1777 It is a static warning if a non-abstract class inherits an abstract method.
1588 1778
1589 \commentary { 1779 \commentary {
1590 For convenience, here is a summary of the relevant rules. Remember that this is not normative. The controlling language is in the relevant sections of the speci fication. 1780 For convenience, here is a summary of the relevant rules. Remember that this is not normative. The controlling language is in the relevant sections of the speci fication.
1591 1781
1592 \begin{enumerate} 1782 \begin{enumerate}
1593 1783
1594 \item There is only one namespace for getters, setters, methods and constructors (\ref{scoping}). A field $f$ introduces a getter $f$ and a non-final field $f$ also introduces a setter $f=$ (\ref{instanceVariables}, \ref{staticVariables}). When we speak of members here, we mean accessible fields, getters, setters and m ethods (\ref{classes}). 1784 \item There is only one namespace for getters, setters, methods and constructors (\ref{scoping}). A field $f$ introduces a getter $f$ and a non-final field $f$ also introduces a setter $f=$ (\ref{instanceVariables}, \ref{staticVariables}). When we speak of members here, we mean accessible fields, getters, setters and m ethods (\ref{classes}).
1595 \item You cannot have two members with the same name in the same class - be the y declared or inherited (\ref{scoping}, \ref{classes}). 1785 \item You cannot have two members with the same name in the same class - be the y declared or inherited (\ref{scoping}, \ref{classes}).
1596 \item Static members are never inherited. 1786 \item Static members are never inherited.
(...skipping 27 matching lines...) Expand all
1624 \item Rule \ref{typeSigAssignable} applies to interfaces as well as classes (\ ref{interfaceInheritanceAndOverriding}). 1814 \item Rule \ref{typeSigAssignable} applies to interfaces as well as classes (\ ref{interfaceInheritanceAndOverriding}).
1625 \item It is a static warning if a concrete class does not have an implementatio n for a method in any of its superinterfaces unless it declares its own \cd{n oSuchMethod} method (\ref{superinterfaces}). 1815 \item It is a static warning if a concrete class does not have an implementatio n for a method in any of its superinterfaces unless it declares its own \cd{n oSuchMethod} method (\ref{superinterfaces}).
1626 \item The identifier of a named constructor cannot be the same as the name of a member declared (as opposed to inherited) in the same class (\ref{constructors}) . 1816 \item The identifier of a named constructor cannot be the same as the name of a member declared (as opposed to inherited) in the same class (\ref{constructors}) .
1627 \end{enumerate} 1817 \end{enumerate}
1628 } 1818 }
1629 1819
1630 1820
1631 %Can we have abstract getters and setters? 1821 %Can we have abstract getters and setters?
1632 1822
1633 \subsection{ Superinterfaces} 1823 \subsection{ Superinterfaces}
1634 \label{superinterfaces} 1824 \LMLabel{superinterfaces}
1635 % what about rules about classes that fail to implement their interfaces? 1825 % what about rules about classes that fail to implement their interfaces?
1636 1826
1827 \LMHash{}
1637 A class has a set of direct superinterfaces. This set includes the interface of its superclass and the interfaces specified in the the \IMPLEMENTS{} clause of the class. 1828 A class has a set of direct superinterfaces. This set includes the interface of its superclass and the interfaces specified in the the \IMPLEMENTS{} clause of the class.
1638 % and any superinterfaces specified by interface injection (\ref{interfaceInject ion}). \Q{The latter needs to be worded carefully - when do interface injection clauses execute and in what scope?} 1829 % and any superinterfaces specified by interface injection (\ref{interfaceInject ion}). \Q{The latter needs to be worded carefully - when do interface injection clauses execute and in what scope?}
1639 1830
1640 \begin{grammar} 1831 \begin{grammar}
1641 {\bf interfaces:} 1832 {\bf interfaces:}
1642 \IMPLEMENTS{} typeList 1833 \IMPLEMENTS{} typeList
1643 . 1834 .
1644 \end{grammar} 1835 \end{grammar}
1645 1836
1837 \LMHash{}
1646 It is a compile-time error if the \IMPLEMENTS{} clause of a class $C$ specifie s a type variable as a superinterface. It is a compile-time error if the \IMPL EMENTS{} clause of a class $C$ specifies an enumerated type (\ref{enums}), a ma lformed type or deferred type (\ref{staticTypes}) as a superinterface It is a c ompile-time error if the \IMPLEMENTS{} clause of a class $C$ specifies type \DYN AMIC{} as a superinterface. It is a compile-time error if the \IMPLEMENTS{} cl ause of a class $C$ specifies a type $T$ as a superinterface more than once. 1838 It is a compile-time error if the \IMPLEMENTS{} clause of a class $C$ specifie s a type variable as a superinterface. It is a compile-time error if the \IMPL EMENTS{} clause of a class $C$ specifies an enumerated type (\ref{enums}), a ma lformed type or deferred type (\ref{staticTypes}) as a superinterface It is a c ompile-time error if the \IMPLEMENTS{} clause of a class $C$ specifies type \DYN AMIC{} as a superinterface. It is a compile-time error if the \IMPLEMENTS{} cl ause of a class $C$ specifies a type $T$ as a superinterface more than once.
1647 It is a compile-time error if the superclass of a class $C$ is specified as a su perinterface of $C$. 1839 It is a compile-time error if the superclass of a class $C$ is specified as a su perinterface of $C$.
1648 1840
1649 \rationale{ 1841 \rationale{
1650 One might argue that it is harmless to repeat a type in the superinterface list, so why make it an error? The issue is not so much that the situation described in program source is erroneous, but that it is pointless. As such, it is an indi cation that the programmer may very well have meant to say something else - and that is a mistake that should be called to her or his attention. Nevertheless, we could simply issue a warning; and perhaps we should and will. That said, prob lems like these are local and easily corrected on the spot, so we feel justified in taking a harder line. 1842 One might argue that it is harmless to repeat a type in the superinterface list, so why make it an error? The issue is not so much that the situation described in program source is erroneous, but that it is pointless. As such, it is an indi cation that the programmer may very well have meant to say something else - and that is a mistake that should be called to her or his attention. Nevertheless, we could simply issue a warning; and perhaps we should and will. That said, prob lems like these are local and easily corrected on the spot, so we feel justified in taking a harder line.
1651 } 1843 }
1652 1844
1845 \LMHash{}
1653 It is a compile-time error if the interface of a class $C$ is a superinterface o f itself. 1846 It is a compile-time error if the interface of a class $C$ is a superinterface o f itself.
1654 1847
1848 \LMHash{}
1655 Let $C$ be a concrete class that does not declare its own \code{noSuchMethod()} method. 1849 Let $C$ be a concrete class that does not declare its own \code{noSuchMethod()} method.
1656 It is a static warning if the implicit interface of $C$ includes an instance me mber $m$ of type $F$ and $C$ does not declare or inherit a corresponding non-abs tract instance member $m$ of type $F'$ such that $F' <: F$. 1850 It is a static warning if the implicit interface of $C$ includes an instance me mber $m$ of type $F$ and $C$ does not declare or inherit a corresponding non-abs tract instance member $m$ of type $F'$ such that $F' <: F$.
1657 1851
1658 \commentary{A class does not inherit members from its superinterfaces. However, its implicit interface does. 1852 \commentary{A class does not inherit members from its superinterfaces. However, its implicit interface does.
1659 } 1853 }
1660 1854
1661 1855
1662 \rationale { 1856 \rationale {
1663 We choose to issue these warnings only for concrete classes; an abstract class m ight legitimately be designed with the expectation that concrete subclasses will implement part of the interface. 1857 We choose to issue these warnings only for concrete classes; an abstract class m ight legitimately be designed with the expectation that concrete subclasses will implement part of the interface.
1664 We also disable these warnings if a \code{noSuchMethod()} declaration is present . In such cases, the supported interface is going to be implemented via \code{no SuchMethod()} and no actual declarations of the implemented interface's members are needed. This allows proxy classes for specific types to be implemented witho ut provoking type warnings. 1858 We also disable these warnings if a \code{noSuchMethod()} declaration is present . In such cases, the supported interface is going to be implemented via \code{no SuchMethod()} and no actual declarations of the implemented interface's members are needed. This allows proxy classes for specific types to be implemented witho ut provoking type warnings.
1665 1859
1666 In addition, it may be useful to suppress these warnings if \code{noSuchMethod} is inherited, However, this may suppress meaningful warnings and so we choose no t to do so. If one does want to suppress the warnings in a subclass, one can def ine a simple implementation of \code{noSuchMethod} in the subclass: 1860 In addition, it may be useful to suppress these warnings if \code{noSuchMethod} is inherited, However, this may suppress meaningful warnings and so we choose no t to do so. If one does want to suppress the warnings in a subclass, one can def ine a simple implementation of \code{noSuchMethod} in the subclass:
1667 } 1861 }
1668 1862
1669 \begin{dartCode} 1863 \begin{dartCode}
1670 noSuchMethod(inv) =$>$ \SUPER.noSuchMethod(inv); 1864 noSuchMethod(inv) =$>$ \SUPER.noSuchMethod(inv);
1671 \end{dartCode} 1865 \end{dartCode}
1672 1866
1867 \LMHash{}
1673 It is a static warning if the implicit interface of a class $C$ includes an ins tance member $m$ of type $F$ and $C$ declares or inherits a corresponding instan ce member $m$ of type $F'$ if $F'$ is not a subtype of $F$. 1868 It is a static warning if the implicit interface of a class $C$ includes an ins tance member $m$ of type $F$ and $C$ declares or inherits a corresponding instan ce member $m$ of type $F'$ if $F'$ is not a subtype of $F$.
1674 1869
1675 \rationale{ 1870 \rationale{
1676 However, if a class does explicitly declare a member that conflicts with its sup erinterface, this always yields a static warning. 1871 However, if a class does explicitly declare a member that conflicts with its sup erinterface, this always yields a static warning.
1677 1872
1678 } 1873 }
1679 %It is a static warning if an imported superinterface of a class $C$ declares pr ivate members. 1874 %It is a static warning if an imported superinterface of a class $C$ declares pr ivate members.
1680 1875
1681 % Should we ignore unimplemented private members? 1876 % Should we ignore unimplemented private members?
1682 1877
(...skipping 14 matching lines...) Expand all
1697 1892
1698 %class C implements I1, I2 {...}; // class declaration 1893 %class C implements I1, I2 {...}; // class declaration
1699 1894
1700 %this should not cause breakage. 1895 %this should not cause breakage.
1701 %} 1896 %}
1702 1897
1703 % \rationale{This avoids the issues with so-called miranda methods etc. } 1898 % \rationale{This avoids the issues with so-called miranda methods etc. }
1704 1899
1705 1900
1706 \section{Interfaces} 1901 \section{Interfaces}
1707 \label{interfaces} 1902 \LMLabel{interfaces}
1708 1903
1904 \LMHash{}
1709 An {\em interface} defines how one may interact with an object. An interface has methods, getters and setters and a set of superinterfaces. 1905 An {\em interface} defines how one may interact with an object. An interface has methods, getters and setters and a set of superinterfaces.
1710 1906
1711 \subsection{Superinterfaces} 1907 \subsection{Superinterfaces}
1712 \label{interfaceSuperinterfaces} 1908 \LMLabel{interfaceSuperinterfaces}
1713 1909
1910 \LMHash{}
1714 An interface has a set of direct superinterfaces. 1911 An interface has a set of direct superinterfaces.
1715 1912
1913 \LMHash{}
1716 An interface $J$ is a superinterface of an interface $I$ iff either $J$ is a dir ect superinterface of $I$ or $J$ is a superinterface of a direct superinterface of $I$. 1914 An interface $J$ is a superinterface of an interface $I$ iff either $J$ is a dir ect superinterface of $I$ or $J$ is a superinterface of a direct superinterface of $I$.
1717 1915
1718 1916
1719 1917
1720 1918
1721 \subsubsection{Inheritance and Overriding} 1919 \subsubsection{Inheritance and Overriding}
1722 \label{interfaceInheritanceAndOverriding} 1920 \LMLabel{interfaceInheritanceAndOverriding}
1723 1921
1922 \LMHash{}
1724 Let $J$ be an interface and $K$ be a library. We define $inherited(J, K)$ to be the set of members $m$ such that all of the following hold: 1923 Let $J$ be an interface and $K$ be a library. We define $inherited(J, K)$ to be the set of members $m$ such that all of the following hold:
1725 \begin{itemize} 1924 \begin{itemize}
1726 \item $m$ is accessible to $K$ and 1925 \item $m$ is accessible to $K$ and
1727 \item $A$ is a direct superinterface of $J$ and either 1926 \item $A$ is a direct superinterface of $J$ and either
1728 \begin{itemize} 1927 \begin{itemize}
1729 \item $A$ declares a member $m$ or 1928 \item $A$ declares a member $m$ or
1730 \item $m$ is a member of $inherited(A, K)$. 1929 \item $m$ is a member of $inherited(A, K)$.
1731 \end{itemize} 1930 \end{itemize}
1732 \item $m$ is not overridden by $J$. 1931 \item $m$ is not overridden by $J$.
1733 \end{itemize} 1932 \end{itemize}
1734 1933
1934 \LMHash{}
1735 Furthermore, we define $overrides(J, K)$ to be the set of members $m^\prime$ su ch that all of the following hold: 1935 Furthermore, we define $overrides(J, K)$ to be the set of members $m^\prime$ su ch that all of the following hold:
1736 \begin{itemize} 1936 \begin{itemize}
1737 \item $J$ is the implicit interface of a class $C$. 1937 \item $J$ is the implicit interface of a class $C$.
1738 \item $C$ declares a member $m$. 1938 \item $C$ declares a member $m$.
1739 \item $m^\prime$ has the same name as $m$. 1939 \item $m^\prime$ has the same name as $m$.
1740 \item $m^\prime$ is accessible to $K$. 1940 \item $m^\prime$ is accessible to $K$.
1741 \item $A$ is a direct superinterface of $J$ and either 1941 \item $A$ is a direct superinterface of $J$ and either
1742 \begin{itemize} 1942 \begin{itemize}
1743 \item $A$ declares a member $m^\prime$ or 1943 \item $A$ declares a member $m^\prime$ or
1744 \item $m^\prime$ is a member of $inherited(A, K)$. 1944 \item $m^\prime$ is a member of $inherited(A, K)$.
1745 \end{itemize} 1945 \end{itemize}
1746 \end{itemize} 1946 \end{itemize}
1747 1947
1748 1948
1949 \LMHash{}
1749 Let $I$ be the implicit interface of a class $C$ declared in library $L$. $I$ { \em inherits} all members of $inherited(I, L)$ and $I$ {\em overrides} $m^\prime $ if $m^\prime \in overrides(I, L)$. 1950 Let $I$ be the implicit interface of a class $C$ declared in library $L$. $I$ { \em inherits} all members of $inherited(I, L)$ and $I$ {\em overrides} $m^\prime $ if $m^\prime \in overrides(I, L)$.
1750 1951
1952 \LMHash{}
1751 All the static warnings pertaining to the overriding of instance members given i n section \ref{classes} above hold for overriding between interfaces as well. 1953 All the static warnings pertaining to the overriding of instance members given i n section \ref{classes} above hold for overriding between interfaces as well.
1752 1954
1955 \LMHash{}
1753 It is a static warning if $m$ is a method and $m^\prime$ is a getter, or if $m$ is a getter and $m^\prime$ is a method. 1956 It is a static warning if $m$ is a method and $m^\prime$ is a getter, or if $m$ is a getter and $m^\prime$ is a method.
1754 1957
1755 1958
1756 1959
1757 %Let $I = S_0$ be the implicit interface of a class $C$ declared in library $L$, and let $\{S_1 \ldots S_k\}$ be the set of all superinterfaces of $I$. 1960 %Let $I = S_0$ be the implicit interface of a class $C$ declared in library $L$, and let $\{S_1 \ldots S_k\}$ be the set of all superinterfaces of $I$.
1758 1961
1759 %Let $I$ be the implicit interface of a class $C$. $I$ inherits any instance me mbers of its superinterfaces that are not overridden by members declared in $C$. 1962 %Let $I$ be the implicit interface of a class $C$. $I$ inherits any instance me mbers of its superinterfaces that are not overridden by members declared in $C$.
1760 1963
1761 % tighten definition? do we need chain as for classes? Definition for interface override? 1964 % tighten definition? do we need chain as for classes? Definition for interface override?
1762 1965
1966 \LMHash{}
1763 However, if the above rules would cause multiple members $m_1, \ldots, m_k$ wit h the same name $n$ to be inherited (because identically named members existed i n several superinterfaces) then at most one member is inherited. 1967 However, if the above rules would cause multiple members $m_1, \ldots, m_k$ wit h the same name $n$ to be inherited (because identically named members existed i n several superinterfaces) then at most one member is inherited.
1764 1968
1969 \LMHash{}
1765 If some but not all of the $m_i, 1 \le i \le k$ are getters none of the $m_i$ ar e inherited, and a static warning is issued. 1970 If some but not all of the $m_i, 1 \le i \le k$ are getters none of the $m_i$ ar e inherited, and a static warning is issued.
1766 1971
1972 \LMHash{}
1767 Otherwise, if the static types $T_1, \ldots, T_k$ of the members $m_1, \ldots, m_k$ are not identical, then there must be a member $m_x$ such that $T_x <: T_ i, 1 \le x \le k$ for all $i \in 1..k$, or a static type warning occurs. The m ember that is inherited is $m_x$, if it exists; otherwise: 1973 Otherwise, if the static types $T_1, \ldots, T_k$ of the members $m_1, \ldots, m_k$ are not identical, then there must be a member $m_x$ such that $T_x <: T_ i, 1 \le x \le k$ for all $i \in 1..k$, or a static type warning occurs. The m ember that is inherited is $m_x$, if it exists; otherwise:
1768 let $numberOfPositionals(f)$ denote the number of positional parameters of a fu nction $f$, and let $numberOfRequiredParams(f)$ denote the number of required pa rameters of a function $f$. Furthermore, let $s$ denote the set of all named par ameters of the $m_1, \ldots, m_k$. Then let 1974 let $numberOfPositionals(f)$ denote the number of positional parameters of a fu nction $f$, and let $numberOfRequiredParams(f)$ denote the number of required pa rameters of a function $f$. Furthermore, let $s$ denote the set of all named par ameters of the $m_1, \ldots, m_k$. Then let
1769 1975
1770 $h = max(numberOfPositionals(m_i)), $ 1976 $h = max(numberOfPositionals(m_i)), $
1771 1977
1772 $r = min(numberOfRequiredParams(m_i)), i \in 1..k$. 1978 $r = min(numberOfRequiredParams(m_i)), i \in 1..k$.
1773 1979
1980 \LMHash{}
1774 Then $I$ has a method named $n$, with $r$ required parameters of type \DYNAMIC{} , $h$ positional parameters of type \DYNAMIC{}, named parameters $s$ of type \ DYNAMIC{} and return type \DYNAMIC{}. 1981 Then $I$ has a method named $n$, with $r$ required parameters of type \DYNAMIC{} , $h$ positional parameters of type \DYNAMIC{}, named parameters $s$ of type \ DYNAMIC{} and return type \DYNAMIC{}.
1775 1982
1776 1983
1777 1984
1778 \commentary{The only situation where the runtime would be concerned with this wo uld be during reflection, if a mirror attempted to obtain the signature of an in terface member. 1985 \commentary{The only situation where the runtime would be concerned with this wo uld be during reflection, if a mirror attempted to obtain the signature of an in terface member.
1779 } 1986 }
1780 1987
1781 \rationale{ 1988 \rationale{
1782 The current solution is a tad complex, but is robust in the face of type annotat ion changes. Alternatives: (a) No member is inherited in case of conflict. (b) The first m is selected (based on order of superinterface list) (c) Inherited me mber chosen at random. 1989 The current solution is a tad complex, but is robust in the face of type annotat ion changes. Alternatives: (a) No member is inherited in case of conflict. (b) The first m is selected (based on order of superinterface list) (c) Inherited me mber chosen at random.
1783 1990
1784 (a) means that the presence of an inherited member of an interface varies depend ing on type signatures. (b) is sensitive to irrelevant details of the declarati on and (c) is liable to give unpredictable results between implementations or ev en between different compilation sessions. 1991 (a) means that the presence of an inherited member of an interface varies depend ing on type signatures. (b) is sensitive to irrelevant details of the declarati on and (c) is liable to give unpredictable results between implementations or ev en between different compilation sessions.
1785 } 1992 }
1786 1993
1787 % Need warnings if overrider conflicts with overriddee either because signatures are incompatible or because done is a method and one is a getter or setter. 1994 % Need warnings if overrider conflicts with overriddee either because signatures are incompatible or because done is a method and one is a getter or setter.
1788 1995
1789 \section{Mixins} 1996 \section{Mixins}
1790 \label{mixins} 1997 \LMLabel{mixins}
1791 1998
1792 1999
2000 \LMHash{}
1793 A mixin describes the difference between a class and its superclass. A mixin is always derived from an existing class declaration. 2001 A mixin describes the difference between a class and its superclass. A mixin is always derived from an existing class declaration.
1794 2002
2003 \LMHash{}
1795 It is a compile-time error if a declared or derived mixin refers to \SUPER{}. It is a compile-time error if a declared or derived mixin explicitly declares a co nstructor. It is a compile-time error if a mixin is derived from a class whose s uperclass is not \code{Object}. 2004 It is a compile-time error if a declared or derived mixin refers to \SUPER{}. It is a compile-time error if a declared or derived mixin explicitly declares a co nstructor. It is a compile-time error if a mixin is derived from a class whose s uperclass is not \code{Object}.
1796 2005
1797 \rationale{ 2006 \rationale{
1798 These restrictions are temporary. We expect to remove them in later versions of Dart. 2007 These restrictions are temporary. We expect to remove them in later versions of Dart.
1799 2008
1800 The restriction on the use of \SUPER{} avoids the problem of rebinding \SUPER{} when the mixin is bound to difference superclasses. 2009 The restriction on the use of \SUPER{} avoids the problem of rebinding \SUPER{} when the mixin is bound to difference superclasses.
1801 2010
1802 The restriction on constructors simplifies the construction of mixin application s because the process of creating instances is simpler. 2011 The restriction on constructors simplifies the construction of mixin application s because the process of creating instances is simpler.
1803 2012
1804 The restriction on the superclass means that the type of a class from which a m ixin is derived is always implemented by any class that mixes it in. This allows us to defer the question of whether and how to express the type of the mixin in dependently of its superclass and super interface types. 2013 The restriction on the superclass means that the type of a class from which a m ixin is derived is always implemented by any class that mixes it in. This allows us to defer the question of whether and how to express the type of the mixin in dependently of its superclass and super interface types.
1805 2014
1806 Reasonable answers exist for all these issues, but their implementation is non-t rivial. 2015 Reasonable answers exist for all these issues, but their implementation is non-t rivial.
1807 } 2016 }
1808 2017
1809 \subsection{Mixin Application} 2018 \subsection{Mixin Application}
1810 \label{mixinApplication} 2019 \LMLabel{mixinApplication}
1811 2020
2021 \LMHash{}
1812 A mixin may be applied to a superclass, yielding a new class. Mixin application occurs when a mixin is mixed into a class declaration via its \WITH{} clause. T he mixin application may be used to extend a class per section (\ref{classes}); alternately, a class may be defined as a mixin application as described in this section. It is a compile-time error if the \WITH{} clause of a mixin applicati on $C$ includes a deferred type expression. 2022 A mixin may be applied to a superclass, yielding a new class. Mixin application occurs when a mixin is mixed into a class declaration via its \WITH{} clause. T he mixin application may be used to extend a class per section (\ref{classes}); alternately, a class may be defined as a mixin application as described in this section. It is a compile-time error if the \WITH{} clause of a mixin applicati on $C$ includes a deferred type expression.
1813 2023
1814 2024
1815 \begin{grammar} 2025 \begin{grammar}
1816 {\bf mixinApplicationClass:} 2026 {\bf mixinApplicationClass:}
1817 identifier typeParameters? `=' mixinApplication `{\escapegrammar ;}' . 2027 identifier typeParameters? `=' mixinApplication `{\escapegrammar ;}' .
1818 2028
1819 {\bf mixinApplication:} 2029 {\bf mixinApplication:}
1820 type mixins interfaces? 2030 type mixins interfaces?
1821 . 2031 .
1822 \end{grammar} 2032 \end{grammar}
1823 2033
2034 \LMHash{}
1824 A mixin application of the form \code{$S$ \WITH{} $M$;} defines a class $C$ w ith superclass $S$. 2035 A mixin application of the form \code{$S$ \WITH{} $M$;} defines a class $C$ w ith superclass $S$.
1825 2036
2037 \LMHash{}
1826 A mixin application of the form \code{$S$ \WITH{} $M_1, \ldots, M_k$;} defines a class $C$ whose superclass is the application of the mixin composition (\ref {mixinComposition}) $M_{k-1} * \ldots * M_1$ to $S$. 2038 A mixin application of the form \code{$S$ \WITH{} $M_1, \ldots, M_k$;} defines a class $C$ whose superclass is the application of the mixin composition (\ref {mixinComposition}) $M_{k-1} * \ldots * M_1$ to $S$.
1827 2039
2040 \LMHash{}
1828 In both cases above, $C$ declares the same instance members as $M$ (respectively , $M_k$). If any of the instance fields of $M$ (respectively, $M_k$) have initia lizers, they are executed in the scope of $M$ (respectively, $M_k$) to initializ e the corresponding fields of $C$. 2041 In both cases above, $C$ declares the same instance members as $M$ (respectively , $M_k$). If any of the instance fields of $M$ (respectively, $M_k$) have initia lizers, they are executed in the scope of $M$ (respectively, $M_k$) to initializ e the corresponding fields of $C$.
1829 2042
2043 \LMHash{}
1830 For each generative constructor named $q_i(T_{i1}$ $ a_{i1}, \ldots , T_{ik_i}$ $ a_{ik_i}), i \in 1..n$ of $S$, $C$ has an implicitly declared constructor name d 2044 For each generative constructor named $q_i(T_{i1}$ $ a_{i1}, \ldots , T_{ik_i}$ $ a_{ik_i}), i \in 1..n$ of $S$, $C$ has an implicitly declared constructor name d
1831 $q'_i = [C/S]q_i$ of the form 2045 $q'_i = [C/S]q_i$ of the form
1832 2046
1833 $q'_i(a_{i1}, \ldots , a_{ik_i}):\SUPER(a_{i1}, \ldots , a_{ik_i});$. 2047 $q'_i(a_{i1}, \ldots , a_{ik_i}):\SUPER(a_{i1}, \ldots , a_{ik_i});$.
1834 2048
1835 %super.id 2049 %super.id
1836 2050
2051 \LMHash{}
1837 If the mixin application declares support for interfaces, the resulting class im plements those interfaces. 2052 If the mixin application declares support for interfaces, the resulting class im plements those interfaces.
1838 2053
2054 \LMHash{}
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$). 2055 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$).
1840 2056
2057 \LMHash{}
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. 2058 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.
1842 2059
1843 \commentary{ 2060 \commentary{
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$. 2061 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$.
1845 2062
1846 } 2063 }
1847 2064
2065 \LMHash{}
1848 The effect of a class definition of the form \code{\CLASS{} $C$ = $M$; } or the form 2066 The effect of a class definition of the form \code{\CLASS{} $C$ = $M$; } or the form
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. 2067 \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.
1850 2068
1851 2069
1852 \subsection{Mixin Composition} 2070 \subsection{Mixin Composition}
1853 \label{mixinComposition} 2071 \LMLabel{mixinComposition}
1854 2072
1855 \rationale{ 2073 \rationale{
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. 2074 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.
1857 } 2075 }
1858 2076
2077 \LMHash{}
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 2078 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
1860 2079
1861 $M_1<T_1 \ldots T_{k_{M_1}}> * M_2<U_1 \ldots U_{k_{M_2}}>$ 2080 $M_1<T_1 \ldots T_{k_{M_1}}> * M_2<U_1 \ldots U_{k_{M_2}}>$
1862 2081
1863 to $S<V_1 \ldots V_{k_S}>$ is equivalent to 2082 to $S<V_1 \ldots V_{k_S}>$ is equivalent to
1864 2083
1865 \begin{dartCode} 2084 \begin{dartCode}
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}> = $ 2085 \ABSTRACT{} \CLASS{} $Id_1<T_1 \ldots T_{k_{M_1}}, U_1 \ldots U_{k_{M_2}}, V_1 \ldots V_{k_S}> = $
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}}>$; 2086 $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}}>$;
1868 \end{dartCode} 2087 \end{dartCode}
1869 2088
1870 where $Id_2$ denotes 2089 where $Id_2$ denotes
1871 2090
1872 \begin{dartCode} 2091 \begin{dartCode}
1873 \ABSTRACT{} \CLASS{} $Id_2<U_1 \ldots U_{k_{M_2}}, V_1 \ldots V_{k_S}> =$ 2092 \ABSTRACT{} \CLASS{} $Id_2<U_1 \ldots U_{k_{M_2}}, V_1 \ldots V_{k_S}> =$
1874 $S<V_1 \ldots V_{k_S}>$ \WITH{} $M_2<U_1 \ldots U_{k_{ M_2}}>$; 2093 $S<V_1 \ldots V_{k_S}>$ \WITH{} $M_2<U_1 \ldots U_{k_{ M_2}}>$;
1875 \end{dartCode} 2094 \end{dartCode}
1876 2095
1877 and $Id_1$ and $Id_2$ are unique identifiers that do not exist anywhere in the p rogram. 2096 and $Id_1$ and $Id_2$ are unique identifiers that do not exist anywhere in the p rogram.
1878 2097
1879 \rationale{ 2098 \rationale{
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. 2099 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.
1881 } 2100 }
1882 2101
2102 \LMHash{}
1883 Mixin composition is associative. 2103 Mixin composition is associative.
1884 2104
1885 2105
1886 \commentary{ 2106 \commentary{
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. 2107 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.
1888 } 2108 }
1889 2109
1890 2110
1891 \section{Enums} 2111 \section{Enums}
1892 \label{enums} 2112 \LMLabel{enums}
1893 2113
2114 \LMHash{}
1894 An {\em enumerated type}, or {\em enum}, is used to represent a fixed number of constant values. 2115 An {\em enumerated type}, or {\em enum}, is used to represent a fixed number of constant values.
1895 2116
1896 \begin{grammar} 2117 \begin{grammar}
1897 {\bf enumType:} 2118 {\bf enumType:}
1898 metadata \ENUM{} id `\{' id [`,' id]* [`,'] `\}' 2119 metadata \ENUM{} id `\{' id [`,' id]* [`,'] `\}'
1899 . 2120 .
1900 \end{grammar} 2121 \end{grammar}
1901 2122
2123 \LMHash{}
1902 The declaration of an enum of the form \code{metadata \ENUM{} E \{ id$_0$, \ldot s id$_{n-1}$\};} 2124 The declaration of an enum of the form \code{metadata \ENUM{} E \{ id$_0$, \ldot s id$_{n-1}$\};}
1903 has the same effect as a class declaration 2125 has the same effect as a class declaration
1904 2126
1905 \begin{dartCode} 2127 \begin{dartCode}
1906 metadata \CLASS{} E \{ 2128 metadata \CLASS{} E \{
1907 \FINAL{} int index; 2129 \FINAL{} int index;
1908 \CONST{} E(\THIS{}.index); 2130 \CONST{} E(\THIS{}.index);
1909 \STATIC{} \CONST{} E id$_0$ = \CONST{} E(0); 2131 \STATIC{} \CONST{} E id$_0$ = \CONST{} E(0);
1910 $\ldots$ 2132 $\ldots$
1911 \STATIC{} \CONST{} E id$_{n-1}$ = const E(n - 1); 2133 \STATIC{} \CONST{} E id$_{n-1}$ = const E(n - 1);
1912 \STATIC{} \CONST{} List$<$E$>$ values = const $<$E$>$[id$_0 \ldots $ id$_{n-1} $]; 2134 \STATIC{} \CONST{} List$<$E$>$ values = const $<$E$>$[id$_0 \ldots $ id$_{n-1} $];
1913 String toString() =$>$ \{ 0: `E.id$_0$', $\ldots$, n-1: `E.id$_{n-1}$'\}[index ] 2135 String toString() =$>$ \{ 0: `E.id$_0$', $\ldots$, n-1: `E.id$_{n-1}$'\}[index ]
1914 \} 2136 \}
1915 \end{dartCode} 2137 \end{dartCode}
1916 2138
1917 \commentary { 2139 \commentary {
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. 2140 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.
1919 } 2141 }
1920 2142
1921 \section{Generics} 2143 \section{Generics}
1922 \label{generics} 2144 \LMLabel{generics}
1923 2145
2146 \LMHash{}
1924 A class declaration (\ref{classes}) or type alias (\ref{typedef}) 2147 A class declaration (\ref{classes}) or type alias (\ref{typedef})
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. 2148 $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.
1926 2149
1927 \begin{grammar} 2150 \begin{grammar}
1928 {\bf typeParameter:} 2151 {\bf typeParameter:}
1929 metadata identifier (\EXTENDS{} type)? 2152 metadata identifier (\EXTENDS{} type)?
1930 . 2153 .
1931 {\bf typeParameters:} 2154 {\bf typeParameters:}
1932 `<' typeParameter (`,' typeParameter)* `>' 2155 `<' typeParameter (`,' typeParameter)* `>'
1933 . 2156 .
1934 \end{grammar} 2157 \end{grammar}
1935 2158
2159 \LMHash{}
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. 2160 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.
1937 2161
2162 \LMHash{}
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. 2163 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.
1939 2164
1940 \rationale{ 2165 \rationale{
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. 2166 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.
1942 } 2167 }
1943 2168
1944 \commentary{ 2169 \commentary{
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: 2170 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:
1946 } 2171 }
1947 2172
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2003 2228
2004 2229
2005 %class T {...} 2230 %class T {...}
2006 2231
2007 %class G<T> extends T; 2232 %class G<T> extends T;
2008 2233
2009 %By current rules, this is illegal. Make sure we preserve this. 2234 %By current rules, this is illegal. Make sure we preserve this.
2010 2235
2011 2236
2012 %\subsection{Interface Injection} 2237 %\subsection{Interface Injection}
2013 %\label{interfaceInjection} 2238 %\LMLabel{interfaceInjection}
2014 2239
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. 2240 %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.
2016 2241
2017 %\begin{grammar} 2242 %\begin{grammar}
2018 %classInterfaceInjection: 2243 %classInterfaceInjection:
2019 %class qualified typeParameters? interfaces '{\escapegrammar ;}' 2244 %class qualified typeParameters? interfaces '{\escapegrammar ;}'
2020 % . 2245 % .
2021 2246
2022 2247
2023 %interfaceInterfaceInjection: 2248 %interfaceInterfaceInjection:
2024 %interface qualified typeParameters? superinterfaces '{\escapegrammar ;}' 2249 %interface qualified typeParameters? superinterfaces '{\escapegrammar ;}'
2025 %. 2250 %.
2026 %\end{grammar} 2251 %\end{grammar}
2027 2252
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. 2253 %\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.
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). 2254 %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).
2030 %} 2255 %}
2031 2256
2032 %\Q{When does an interface injection take effect? When the containing library is loaded? 2257 %\Q{When does an interface injection take effect? When the containing library is loaded?
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. 2258 %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.
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? 2259 %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?
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. 2260 %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.
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. 2261 %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.
2037 %} 2262 %}
2038 2263
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. 2264 %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.
2040 2265
2041 2266
2042 \section{Metadata} 2267 \section{Metadata}
2043 \label{metadata} 2268 \LMLabel{metadata}
2044 2269
2270 \LMHash{}
2045 Dart supports metadata which is used to attach user defined annotations to progr am structures. 2271 Dart supports metadata which is used to attach user defined annotations to progr am structures.
2046 2272
2047 \begin{grammar} 2273 \begin{grammar}
2048 {\bf metadata:} 2274 {\bf metadata:}
2049 (`@' qualified ({\escapegrammar `.'} identifier)? (arguments)?)* 2275 (`@' qualified ({\escapegrammar `.'} identifier)? (arguments)?)*
2050 . 2276 .
2051 \end{grammar} 2277 \end{grammar}
2052 2278
2279 \LMHash{}
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: 2280 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:
2054 \begin{itemize} 2281 \begin{itemize}
2055 \item A reference to a compile-time constant variable. 2282 \item A reference to a compile-time constant variable.
2056 \item A call to a constant constructor. 2283 \item A call to a constant constructor.
2057 \end{itemize} 2284 \end{itemize}
2058 2285
2286 \LMHash{}
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. 2287 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.
2060 2288
2061 \commentary{ 2289 \commentary{
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. 2290 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.
2063 } 2291 }
2064 2292
2065 \rationale{ 2293 \rationale{
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. 2294 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.
2067 } 2295 }
2068 2296
2069 \commentary{ 2297 \commentary{
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. 2298 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.
2071 } 2299 }
2072 2300
2301 \LMHash{}
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. 2302 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.
2074 2303
2304 \LMHash{}
2075 The constant expression given in an annotation is type checked and evaluated in the scope surrounding the declaration being annotated. 2305 The constant expression given in an annotation is type checked and evaluated in the scope surrounding the declaration being annotated.
2076 2306
2077 2307
2078 \section{Expressions} 2308 \section{Expressions}
2079 \label{expressions} 2309 \LMLabel{expressions}
2080 2310
2311 \LMHash{}
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}). 2312 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}).
2082 2313
2083 2314
2084 \begin{grammar} 2315 \begin{grammar}
2085 2316
2086 {\bf expression:}assignableExpression assignmentOperator expression; 2317 {\bf expression:}assignableExpression assignmentOperator expression;
2087 conditionalExpression cascadeSection*; 2318 conditionalExpression cascadeSection*;
2088 throwExpression 2319 throwExpression
2089 . 2320 .
2090 2321
(...skipping 14 matching lines...) Expand all
2105 functionExpression; 2336 functionExpression;
2106 literal; 2337 literal;
2107 identifier; 2338 identifier;
2108 newExpression; 2339 newExpression;
2109 constObjectExpression; 2340 constObjectExpression;
2110 `(' expression `)' 2341 `(' expression `)'
2111 . 2342 .
2112 2343
2113 \end{grammar} 2344 \end{grammar}
2114 2345
2346 \LMHash{}
2115 An expression $e$ may always be enclosed in parentheses, but this never has any semantic effect on $e$. 2347 An expression $e$ may always be enclosed in parentheses, but this never has any semantic effect on $e$.
2116 2348
2117 \commentary{ 2349 \commentary{
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. 2350 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.
2119 } 2351 }
2120 2352
2121 \subsubsection{Object Identity} 2353 \subsubsection{Object Identity}
2122 \label{objectIdentity} 2354 \LMLabel{objectIdentity}
2123 2355
2356 \LMHash{}
2124 The predefined Dart function \cd{identical()} is defined such that \code{identic al($c_1$, $c_2$)} iff: 2357 The predefined Dart function \cd{identical()} is defined such that \code{identic al($c_1$, $c_2$)} iff:
2125 \begin{itemize} 2358 \begin{itemize}
2126 \item $c_1$ evaluates to either \NULL{} or an instance of \code{bool} and \co de{$c_1$ == $c_2$}, OR 2359 \item $c_1$ evaluates to either \NULL{} or an instance of \code{bool} and \co de{$c_1$ == $c_2$}, OR
2127 \item $c_1$ and $c_2$ are instances of \code{int} and \code{$c_1$ == $c_2$}, OR 2360 \item $c_1$ and $c_2$ are instances of \code{int} and \code{$c_1$ == $c_2$}, OR
2128 \item $c_1$ and $c_2$ are constant strings and \code{$c_1$ == $c_2$}, OR 2361 \item $c_1$ and $c_2$ are constant strings and \code{$c_1$ == $c_2$}, OR
2129 \item $c_1$ and $c_2$ are instances of \cd{double} and one of the following holds: 2362 \item $c_1$ and $c_2$ are instances of \cd{double} and one of the following holds:
2130 \begin{itemize} 2363 \begin{itemize}
2131 \item $c_1$ and $c_2$ are non-zero and \code{$c_1$ == $c_2$}. 2364 \item $c_1$ and $c_2$ are non-zero and \code{$c_1$ == $c_2$}.
2132 \item Both $c_1$ and $c_2$ are $+0.0$. 2365 \item Both $c_1$ and $c_2$ are $+0.0$.
2133 \item Both $c_1$ and $c_2$ are $-0.0$. 2366 \item Both $c_1$ and $c_2$ are $-0.0$.
(...skipping 13 matching lines...) Expand all
2147 \rationale{ 2380 \rationale{
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. 2381 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.
2149 2382
2150 The definition of identity is not constrained in the same way. Instead, it assum es that bit-identical doubles are identical. 2383 The definition of identity is not constrained in the same way. Instead, it assum es that bit-identical doubles are identical.
2151 2384
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. 2385 The rules for identity make it impossible for a Dart programmer to observe wheth er a boolean or numerical value is boxed or unboxed.
2153 } 2386 }
2154 2387
2155 2388
2156 \subsection{Constants} 2389 \subsection{Constants}
2157 \label{constants} 2390 \LMLabel{constants}
2158 2391
2392 \LMHash{}
2159 A {\em constant expression} is an expression whose value can never change, and t hat can be evaluated entirely at compile time. 2393 A {\em constant expression} is an expression whose value can never change, and t hat can be evaluated entirely at compile time.
2160 2394
2395 \LMHash{}
2161 A constant expression is one of the following: 2396 A constant expression is one of the following:
2162 \begin{itemize} 2397 \begin{itemize}
2163 \item A literal number (\ref{numbers}). 2398 \item A literal number (\ref{numbers}).
2164 \item A literal boolean (\ref{booleans}). 2399 \item A literal boolean (\ref{booleans}).
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{}. 2400 \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{}.
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.} 2401 \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.}
2167 \item A literal symbol (\ref{symbols}). 2402 \item A literal symbol (\ref{symbols}).
2168 \item \NULL{} (\ref{null}). 2403 \item \NULL{} (\ref{null}).
2169 \item A qualified reference to a static constant variable (\ref{variables}) that is not qualified by a deferred prefix. 2404 \item A qualified reference to a static constant variable (\ref{variables}) that is not qualified by 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. 2405 \commentary {For example, If class C declares a constant static variable v, C.v is a constant. The same is true if C is accessed via a prefix p; p.C.v is a cons tant unless p is a deferred prefix.
(...skipping 14 matching lines...) Expand all
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{}. 2420 \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{}.
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{}. 2421 \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{}.
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. 2422 \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.
2188 \item An expression of the form \code{$e$.length} where $e$ is a constant expres sion that evaluates to a string value. 2423 \item An expression of the form \code{$e$.length} where $e$ is a constant expres sion that evaluates to a string value.
2189 \end{itemize} 2424 \end{itemize}
2190 2425
2191 % null in all the expressions 2426 % null in all the expressions
2192 2427
2193 % designed so constants do not depend on check diode being on or not. 2428 % designed so constants do not depend on check diode being on or not.
2194 2429
2430 \LMHash{}
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. 2431 It is a compile-time error if an expression is required to be a constant express ion but its evaluation would raise an exception.
2196 2432
2197 % so, checked mode? analyzers? editor/development compilers? 2433 % so, checked mode? analyzers? editor/development compilers?
2198 \commentary{ 2434 \commentary{
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. 2435 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.
2200 2436
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. 2437 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.
2202 2438
2203 On the other hand, since implementations are free to compile code late, some com pile-time errors may manifest quite late. 2439 On the other hand, since implementations are free to compile code late, some com pile-time errors may manifest quite late.
2204 } 2440 }
(...skipping 22 matching lines...) Expand all
2227 } 2463 }
2228 2464
2229 \rationale{ 2465 \rationale{
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: 2466 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:
2231 \begin{enumerate} 2467 \begin{enumerate}
2232 \item It is constant. We can evaluate it at compile-time. 2468 \item It is constant. We can evaluate it at compile-time.
2233 \item It seems more useful to give the error stemming from the evaluation explic itly. 2469 \item It seems more useful to give the error stemming from the evaluation explic itly.
2234 \end{enumerate} 2470 \end{enumerate}
2235 } 2471 }
2236 2472
2473 \LMHash{}
2237 It is a compile-time error if the value of a compile-time constant expression de pends on itself. 2474 It is a compile-time error if the value of a compile-time constant expression de pends on itself.
2238 2475
2239 \commentary{ 2476 \commentary{
2240 As an example, consider: 2477 As an example, consider:
2241 } 2478 }
2242 2479
2243 \begin{dartCode} 2480 \begin{dartCode}
2244 \CLASS{} CircularConsts\{ 2481 \CLASS{} CircularConsts\{
2245 // Illegal program - mutually recursive compile-time constants 2482 // Illegal program - mutually recursive compile-time constants
2246 \STATIC{} \CONST{} i = j; // a compile-time constant 2483 \STATIC{} \CONST{} i = j; // a compile-time constant
2247 \STATIC{} \CONST{} j = i; // a compile-time constant 2484 \STATIC{} \CONST{} j = i; // a compile-time constant
2248 \} 2485 \}
2249 \end{dartCode} 2486 \end{dartCode}
2250 2487
2251 2488
2252 \begin{grammar} 2489 \begin{grammar}
2253 {\bf literal:}nullLiteral; 2490 {\bf literal:}nullLiteral;
2254 booleanLiteral; 2491 booleanLiteral;
2255 numericLiteral; 2492 numericLiteral;
2256 stringLiteral; 2493 stringLiteral;
2257 symbolLiteral; 2494 symbolLiteral;
2258 mapLiteral; 2495 mapLiteral;
2259 listLiteral 2496 listLiteral
2260 . 2497 .
2261 \end{grammar} 2498 \end{grammar}
2262 2499
2263 2500
2264 2501
2265 \subsection{Null} 2502 \subsection{Null}
2266 \label{null} 2503 \LMLabel{null}
2267 2504
2505 \LMHash{}
2268 The reserved word \NULL{} denotes the {\em null object}. 2506 The reserved word \NULL{} denotes the {\em null object}.
2269 %\Q{Any methods, such as \code{isNull}?} 2507 %\Q{Any methods, such as \code{isNull}?}
2270 2508
2271 \begin{grammar} 2509 \begin{grammar}
2272 {\bf nullLiteral:} 2510 {\bf nullLiteral:}
2273 \NULL{} 2511 \NULL{}
2274 . 2512 .
2275 \end{grammar} 2513 \end{grammar}
2276 2514
2515 \LMHash{}
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}. 2516 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}.
2278 Invoking a method on \NULL{} yields a \code{NoSuchMethodError} unless the metho d is explicitly implemented by class \code{Null}. 2517 Invoking a method on \NULL{} yields a \code{NoSuchMethodError} unless the metho d is explicitly implemented by class \code{Null}.
2279 2518
2519 \LMHash{}
2280 The static type of \NULL{} is $\bot$. 2520 The static type of \NULL{} is $\bot$.
2281 2521
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. 2522 \rationale{The decision to use $\bot$ instead of \code{Null} allows \NULL{} to b e be assigned everywhere without complaint by the static checker.
2283 } 2523 }
2284 2524
2285 2525
2286 \subsection{Numbers} 2526 \subsection{Numbers}
2287 \label{numbers} 2527 \LMLabel{numbers}
2288 2528
2529 \LMHash{}
2289 A {\em numeric literal} is either a decimal or hexadecimal integer of arbitrary size, or a decimal double. 2530 A {\em numeric literal} is either a decimal or hexadecimal integer of arbitrary size, or a decimal double.
2290 2531
2291 \begin{grammar} 2532 \begin{grammar}
2292 {\bf numericLiteral:}NUMBER; 2533 {\bf numericLiteral:}NUMBER;
2293 HEX\_NUMBER 2534 HEX\_NUMBER
2294 . 2535 .
2295 2536
2296 {\bf NUMBER:} DIGIT+ (`{\escapegrammar.}' DIGIT+)? EXPONENT?; 2537 {\bf NUMBER:} DIGIT+ (`{\escapegrammar.}' DIGIT+)? EXPONENT?;
2297 {`\escapegrammar .}' DIGIT+ EXPONENT? 2538 {`\escapegrammar .}' DIGIT+ EXPONENT?
2298 . 2539 .
2299 2540
2300 {\bf EXPONENT:} 2541 {\bf EXPONENT:}
2301 (`e' $|$ `E') ('+' $|$ `-`)? DIGIT+ 2542 (`e' $|$ `E') ('+' $|$ `-`)? DIGIT+
2302 . 2543 .
2303 2544
2304 {\bf HEX\_NUMBER:}`0x' HEX\_DIGIT+; 2545 {\bf HEX\_NUMBER:}`0x' HEX\_DIGIT+;
2305 `0X' HEX\_DIGIT+ 2546 `0X' HEX\_DIGIT+
2306 . 2547 .
2307 2548
2308 {\bf HEX\_DIGIT:}`a'{\escapegrammar ..}'f'; 2549 {\bf HEX\_DIGIT:}`a'{\escapegrammar ..}'f';
2309 `A'{\escapegrammar ..}'F'; 2550 `A'{\escapegrammar ..}'F';
2310 DIGIT 2551 DIGIT
2311 . 2552 .
2312 \end{grammar} 2553 \end{grammar}
2313 2554
2555 \LMHash{}
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. 2556 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.
2315 2557
2558 \LMHash{}
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. 2559 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.
2317 2560
2318 \commentary{ 2561 \commentary{
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. 2562 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.
2320 } 2563 }
2321 2564
2565 \LMHash{}
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}. 2566 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}.
2323 2567
2568 \LMHash{}
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}. 2569 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}.
2325 2570
2571 \LMHash{}
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}. 2572 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}.
2327 The static type of a literal double is \code{double}. 2573 The static type of a literal double is \code{double}.
2328 2574
2329 \subsection{Booleans} 2575 \subsection{Booleans}
2330 \label{booleans} 2576 \LMLabel{booleans}
2331 2577
2578 \LMHash{}
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}. 2579 The reserved words \TRUE{} and \FALSE{} denote objects that represent the boolea n values true and false respectively. They are the {\em boolean literals}.
2333 2580
2334 \begin{grammar} 2581 \begin{grammar}
2335 {\bf booleanLiteral:}\TRUE{}; 2582 {\bf booleanLiteral:}\TRUE{};
2336 \FALSE{} 2583 \FALSE{}
2337 . 2584 .
2338 \end{grammar} 2585 \end{grammar}
2339 2586
2587 \LMHash{}
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}. 2588 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}.
2341 2589
2342 \commentary{ 2590 \commentary{
2343 It follows that the two boolean literals are the only two instances of \code{boo l}. 2591 It follows that the two boolean literals are the only two instances of \code{boo l}.
2344 } 2592 }
2345 2593
2594 \LMHash{}
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}. 2595 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}.
2347 2596
2348 \subsubsection{Boolean Conversion} 2597 \subsubsection{Boolean Conversion}
2349 \label{booleanConversion} 2598 \LMLabel{booleanConversion}
2350 2599
2600 \LMHash{}
2351 {\em Boolean conversion} maps any object $o$ into a boolean. Boolean conversion is defined by the function application 2601 {\em Boolean conversion} maps any object $o$ into a boolean. Boolean conversion is defined by the function application
2352 2602
2353 \begin{dartCode} 2603 \begin{dartCode}
2354 (bool v)\{ 2604 (bool v)\{
2355 \ASSERT{}(v != \NULL{}); 2605 \ASSERT{}(v != \NULL{});
2356 % \IF{} (\NULL{} == v) \{ \THROW{} \NEW{} AssertionError('null is not a bo ol')\}; 2606 % \IF{} (\NULL{} == v) \{ \THROW{} \NEW{} AssertionError('null is not a bo ol')\};
2357 \RETURN{} identical(v, \TRUE{}); 2607 \RETURN{} identical(v, \TRUE{});
2358 \}(o) 2608 \}(o)
2359 \end{dartCode} 2609 \end{dartCode}
2360 2610
2361 \rationale{ 2611 \rationale{
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. 2612 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.
2363 2613
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. 2614 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.
2365 2615
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). 2616 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).
2367 } 2617 }
2368 2618
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. 2619 \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.
2370 } 2620 }
2371 2621
2372 \subsection{Strings} 2622 \subsection{Strings}
2373 \label{strings} 2623 \LMLabel{strings}
2374 2624
2625 \LMHash{}
2375 A {\em string} is a sequence of UTF-16 code units. 2626 A {\em string} is a sequence of UTF-16 code units.
2376 2627
2377 \rationale{ 2628 \rationale{
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. 2629 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.
2379 } 2630 }
2380 2631
2381 \begin{grammar} 2632 \begin{grammar}
2382 {\bf stringLiteral:}(multilineString $|$ singleLineString)+ 2633 {\bf stringLiteral:}(multilineString $|$ singleLineString)+
2383 . 2634 .
2384 \end{grammar} 2635 \end{grammar}
2385 2636
2637 \LMHash{}
2386 A string can be either a sequence of single line strings or a multiline string. 2638 A string can be either a sequence of single line strings or a multiline string.
2387 2639
2388 \begin{grammar} 2640 \begin{grammar}
2389 {\bf singleLineString:}`{\escapegrammar \code{"}}' stringContentDQ* `{\escapegr ammar \code{"}}'; 2641 {\bf singleLineString:}`{\escapegrammar \code{"}}' stringContentDQ* `{\escapegr ammar \code{"}}';
2390 `{\escapegrammar \code{'}}' stringContentSQ* `{\escapegrammar \code{'}}'; 2642 `{\escapegrammar \code{'}}' stringContentSQ* `{\escapegrammar \code{'}}';
2391 `r' `{\escapegrammar \code{'}}' (\~{}( `{\escapegrammar \code{'}}' $|$ NEW LINE ))* `{\escapegrammar \code{'}}'; 2643 `r' `{\escapegrammar \code{'}}' (\~{}( `{\escapegrammar \code{'}}' $|$ NEW LINE ))* `{\escapegrammar \code{'}}';
2392 `r' `{\escapegrammar \code{"}}' (\~{}( `{\escapegrammar \code{"}}' $|$ NEW LINE ))* `{\escapegrammar \code{"}}' 2644 `r' `{\escapegrammar \code{"}}' (\~{}( `{\escapegrammar \code{"}}' $|$ NEW LINE ))* `{\escapegrammar \code{"}}'
2393 . 2645 .
2394 \end{grammar} 2646 \end{grammar}
2395 2647
2648 \LMHash{}
2396 A single line string is delimited by either matching single quotes or matching d ouble quotes. 2649 A single line string is delimited by either matching single quotes or matching d ouble quotes.
2397 2650
2398 \commentary{ 2651 \commentary{
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''. 2652 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''.
2400 } 2653 }
2401 2654
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. 2655 \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.
2403 } 2656 }
2404 2657
2658 \LMHash{}
2405 Adjacent 2659 Adjacent
2406 %single line 2660 %single line
2407 strings are implicitly concatenated to form a single string literal. 2661 strings are implicitly concatenated to form a single string literal.
2408 %, and so are adjacent multiline strings, but the two forms may not be mixed. 2662 %, and so are adjacent multiline strings, but the two forms may not be mixed.
2409 2663
2410 2664
2411 \commentary{Here is an example} 2665 \commentary{Here is an example}
2412 2666
2413 \begin{dartCode} 2667 \begin{dartCode}
2414 print("A string" "and then another"); // prints: A stringand then another 2668 print("A string" "and then another"); // prints: A stringand then another
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2467 `$\backslash$ u' HEX\_DIGIT HEX\_DIGIT HEX\_DIGIT HEX\_DIGIT; 2721 `$\backslash$ u' HEX\_DIGIT HEX\_DIGIT HEX\_DIGIT HEX\_DIGIT;
2468 `$\backslash$ u\{' HEX\_DIGIT\_SEQUENCE `\}' 2722 `$\backslash$ u\{' HEX\_DIGIT\_SEQUENCE `\}'
2469 . 2723 .
2470 2724
2471 {\bf HEX\_DIGIT\_SEQUENCE:} 2725 {\bf HEX\_DIGIT\_SEQUENCE:}
2472 HEX\_DIGIT HEX\_DIGIT? HEX\_DIGIT? HEX\_DIGIT? HEX\_DIGIT? HEX\_DIGIT? 2726 HEX\_DIGIT HEX\_DIGIT? HEX\_DIGIT? HEX\_DIGIT? HEX\_DIGIT? HEX\_DIGIT?
2473 . 2727 .
2474 2728
2475 \end{grammar} 2729 \end{grammar}
2476 2730
2731 \LMHash{}
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. 2732 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.
2478 2733
2479 2734
2480 \rationale{ 2735 \rationale{
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. 2736 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.
2482 } 2737 }
2483 2738
2739 \LMHash{}
2484 Strings support escape sequences for special characters. The escapes are: 2740 Strings support escape sequences for special characters. The escapes are:
2485 \begin{itemize} 2741 \begin{itemize}
2486 \item $\backslash$n for newline, equivalent to $\backslash$x0A. 2742 \item $\backslash$n for newline, equivalent to $\backslash$x0A.
2487 \item $\backslash$r for carriage return, equivalent to $\backslash$x0D. 2743 \item $\backslash$r for carriage return, equivalent to $\backslash$x0D.
2488 \item $\backslash$f for form feed, equivalent to $\backslash$x0C. 2744 \item $\backslash$f for form feed, equivalent to $\backslash$x0C.
2489 \item $\backslash$b for backspace, equivalent to $\backslash$x08. 2745 \item $\backslash$b for backspace, equivalent to $\backslash$x08.
2490 \item $\backslash$t for tab, equivalent to $\backslash$x09. 2746 \item $\backslash$t for tab, equivalent to $\backslash$x09.
2491 \item $\backslash$v for vertical tab, equivalent to $\backslash$x0B 2747 \item $\backslash$v for vertical tab, equivalent to $\backslash$x0B
2492 \item $\backslash$x $HEX\_DIGIT_1$ $HEX\_DIGIT_2$, equivalent to 2748 \item $\backslash$x $HEX\_DIGIT_1$ $HEX\_DIGIT_2$, equivalent to
2493 2749
2494 $\backslash$u\{$HEX\_DIGIT_1$ $HEX\_DIGIT_2$\}. 2750 $\backslash$u\{$HEX\_DIGIT_1$ $HEX\_DIGIT_2$\}.
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$\}. 2751 \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$\}.
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. 2752 \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.
2497 \item \$ indicating the beginning of an interpolated expression. 2753 \item \$ indicating the beginning of an interpolated expression.
2498 \item Otherwise, $\backslash k$ indicates the character $k$ for any $k$ not in $ \{n, r, f, b, t, v, x, u\}$. 2754 \item Otherwise, $\backslash k$ indicates the character $k$ for any $k$ not in $ \{n, r, f, b, t, v, x, u\}$.
2499 \end{itemize} 2755 \end{itemize}
2500 2756
2757 \LMHash{}
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. 2758 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.
2502 2759
2760 \LMHash{}
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. 2761 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.
2504 2762
2505 2763
2506 2764
2507 \begin{grammar} 2765 \begin{grammar}
2508 {\bf stringContentDQ:}\~{}( `$\backslash$' $|$ `{\escapegrammar \texttt{"}}' $| $ `\$' $|$ NEWLINE ); 2766 {\bf stringContentDQ:}\~{}( `$\backslash$' $|$ `{\escapegrammar \texttt{"}}' $| $ `\$' $|$ NEWLINE );
2509 `$\backslash$' \~{}( NEWLINE ); 2767 `$\backslash$' \~{}( NEWLINE );
2510 stringInterpolation 2768 stringInterpolation
2511 . 2769 .
2512 2770
(...skipping 10 matching lines...) Expand all
2523 {\bf stringContentTSQ:}\~{}( `$\backslash$' $|$ `{\escapegrammar \code{'}\code{ '}\code{'}}' $|$ `\$'); 2781 {\bf stringContentTSQ:}\~{}( `$\backslash$' $|$ `{\escapegrammar \code{'}\code{ '}\code{'}}' $|$ `\$');
2524 stringInterpolation 2782 stringInterpolation
2525 . 2783 .
2526 2784
2527 {\bf NEWLINE:}$\backslash$ n; 2785 {\bf NEWLINE:}$\backslash$ n;
2528 $\backslash$ r 2786 $\backslash$ r
2529 . 2787 .
2530 2788
2531 \end{grammar} 2789 \end{grammar}
2532 2790
2791 \LMHash{}
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}. 2792 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}.
2534 2793
2535 \subsubsection{String Interpolation} 2794 \subsubsection{String Interpolation}
2536 \label{stringInterpolation} 2795 \LMLabel{stringInterpolation}
2537 2796
2797 \LMHash{}
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}. 2798 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}.
2539 2799
2540 \begin{grammar} 2800 \begin{grammar}
2541 {\bf stringInterpolation:}`\$' IDENTIFIER\_NO\_DOLLAR; 2801 {\bf stringInterpolation:}`\$' IDENTIFIER\_NO\_DOLLAR;
2542 `\$' `\{' expression `\}' % could be top level expression, no? 2802 `\$' `\{' expression `\}' % could be top level expression, no?
2543 . 2803 .
2544 \end{grammar} 2804 \end{grammar}
2545 2805
2546 \commentary{The reader will note that the expression inside the interpolation co uld itself include strings, which could again be interpolated recursively. 2806 \commentary{The reader will note that the expression inside the interpolation co uld itself include strings, which could again be interpolated recursively.
2547 } 2807 }
2548 2808
2809 \LMHash{}
2549 An unescaped \$ character in a string signifies the beginning of an interpolated expression. The \$ sign may be followed by either: 2810 An unescaped \$ character in a string signifies the beginning of an interpolated expression. The \$ sign may be followed by either:
2550 \begin{itemize} 2811 \begin{itemize}
2551 \item A single identifier $id$ that must not contain the \$ character. 2812 \item A single identifier $id$ that must not contain the \$ character.
2552 \item An expression $e$ delimited by curly braces. 2813 \item An expression $e$ delimited by curly braces.
2553 \end{itemize} 2814 \end{itemize}
2554 2815
2816 \LMHash{}
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$'' }. 2817 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$'' }.
2556 2818
2557 \subsection{Symbols} 2819 \subsection{Symbols}
2558 \label{symbols} 2820 \LMLabel{symbols}
2559 2821
2822 \LMHash{}
2560 A {\em symbol literal} denotes the name of a declaration in a Dart program. 2823 A {\em symbol literal} denotes the name of a declaration in a Dart program.
2561 2824
2562 \begin{grammar} 2825 \begin{grammar}
2563 {\bf symbolLiteral:} 2826 {\bf symbolLiteral:}
2564 `\#' (operator $|$ (identifier (`{\escapegrammar .}' identifier)*)) . 2827 `\#' (operator $|$ (identifier (`{\escapegrammar .}' identifier)*)) .
2565 \end{grammar} 2828 \end{grammar}
2566 2829
2830 \LMHash{}
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')}. 2831 A symbol literal \code{\#id} where \code{id} does not begin with an underscore ( '\code{\_}') is equivalent to the expression \code{\CONST{} Symbol('id')}.
2568 2832
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. 2833 \LMHash{}
2834 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.
2570 2835
2571 \rationale{ 2836 \rationale{
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. 2837 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.
2573 2838
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. 2839 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.
2575 } 2840 }
2576 2841
2842 \LMHash{}
2577 The static type of a symbol literal is \code{Symbol}. 2843 The static type of a symbol literal is \code{Symbol}.
2578 2844
2579 \subsection{Lists} 2845 \subsection{Lists}
2580 \label{lists} 2846 \LMLabel{lists}
2581 2847
2848 \LMHash{}
2582 A {\em list literal} denotes a list, which is an integer indexed collection of o bjects. 2849 A {\em list literal} denotes a list, which is an integer indexed collection of o bjects.
2583 2850
2584 \begin{grammar} 2851 \begin{grammar}
2585 {\bf listLiteral:} 2852 {\bf listLiteral:}
2586 \CONST{}? typeArguments? `[' (expressionList `,'?)? `]' 2853 \CONST{}? typeArguments? `[' (expressionList `,'?)? `]'
2587 . 2854 .
2588 \end{grammar} 2855 \end{grammar}
2589 2856
2857 \LMHash{}
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. 2858 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.
2591 2859
2592 2860
2861 \LMHash{}
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 2862 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
2594 after they are created. Attempting to mutate a constant list literal will result in a dynamic error. 2863 after they are created. Attempting to mutate a constant list literal will result in a dynamic error.
2595 2864
2865 \LMHash{}
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. 2866 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.
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.} 2867 \rationale{The binding of a type parameter is not known at compile-time, so we c annot use type parameters inside compile-time constants.}
2598 2868
2869 \LMHash{}
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]$. 2870 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]$.
2600 2871
2872 \LMHash{}
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$)}. 2873 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$)}.
2602 2874
2603 \commentary{In other words, constant list literals are canonicalized.} 2875 \commentary{In other words, constant list literals are canonicalized.}
2604 2876
2877 \LMHash{}
2605 A run-time list literal $<E>[e_1 \ldots e_n]$ is evaluated as follows: 2878 A run-time list literal $<E>[e_1 \ldots e_n]$ is evaluated as follows:
2606 \begin{itemize} 2879 \begin{itemize}
2607 \item 2880 \item
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$. 2881 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$.
2609 \item A fresh instance (\ref{generativeConstructors}) $a$, of size $n$, whose class implements the built-in class $List<E>$ is allocated. 2882 \item A fresh instance (\ref{generativeConstructors}) $a$, of size $n$, whose class implements the built-in class $List<E>$ is allocated.
2610 \item 2883 \item
2611
2612 The operator \code{[]=} is invoked on $a$ with first argument $i$ and second a rgument 2884 The operator \code{[]=} is invoked on $a$ with first argument $i$ and second a rgument
2613 %The $i$th element of $a$ is set to 2885 %The $i$th element of $a$ is set to
2614 $o_{i+1}, 0 \le i < n$. 2886 $o_{i+1}, 0 \le i < n$.
2615 \item 2887 \item
2616 The result of the evaluation is $a$. 2888 The result of the evaluation is $a$.
2617 \end{itemize} 2889 \end{itemize}
2618 2890
2619 2891
2620 \commentary{ 2892 \commentary{
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}$. 2893 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}$.
2622 } 2894 }
2623 2895
2896 \LMHash{}
2624 A runtime list literal $[e_1 \ldots e_n]$ is evaluated as $< \DYNAMIC{}>[e_1\l dots e_n]$. 2897 A runtime list literal $[e_1 \ldots e_n]$ is evaluated as $< \DYNAMIC{}>[e_1\l dots e_n]$.
2625 2898
2626 2899
2627 \commentary{ 2900 \commentary{
2628 There is no restriction precluding nesting of list literals. It follows from the rules above that 2901 There is no restriction precluding nesting of list literals. It follows from the rules above that
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{}. 2902 $<List<int>>[[1, 2, 3], [4, 5, 6]]$ is a list with type parameter $List<int>$, c ontaining two lists with type parameter \DYNAMIC{}.
2630 } 2903 }
2631 2904
2905 \LMHash{}
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{}>$. 2906 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{}>$.
2633 2907
2634 \rationale{ 2908 \rationale{
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{}. 2909 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{}.
2636 } 2910 }
2637 2911
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}. 2912 %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}.
2639 % what about generics? 2913 % what about generics?
2640 2914
2641 \subsection{Maps} 2915 \subsection{Maps}
2642 \label{maps} 2916 \LMLabel{maps}
2643 2917
2918 \LMHash{}
2644 A {\em map literal} denotes a map object. 2919 A {\em map literal} denotes a map object.
2645 2920
2646 \begin{grammar} 2921 \begin{grammar}
2647 {\bf mapLiteral:} 2922 {\bf mapLiteral:}
2648 \CONST{}? typeArguments? `\{' (mapLiteralEntry (`,' mapLiteralEntry)* `,' ?)? `\}' 2923 \CONST{}? typeArguments? `\{' (mapLiteralEntry (`,' mapLiteralEntry)* `,' ?)? `\}'
2649 . 2924 .
2650 2925
2651 {\bf mapLiteralEntry:} 2926 {\bf mapLiteralEntry:}
2652 % identifier `{\escapegrammar :}' expression; 2927 % identifier `{\escapegrammar :}' expression;
2653 expression `{\escapegrammar :}' expression 2928 expression `{\escapegrammar :}' expression
2654 . 2929 .
2655 \end{grammar} 2930 \end{grammar}
2656 2931
2932 \LMHash{}
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. 2933 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.
2658 2934
2935 \LMHash{}
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 2936 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
2660 after they are created. Attempting to mutate a constant map literal will result in a dynamic error. 2937 after they are created. Attempting to mutate a constant map literal will result in a dynamic error.
2661 2938
2939 \LMHash{}
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 2940 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
2663 %symbol, 2941 %symbol,
2664 string, an integer, a literal symbol or the result of invoking a constant constr uctor of class \cd{Symbol}. 2942 string, an integer, a literal symbol or the result of invoking a constant constr uctor of class \cd{Symbol}.
2665 It is a compile-time error if the type arguments of a constant map literal inclu de a type parameter. 2943 It is a compile-time error if the type arguments of a constant map literal inclu de a type parameter.
2666 2944
2945 \LMHash{}
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\}$. 2946 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\}$.
2668 2947
2948 \LMHash{}
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$)}. 2949 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$)}.
2670 2950
2671 \commentary{In other words, constant map literals are canonicalized.} 2951 \commentary{In other words, constant map literals are canonicalized.}
2672 2952
2953 \LMHash{}
2673 A runtime map literal $<K, V>\{k_1:e_1\ldots k_n :e_n\}$ is evaluated as follow s: 2954 A runtime map literal $<K, V>\{k_1:e_1\ldots k_n :e_n\}$ is evaluated as follow s:
2674 \begin{itemize} 2955 \begin{itemize}
2675 \item 2956 \item
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$. 2957 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$.
2677 \item A fresh instance (\ref{generativeConstructors}) $m$ whose class implement s the built-in class 2958 \item A fresh instance (\ref{generativeConstructors}) $m$ whose class implement s the built-in class
2678 2959
2679 $Map<K, V>$ is allocated. 2960 $Map<K, V>$ is allocated.
2680 \item 2961 \item
2681 The operator \code{[]=} is invoked on $m$ with first argument $u_i$ and second argument $o_i, i \in 1.. n$. 2962 The operator \code{[]=} is invoked on $m$ with first argument $u_i$ and second argument $o_i, i \in 1.. n$.
2682 \item 2963 \item
2683 The result of the evaluation is $m$. 2964 The result of the evaluation is $m$.
2684 \end{itemize} 2965 \end{itemize}
2685 2966
2686 2967
2968 \LMHash{}
2687 A runtime map literal $\{k_1:e_1\ldots k_n :e_n\}$ is evaluated as 2969 A runtime map literal $\{k_1:e_1\ldots k_n :e_n\}$ is evaluated as
2688 2970
2689 $<\DYNAMIC{}, \DYNAMIC{}>\{k_1:e_1\ldots k_n :e_n\}$. 2971 $<\DYNAMIC{}, \DYNAMIC{}>\{k_1:e_1\ldots k_n :e_n\}$.
2690 2972
2973 \LMHash{}
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. 2974 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.
2692 2975
2976 \LMHash{}
2693 A map literal is ordered: iterating over the keys and/or values of the maps alwa ys happens in the 2977 A map literal is ordered: iterating over the keys and/or values of the maps alwa ys happens in the
2694 order the keys appeared in the source code. 2978 order the keys appeared in the source code.
2695 2979
2696 \commentary{ 2980 \commentary{
2697 Of course, if a key repeats, the order is defined by first occurrence, but the v alue is defined by the last. 2981 Of course, if a key repeats, the order is defined by first occurrence, but the v alue is defined by the last.
2698 } 2982 }
2699 2983
2984 \LMHash{}
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{}>$. 2985 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{}>$.
2701 2986
2702 2987
2703 \subsection{Throw} 2988 \subsection{Throw}
2704 \label{throw} 2989 \LMLabel{throw}
2705 2990
2991 \LMHash{}
2706 The {\em throw expression} is used to raise an exception. 2992 The {\em throw expression} is used to raise an exception.
2707 2993
2708 \begin{grammar} 2994 \begin{grammar}
2709 {\bf throwExpression:} 2995 {\bf throwExpression:}
2710 \THROW{} expression 2996 \THROW{} expression
2711 . 2997 .
2712 2998
2713 {\bf throwExpressionWithoutCascade:} 2999 {\bf throwExpressionWithoutCascade:}
2714 \THROW{} expressionWithoutCascade 3000 \THROW{} expressionWithoutCascade
2715 . 3001 .
2716 3002
2717 \end{grammar} 3003 \end{grammar}
2718 3004
3005 \LMHash{}
2719 The {\em current exception} is the last exception raised and not subsequently c aught at a given moment during runtime. 3006 The {\em current exception} is the last exception raised and not subsequently c aught at a given moment during runtime.
2720 3007
3008 \LMHash{}
2721 Evaluation of a throw expression of the form \code{\THROW{} $e$;} proceeds as follows: 3009 Evaluation of a throw expression of the form \code{\THROW{} $e$;} proceeds as follows:
2722 3010
3011 \LMHash{}
2723 The expression $e$ is evaluated yielding a value $v$. 3012 The expression $e$ is evaluated yielding a value $v$.
2724 3013
2725 \commentary{ 3014 \commentary{
2726 There is no requirement that the expression $e$ evaluate to a special kind of ex ception or error object. 3015 There is no requirement that the expression $e$ evaluate to a special kind of ex ception or error object.
2727 } 3016 }
2728 3017
3018 \LMHash{}
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. 3019 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.
2730 3020
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. 3021 \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.
2732 } 3022 }
2733 3023
3024 \LMHash{}
2734 Let $f$ be the immediately enclosing function. 3025 Let $f$ be the immediately enclosing function.
2735 3026
3027 \LMHash{}
2736 If $f$ is synchronous (\ref{functions}), control is transferred to the nearest d ynamically enclosing exception handler. 3028 If $f$ is synchronous (\ref{functions}), control is transferred to the nearest d ynamically enclosing exception handler.
2737 3029
2738 \commentary{ 3030 \commentary{
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. 3031 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.
2740 } 3032 }
2741 3033
3034 \LMHash{}
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. 3035 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.
2743 3036
2744 \rationale{ 3037 \rationale{
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. 3038 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.
2746 } 3039 }
2747 3040
3041 \LMHash{}
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. 3042 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.
2749 3043
3044 \LMHash{}
2750 The static type of a throw expression is $\bot$. 3045 The static type of a throw expression is $\bot$.
2751 3046
2752 3047
2753 \subsection{ Function Expressions} 3048 \subsection{ Function Expressions}
2754 \label{functionExpressions} 3049 \LMLabel{functionExpressions}
2755 3050
3051 \LMHash{}
2756 A {\em function literal} is an object that encapsulates an executable unit of co de. 3052 A {\em function literal} is an object that encapsulates an executable unit of co de.
2757 3053
2758 \begin{grammar} 3054 \begin{grammar}
2759 {\bf functionExpression:} 3055 {\bf functionExpression:}
2760 formalParameterList functionBody 3056 formalParameterList functionBody
2761 . 3057 .
2762 \end{grammar} 3058 \end{grammar}
2763 3059
3060 \LMHash{}
2764 The class of a function literal implements the built-in class \code{Function}. 3061 The class of a function literal implements the built-in class \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}. 3062 %Invoking the getter \code{runtimeType} on a function literal returns the \code{ Type} object that is the value of the expression \code{Function}.
2766 % not necessarily 3063 % not necessarily
2767 3064
2768 3065
2769 %Q{Can anyone implement it? Then we should define things via call} 3066 %Q{Can anyone implement it? Then we should define things via call}
2770 3067
3068 \LMHash{}
2771 The static type of a function literal of the form 3069 The static type of a function literal of the form
2772 3070
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$ 3071 $(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$
2774 is 3072 is
2775 3073
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$. 3074 $(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$.
2777 3075
3076 \LMHash{}
2778 The static type of a function literal of the form 3077 The static type of a function literal of the form
2779 3078
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$ 3079 $(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$
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$. 3080 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$.
2782 3081
3082 \LMHash{}
2783 The static type of a function literal of the form 3083 The static type of a function literal of the form
2784 3084
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$ 3085 $(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$
2786 is 3086 is
2787 3087
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$. 3088 $(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$.
2789 3089
3090 \LMHash{}
2790 The static type of a function literal of the form 3091 The static type of a function literal of the form
2791 3092
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$ 3093 $(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$
2793 3094
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$. 3095 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$.
2795 3096
3097 \LMHash{}
2796 The static type of a function literal of the form 3098 The static type of a function literal of the form
2797 3099
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\}$ 3100 $(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\}$
2799 3101
2800 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w \DYNAMIC{}$. 3102 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w \DYNAMIC{}$.
2801 3103
3104 \LMHash{}
2802 The static type of a function literal of the form 3105 The static type of a function literal of the form
2803 3106
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\}$ 3107 $(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\}$
2805 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Future$. 3108 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Future$.
2806 3109
3110 \LMHash{}
2807 The static type of a function literal of the form 3111 The static type of a function literal of the form
2808 3112
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\}$ 3113 $(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\}$
2810 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Stream$. 3114 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Stream$.
2811 3115
3116 \LMHash{}
2812 The static type of a function literal of the form 3117 The static type of a function literal of the form
2813 3118
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\}$ 3119 $(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\}$
2815 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Iterable$. 3120 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Iterable$.
2816 3121
2817 3122
3123 \LMHash{}
2818 The static type of a function literal of the form 3124 The static type of a function literal of the form
2819 3125
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\}$ 3126 $(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\}$
2821 3127
2822 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w \DYNAMIC{}$. 3128 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w \DYNAMIC{}$.
2823 3129
2824 3130
3131 \LMHash{}
2825 The static type of a function literal of the form 3132 The static type of a function literal of the form
2826 3133
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\}$ 3134 $(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\}$
2828 3135
2829 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar row Future{}$. 3136 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar row Future{}$.
2830 3137
3138 \LMHash{}
2831 The static type of a function literal of the form 3139 The static type of a function literal of the form
2832 3140
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\}$ 3141 $(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\}$
2834 3142
2835 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar row Stream{}$. 3143 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar row Stream{}$.
2836 3144
3145 \LMHash{}
2837 The static type of a function literal of the form 3146 The static type of a function literal of the form
2838 3147
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\}$ 3148 $(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\}$
2840 3149
2841 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar row Iterable{}$. 3150 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar row Iterable{}$.
2842 3151
3152 \LMHash{}
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{}. 3153 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{}.
2844 3154
2845 3155
2846 \subsection{ This} 3156 \subsection{ This}
2847 \label{this} 3157 \LMLabel{this}
2848 3158
3159 \LMHash{}
2849 The reserved word \THIS{} denotes the target of the current instance member invo cation. 3160 The reserved word \THIS{} denotes the target of the current instance member invo cation.
2850 3161
2851 \begin{grammar} 3162 \begin{grammar}
2852 {\bf thisExpression:} 3163 {\bf thisExpression:}
2853 \THIS{} 3164 \THIS{}
2854 . 3165 .
2855 \end{grammar} 3166 \end{grammar}
2856 3167
3168 \LMHash{}
2857 The static type of \THIS{} is the interface of the immediately enclosing class. 3169 The static type of \THIS{} is the interface of the immediately enclosing class.
2858 3170
2859 \commentary{ 3171 \commentary{
2860 We do not support self-types at this point. 3172 We do not support self-types at this point.
2861 } 3173 }
2862 3174
3175 \LMHash{}
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. 3176 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.
2864 3177
2865 \subsection{ Instance Creation} 3178 \subsection{ Instance Creation}
2866 \label{instanceCreation} 3179 \LMLabel{instanceCreation}
2867 3180
3181 \LMHash{}
2868 Instance creation expressions invoke constructors to produce instances. 3182 Instance creation expressions invoke constructors to produce instances.
2869 3183
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. 3184 %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.
2871 3185
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}). 3186 %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}).
2873 3187
3188 \LMHash{}
2874 It is a static type warning if 3189 It is a static type warning if
2875 the type $T$ in an instance creation expression of one of the forms 3190 the type $T$ in an instance creation expression of one of the forms
2876 3191
2877 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 3192 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
2878 3193
2879 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 3194 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
2880 3195
2881 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 3196 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
2882 3197
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}). 3198 \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}).
2884 3199
3200 \LMHash{}
2885 It is a compile-time error if the type $T$ in an instance creation expression of one of the forms 3201 It is a compile-time error if the type $T$ in an instance creation expression of one of the forms
2886 3202
2887 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 3203 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
2888 3204
2889 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 3205 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
2890 3206
2891 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 3207 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
2892 3208
2893 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3209 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
2894 3210
2895 is an enumerated type (\ref{enums}). 3211 is an enumerated type (\ref{enums}).
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$. 3212 %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$.
2897 3213
2898 3214
2899 \subsubsection{ New} 3215 \subsubsection{ New}
2900 \label{new} 3216 \LMLabel{new}
2901 3217
3218 \LMHash{}
2902 The {\em new expression} invokes a constructor (\ref{constructors}). 3219 The {\em new expression} invokes a constructor (\ref{constructors}).
2903 3220
2904 \begin{grammar} 3221 \begin{grammar}
2905 {\bf newExpression:} 3222 {\bf newExpression:}
2906 \NEW{} type (`{\escapegrammar .}' identifier)? arguments 3223 \NEW{} type (`{\escapegrammar .}' identifier)? arguments
2907 . 3224 .
2908 \end{grammar} 3225 \end{grammar}
2909 3226
3227 \LMHash{}
2910 Let $e$ be a new expression of the form 3228 Let $e$ be a new expression of the form
2911 3229
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 3230 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ or the form
2913 3231
2914 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. 3232 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$.
2915 3233
2916 %It is a runtime type error if 3234 %It is a runtime type error if
2917 %the type $T$ is malformed. 3235 %the type $T$ is malformed.
2918 %It is a static warning if $T$ is a malformed type. 3236 %It is a static warning if $T$ is a malformed type.
2919 3237
2920 %not a class accessible in the current scope, optionally followed by type argum ents. 3238 %not a class accessible in the current scope, optionally followed by type argum ents.
2921 3239
3240 \LMHash{}
2922 If $T$ is a class or parameterized type accessible in the current scope then: 3241 If $T$ is a class or parameterized type accessible in the current scope then:
2923 \begin{itemize} 3242 \begin{itemize}
2924 \item 3243 \item
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$. 3244 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$.
2926 \end{itemize} 3245 \end{itemize}
2927 3246
3247 \LMHash{}
2928 If $T$ is a parameterized type (\ref{parameterizedTypes}) $S<U_1, \ldots, U_m>$ , let $R = S$. 3248 If $T$ is a parameterized type (\ref{parameterizedTypes}) $S<U_1, \ldots, U_m>$ , let $R = S$.
2929 %It is a 3249 %It is a
2930 %compile-time CHANGED 3250 %compile-time CHANGED
2931 %runtime type 3251 %runtime type
2932 %error if $S$ is not a generic (\ref{generics}) type with $m$ type parameters. 3252 %error if $S$ is not a generic (\ref{generics}) type with $m$ type parameters.
2933 If $T$ is not a parameterized type, let $R = T$. 3253 If $T$ is not a parameterized type, let $R = 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$. 3254 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$.
2935 3255
3256 \LMHash{}
2936 If $R$ is a generic with $l = m$ type parameters then 3257 If $R$ is a generic with $l = m$ type parameters then
2937 \begin{itemize} 3258 \begin{itemize}
2938 \item If $T$ is not a parameterized type, then for $ i \in 1 .. l$, let $V_i = \DYNAMIC{}$. 3259 \item If $T$ is not a parameterized type, then for $ i \in 1 .. l$, let $V_i = \DYNAMIC{}$.
2939 \item If $T$ is a parameterized type then let $V_i = U_i$ for $ i \in 1 .. m$. 3260 \item If $T$ is a parameterized type then let $V_i = U_i$ for $ i \in 1 .. m$.
2940 \end{itemize} 3261 \end{itemize}
2941 3262
3263 \LMHash{}
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$. 3264 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$.
2943 3265
3266 \LMHash{}
2944 Evaluation of $e$ proceeds as follows: 3267 Evaluation of $e$ proceeds as follows:
2945 3268
3269 \LMHash{}
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. 3270 First, the argument list $(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k} : a_{n+k})$ is evaluated.
2947 3271
3272 \LMHash{}
2948 If $T$ is a deferred type with prefix $p$, then if $p$ has not been successfully loaded, a dynamic error occurs. 3273 If $T$ is a deferred type with prefix $p$, then if $p$ has not been successfully loaded, a dynamic error occurs.
2949 3274
3275 \LMHash{}
2950 Then, if $q$ is a non-factory constructor of an abstract class then an \code{Abs tractClassInstantiationError} is thrown. 3276 Then, if $q$ is a non-factory constructor of an abstract class then an \code{Abs tractClassInstantiationError} is thrown.
2951 3277
3278 \LMHash{}
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. 3279 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.
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. 3280 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.
2954 3281
3282 \LMHash{}
2955 Otherwise, if $q$ is a generative constructor (\ref{generativeConstructors}), th en: 3283 Otherwise, if $q$ is a generative constructor (\ref{generativeConstructors}), th en:
2956 3284
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.} 3285 \commentary{Note that it this point we are assured that the number of actual typ e arguments match the number of formal type parameters.}
2958 3286
3287 \LMHash{}
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{}. 3288 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{}.
2960 3289
2961 \commentary{ 3290 \commentary{
2962 Observe that \THIS{} is not in scope in $e_f$. Hence, the initialization cannot depend on other properties of the object being instantiated. 3291 Observe that \THIS{} is not in scope in $e_f$. Hence, the initialization cannot depend on other properties of the object being instantiated.
2963 } 3292 }
2964 3293
3294 \LMHash{}
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$. 3295 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$.
2966 3296
3297 \LMHash{}
2967 Otherwise, $q$ is a factory constructor (\ref{factories}). Then: 3298 Otherwise, $q$ is a factory constructor (\ref{factories}). Then:
2968 3299
3300 \LMHash{}
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 3301 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
2970 3302
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. 3303 $[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.
2972 3304
2973 3305
3306 \LMHash{}
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$. 3307 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$.
2975 3308
3309 \LMHash{}
2976 It is a static warning if $q$ is a constructor of an abstract class and $q$ is n ot a factory constructor. 3310 It is a static warning if $q$ is a constructor of an abstract class and $q$ is n ot a factory constructor.
2977 3311
2978 \commentary{The above gives precise meaning to the idea that instantiating an ab stract class leads to a warning. 3312 \commentary{The above gives precise meaning to the idea that instantiating an ab stract class leads to a warning.
2979 A similar clause applies to constant object creation in the next section. 3313 A similar clause applies to constant object creation in the next section.
2980 } 3314 }
2981 3315
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. 3316 \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.
2983 } 3317 }
2984 3318
3319 \LMHash{}
2985 The static type of an instance creation expression of either the form 3320 The static type of an instance creation expression of either the form
2986 3321
2987 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3322 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
2988 3323
2989 or the form 3324 or the form
2990 3325
2991 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3326 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
2992 3327
2993 is $T$. 3328 is $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$). 3329 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$).
2995 3330
2996 3331
2997 3332
2998 \subsubsection{ Const} 3333 \subsubsection{ Const}
2999 \label{const} 3334 \LMLabel{const}
3000 3335
3336 \LMHash{}
3001 A {\em constant object expression} invokes a constant constructor (\ref{constant Constructors}). 3337 A {\em constant object expression} invokes a constant constructor (\ref{constant Constructors}).
3002 3338
3003 \begin{grammar} 3339 \begin{grammar}
3004 {\bf constObjectExpression:} 3340 {\bf constObjectExpression:}
3005 \CONST{} type ('{\escapegrammar .}' identifier)? arguments 3341 \CONST{} type ('{\escapegrammar .}' identifier)? arguments
3006 . 3342 .
3007 \end{grammar} 3343 \end{grammar}
3008 3344
3345 \LMHash{}
3009 Let $e$ be a constant object expression of the form 3346 Let $e$ be a constant object expression of the form
3010 3347
3011 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3348 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
3012 3349
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}). 3350 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}).
3014 3351
3015 \commentary{In particular, $T$ may not be a type variable.} 3352 \commentary{In particular, $T$ may not be a type variable.}
3016 3353
3354 \LMHash{}
3017 If $T$ is a parameterized type, it is a compile-time error if $T$ includes a typ e variable among its type arguments. 3355 If $T$ is a parameterized type, it is a compile-time error if $T$ includes a typ e variable among its type arguments.
3018 3356
3357 \LMHash{}
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$. 3358 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$.
3020 3359
3360 \LMHash{}
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. 3361 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.
3022 3362
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$. 3363 %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$.
3024 %Finally, 3364 %Finally,
3025 % If $T$ is a generic with $l$ retype parameters, then for all $ i \in 1 .. l$, let $V_i = \DYNAMIC{}$. 3365 % If $T$ is a generic with $l$ retype parameters, then for all $ i \in 1 .. l$, let $V_i = \DYNAMIC{}$.
3026 3366
3367 \LMHash{}
3027 Evaluation of $e$ proceeds as follows: 3368 Evaluation of $e$ proceeds as follows:
3028 3369
3370 \LMHash{}
3029 First, if $e$ is of the form 3371 First, if $e$ is of the form
3030 3372
3031 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3373 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
3032 3374
3033 then let $i$ be the value of the expression 3375 then let $i$ be the value of the expression
3034 3376
3035 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. 3377 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$.
3036 3378
3379 \LMHash{}
3037 Otherwise, $e$ must be of the form 3380 Otherwise, $e$ must be of the form
3038 3381
3039 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 3382 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
3040 3383
3041 in which case let $i$ be the result of evaluating 3384 in which case let $i$ be the result of evaluating
3042 3385
3043 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. 3386 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$.
3044 3387
3388 \LMHash{}
3045 Then: 3389 Then:
3046 \begin{itemize} 3390 \begin{itemize}
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: 3391 \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:
3048 \begin{itemize} 3392 \begin{itemize}
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$. 3393 \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$.
3050 \end{itemize} 3394 \end{itemize}
3051 \item Otherwise the value of $e$ is $i$. 3395 \item Otherwise the value of $e$ is $i$.
3052 \end{itemize} 3396 \end{itemize}
3053 3397
3054 \commentary{ 3398 \commentary{
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. 3399 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.
3056 } 3400 }
3057 3401
3402 \LMHash{}
3058 The static type of a constant object expression of either the form 3403 The static type of a constant object expression of either the form
3059 3404
3060 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3405 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
3061 3406
3062 or the form 3407 or the form
3063 3408
3064 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3409 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
3065 3410
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$). 3411 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$).
3067 3412
3413 \LMHash{}
3068 It is a compile-time error if evaluation of a constant object results in an unca ught exception being thrown. 3414 It is a compile-time error if evaluation of a constant object results in an unca ught exception being thrown.
3069 3415
3070 \commentary{ 3416 \commentary{
3071 To see how such situations might arise, consider the following examples: 3417 To see how such situations might arise, consider the following examples:
3072 } 3418 }
3073 3419
3074 \begin{dartCode} 3420 \begin{dartCode}
3075 \CLASS{} A \{ 3421 \CLASS{} A \{
3076 \FINAL{} x; 3422 \FINAL{} x;
3077 \CONST{} A(p): x = p * 10; 3423 \CONST{} A(p): x = p * 10;
(...skipping 11 matching lines...) Expand all
3089 \} 3435 \}
3090 3436
3091 \CONST{} A(\CONST{} IntPair(1,2)); // compile-time error: illegal in a subtler w ay 3437 \CONST{} A(\CONST{} IntPair(1,2)); // compile-time error: illegal in a subtler w ay
3092 \end{dartCode} 3438 \end{dartCode}
3093 3439
3094 \commentary{ 3440 \commentary{
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. 3441 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.
3096 } 3442 }
3097 3443
3098 3444
3445 \LMHash{}
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. 3446 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.
3100 3447
3101 3448
3102 \subsection{ Spawning an Isolate} 3449 \subsection{ Spawning an Isolate}
3103 \label{spawningAnIsolate} 3450 \LMLabel{spawningAnIsolate}
3104 3451
3452 \LMHash{}
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. 3453 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.
3106 3454
3455 \LMHash{}
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. 3456 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.
3108 3457
3109 \commentary{ 3458 \commentary{
3110 As discussed in section \ref{errorsAndWarnings}, the handling of a suspended iso late is the responsibility of the embedder. 3459 As discussed in section \ref{errorsAndWarnings}, the handling of a suspended iso late is the responsibility of the embedder.
3111 } 3460 }
3112 3461
3113 3462
3114 3463
3115 \subsection{ Function Invocation} 3464 \subsection{ Function Invocation}
3116 \label{functionInvocation} 3465 \LMLabel{functionInvocation}
3117 3466
3467 \LMHash{}
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. 3468 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.
3119 3469
3470 \LMHash{}
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. 3471 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.
3121 3472
3473 \LMHash{}
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: 3474 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:
3123 \begin{itemize} 3475 \begin{itemize}
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}). 3476 \item If the current return value is defined then, if $s$ has been canceled then its cancellation future is completed with \NULL{} (\ref{null}).
3125 \item If the current exception $x$ is defined: 3477 \item If the current exception $x$ is defined:
3126 \begin{itemize} 3478 \begin{itemize}
3127 \item $x$ is added to $s$. 3479 \item $x$ is added to $s$.
3128 \item If $s$ has been canceled then its cancellation future is completed with $x$ as an error. 3480 \item If $s$ has been canceled then its cancellation future is completed with $x$ as an error.
3129 \end{itemize} 3481 \end{itemize}
3130 \item $s$ is closed. 3482 \item $s$ is closed.
3131 \end{itemize} 3483 \end{itemize}
3132 3484
3133 \rationale{ 3485 \rationale{
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. 3486 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.
3135 } 3487 }
3136 3488
3489 \LMHash{}
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. 3490 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.
3138 3491
3139 \rationale{Such streams may be left open by for loops that were escaped when an exception was thrown within them for example. 3492 \rationale{Such streams may be left open by for loops that were escaped when an exception was thrown within them for example.
3140 } 3493 }
3141 3494
3495 \LMHash{}
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. 3496 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.
3143 3497
3498 \LMHash{}
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. 3499 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.
3145 3500
3146 3501
3502 \LMHash{}
3147 Execution of $f$ terminates when the first of the following occurs: 3503 Execution of $f$ terminates when the first of the following occurs:
3148 \begin{itemize} 3504 \begin{itemize}
3149 \item An exception is thrown and not caught within the current function activati on. 3505 \item An exception is thrown and not caught within the current function activati on.
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. 3506 \item A return statement (\ref{return}) immediately nested in the body of $f$ is executed and not intercepted in a \FINALLY{} (\ref{try}) clause.
3151 \item The last statement of the body completes execution. 3507 \item The last statement of the body completes execution.
3152 \end{itemize} 3508 \end{itemize}
3153 3509
3154 3510
3155 3511
3156 3512
3157 \subsubsection{ Actual Argument List Evaluation} 3513 \subsubsection{ Actual Argument List Evaluation}
3158 \label{actualArguments} 3514 \LMLabel{actualArguments}
3159 3515
3516 \LMHash{}
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. 3517 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.
3161 3518
3162 \begin{grammar} 3519 \begin{grammar}
3163 {\bf arguments:} 3520 {\bf arguments:}
3164 `(' argumentList? `)' 3521 `(' argumentList? `)'
3165 . 3522 .
3166 3523
3167 {\bf argumentList:}namedArgument (`,' namedArgument)*; 3524 {\bf argumentList:}namedArgument (`,' namedArgument)*;
3168 % expressionList ',' spreadArgument; 3525 % expressionList ',' spreadArgument;
3169 expressionList (`,' namedArgument)* 3526 expressionList (`,' namedArgument)*
3170 % spreadArgument 3527 % spreadArgument
3171 . 3528 .
3172 3529
3173 {\bf namedArgument:} 3530 {\bf namedArgument:}
3174 label expression % could be top level expression? 3531 label expression % could be top level expression?
3175 . 3532 .
3176 \end{grammar} 3533 \end{grammar}
3177 3534
3535 \LMHash{}
3178 Evaluation of an actual argument list of the form 3536 Evaluation of an actual argument list of the form
3179 3537
3180 $(a_1, \ldots, a_m, q_1: a_{m+1}, \ldots, q_l: a_{m+l})$ 3538 $(a_1, \ldots, a_m, q_1: a_{m+1}, \ldots, q_l: a_{m+l})$
3181 3539
3182 proceeds as follows: 3540 proceeds as follows:
3183 3541
3542 \LMHash{}
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}$. 3543 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}$.
3185 3544
3186 \commentary{Simply stated, an argument list consisting of $m$ positional argumen ts and $l$ named arguments is evaluated from left to right. 3545 \commentary{Simply stated, an argument list consisting of $m$ positional argumen ts and $l$ named arguments is evaluated from left to right.
3187 } 3546 }
3188 3547
3189 3548
3190 \subsubsection{ Binding Actuals to Formals} 3549 \subsubsection{ Binding Actuals to Formals}
3191 \label{bindingActualsToFormals} 3550 \LMLabel{bindingActualsToFormals}
3192 3551
3552 \LMHash{}
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$. 3553 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$.
3194 3554
3555 \LMHash{}
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: 3556 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:
3196 3557
3197 \commentary{ 3558 \commentary{
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. 3559 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.
3199 } 3560 }
3200 3561
3201 \commentary{ 3562 \commentary{
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. 3563 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.
3203 } 3564 }
3204 3565
3205 3566
3567 \LMHash{}
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. 3568 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.
3207 3569
3208 \commentary{All of these remaining parameters are necessarily optional and thus have default values.} 3570 \commentary{All of these remaining parameters are necessarily optional and thus have default values.}
3209 3571
3572 \LMHash{}
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$. 3573 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$.
3211 3574
3575 \LMHash{}
3212 It is a compile-time error if $q_i = q_j$ for any $i \ne j$. 3576 It is a compile-time error if $q_i = q_j$ for any $i \ne j$.
3213 3577
3578 \LMHash{}
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$. 3579 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$.
3215 3580
3216 \subsubsection{ Unqualified Invocation} 3581 \subsubsection{ Unqualified Invocation}
3217 \label{unqualifiedInvocation} 3582 \LMLabel{unqualifiedInvocation}
3218 3583
3584 \LMHash{}
3219 An unqualified function invocation $i$ has the form 3585 An unqualified function invocation $i$ has the form
3220 3586
3221 $id(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$, 3587 $id(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$,
3222 3588
3223 where $id$ is an identifier. 3589 where $id$ is an identifier.
3224 3590
3591 \LMHash{}
3225 If there exists a lexically visible declaration named $id$, let $f_{id}$ be the innermost such declaration. Then: 3592 If there exists a lexically visible declaration named $id$, let $f_{id}$ be the innermost such declaration. Then:
3226 \begin{itemize} 3593 \begin{itemize}
3227 \item 3594 \item
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}). 3595 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}).
3229 \item 3596 \item
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}) $. 3597 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}) $.
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}) $. 3598 \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}) $.
3232 \end{itemize} 3599 \end{itemize}
3233 3600
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})$. 3601 %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})$.
3235 3602
3236 %\rationale{ 3603 %\rationale{
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. 3604 %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.
3238 %} 3605 %}
3239 3606
3607 \LMHash{}
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. 3608 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.
3241 3609
3610 \LMHash{}
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})$. 3611 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})$.
3243 3612
3244 % Should also say: 3613 % Should also say:
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. 3614 % 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.
3246 3615
3247 3616
3248 3617
3249 3618
3250 3619
3251 \subsubsection{ Function Expression Invocation} 3620 \subsubsection{ Function Expression Invocation}
3252 \label{functionExpressionInvocation} 3621 \LMLabel{functionExpressionInvocation}
3253 3622
3623 \LMHash{}
3254 A function expression invocation $i$ has the form 3624 A function expression invocation $i$ has the form
3255 3625
3256 $e_f(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, 3626 $e_f(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
3257 3627
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}). 3628 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}).
3259 3629
3260 \commentary{ 3630 \commentary{
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. 3631 \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.
3262 } 3632 }
3263 3633
3634 \LMHash{}
3264 Otherwise: 3635 Otherwise:
3265 3636
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})$. 3637 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})$.
3267 3638
3268 \commentary{ 3639 \commentary{
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. 3640 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.
3270 } 3641 }
3271 3642
3643 \LMHash{}
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 3644 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
3273 the static type of $i$ is the declared return type of $F$. 3645 the static type of $i$ is the declared return type of $F$.
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$. 3646 %\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$.
3275 %\end{itemize} 3647 %\end{itemize}
3276 3648
3277 \subsection{ Lookup} 3649 \subsection{ Lookup}
3278 3650
3279 \subsubsection{Method Lookup} 3651 \subsubsection{Method Lookup}
3280 \label{methodLookup} 3652 \LMLabel{methodLookup}
3281 3653
3654 \LMHash{}
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$. 3655 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$.
3283 3656
3657 \LMHash{}
3284 The result of a lookup of method $m$ in class $C$ with respect to library $L$ i s: 3658 The result of a lookup of method $m$ in class $C$ with respect to library $L$ i s:
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. 3659 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.
3286 3660
3287 \rationale { 3661 \rationale {
3288 The motivation for skipping abstract members during lookup is largely to allow s moother mixin composition. 3662 The motivation for skipping abstract members during lookup is largely to allow s moother mixin composition.
3289 } 3663 }
3290 3664
3291 3665
3292 \subsubsection{ Getter and Setter Lookup} 3666 \subsubsection{ Getter and Setter Lookup}
3293 \label{getterAndSetterLookup} 3667 \LMLabel{getterAndSetterLookup}
3294 3668
3669 \LMHash{}
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$. 3670 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$.
3296 3671
3672 \LMHash{}
3297 The result of a lookup of a getter (respectively setter) $m$ in class $C$ with respect to library $L$ is: 3673 The result of a lookup of a getter (respectively setter) $m$ in class $C$ with respect to library $L$ is:
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. 3674 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.
3299 3675
3300 \rationale { 3676 \rationale {
3301 The motivation for skipping abstract members during lookup is largely to allow s moother mixin composition. 3677 The motivation for skipping abstract members during lookup is largely to allow s moother mixin composition.
3302 } 3678 }
3303 3679
3304 3680
3305 \subsection{ Top level Getter Invocation} 3681 \subsection{ Top level Getter Invocation}
3306 \label{topLevelGetterInvocation} 3682 \LMLabel{topLevelGetterInvocation}
3307 3683
3684 \LMHash{}
3308 Evaluation of a top-level getter invocation $i$ of the form $m$, where $m$ is an identifier, proceeds as follows: 3685 Evaluation of a top-level getter invocation $i$ of the form $m$, where $m$ is an identifier, proceeds as follows:
3309 3686
3687 \LMHash{}
3310 The getter function $m$ is invoked. The value of $i$ is the result returned by t he call to the getter function. 3688 The getter function $m$ is invoked. The value of $i$ is the result returned by t he call to the getter function.
3311 \commentary{ 3689 \commentary{
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. 3690 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.
3313 } 3691 }
3314 3692
3693 \LMHash{}
3315 The static type of $i$ is the declared return type of $m$. 3694 The static type of $i$ is the declared return type of $m$.
3316 3695
3317 \subsection{ Method Invocation} 3696 \subsection{ Method Invocation}
3318 \label{methodInvocation} 3697 \LMLabel{methodInvocation}
3319 3698
3699 \LMHash{}
3320 Method invocation can take several forms as specified below. 3700 Method invocation can take several forms as specified below.
3321 3701
3322 \subsubsection{Ordinary Invocation} 3702 \subsubsection{Ordinary Invocation}
3323 \label{ordinaryInvocation} 3703 \LMLabel{ordinaryInvocation}
3324 3704
3705 \LMHash{}
3325 An ordinary method invocation $i$ has the form 3706 An ordinary method invocation $i$ has the form
3326 3707
3327 $o.m(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. 3708 $o.m(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$.
3328 3709
3710 \LMHash{}
3329 Evaluation of an ordinary method invocation $i$ of the form 3711 Evaluation of an ordinary method invocation $i$ of the form
3330 3712
3331 $o.m(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 3713 $o.m(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
3332 3714
3333 proceeds as follows: 3715 proceeds as follows:
3334 3716
3717 \LMHash{}
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$. 3718 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$.
3336 3719
3720 \LMHash{}
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$. 3721 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$.
3338 3722
3339 \commentary{ 3723 \commentary{
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. 3724 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.
3341 } 3725 }
3342 3726
3727 \LMHash{}
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. 3728 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.
3344 3729
3730 \LMHash{}
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. 3731 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.
3346 3732
3733 \LMHash{}
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$. 3734 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$.
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. 3735 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.
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 3736 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
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}\}$. 3737 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}\}$.
3351 3738
3739 \LMHash{}
3352 If getter lookup has also failed, then a new instance $im$ of the predefined c lass \code{Invocation} is created, such that : 3740 If getter lookup has also failed, then a new instance $im$ of the predefined c lass \code{Invocation} is created, such that :
3353 \begin{itemize} 3741 \begin{itemize}
3354 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 3742 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
3355 \item \code{im.memberName} evaluates to \code{'m'}. 3743 \item \code{im.memberName} evaluates to \code{'m'}.
3356 \item \code{im.positionalArguments} evaluates to an immutable list with the same values as \code{[$o_1, \ldots, o_n$]}. 3744 \item \code{im.positionalArguments} evaluates to an immutable list with the same values as \code{[$o_1, \ldots, o_n$]}.
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}$\}}. 3745 \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}$\}}.
3358 \end{itemize} 3746 \end{itemize}
3359 3747
3748 \LMHash{}
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 : 3749 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 :
3361 \begin{itemize} 3750 \begin{itemize}
3362 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 3751 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
3363 \item \code{im.memberName} evaluates to \code{noSuchMethod'}. 3752 \item \code{im.memberName} evaluates to \code{noSuchMethod'}.
3364 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$. 3753 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$.
3365 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 3754 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3366 \end{itemize} 3755 \end{itemize}
3367 3756
3368 and the result of the latter invocation is the result of evaluating $i$. 3757 and the result of the latter invocation is the result of evaluating $i$.
3369 3758
3370 \rationale { 3759 \rationale {
3371 It is possible to bring about such a situation by overriding \code{noSuchMethod( )} with the wrong number of arguments:} 3760 It is possible to bring about such a situation by overriding \code{noSuchMethod( )} with the wrong number of arguments:}
3372 3761
3373 \begin{code} 3762 \begin{code}
3374 \CLASS{} Perverse \{ 3763 \CLASS{} Perverse \{
3375 noSuchMethod(x,y) =$>$ x + y; 3764 noSuchMethod(x,y) =$>$ x + y;
3376 \} 3765 \}
3377 3766
3378 \NEW{} Perverse.unknownMethod(); 3767 \NEW{} Perverse.unknownMethod();
3379 \end{code} 3768 \end{code}
3380 3769
3381 \commentary{Notice that the wording carefully avoids re-evaluating the receiver $o$ and the arguments $a_i$. } 3770 \commentary{Notice that the wording carefully avoids re-evaluating the receiver $o$ and the arguments $a_i$. }
3382 3771
3772 \LMHash{}
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: 3773 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:
3384 \begin{itemize} 3774 \begin{itemize}
3385 \item 3775 \item
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 3776 $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
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$. 3777 \item $T$ is \code{Type}, $e$ is a constant type literal and the class correspo nding to $e$ has a static getter named $m$.
3388 \end{itemize} 3778 \end{itemize}
3389 3779
3780 \LMHash{}
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$. 3781 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$.
3391 3782
3783 \LMHash{}
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 `.'. 3784 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 `.'.
3393 3785
3394 3786
3395 \subsubsection{Cascaded Invocations} 3787 \subsubsection{Cascaded Invocations}
3396 \label{cascadedInvocations} 3788 \LMLabel{cascadedInvocations}
3397 3789
3790 \LMHash{}
3398 A {\em cascaded method invocation} has the form {\em e..suffix} 3791 A {\em cascaded method invocation} has the form {\em e..suffix}
3399 where $e$ is an expression and {\em suffix} is a sequence of operator, method, g etter or setter invocations. 3792 where $e$ is an expression and {\em suffix} is a sequence of operator, method, g etter or setter invocations.
3400 3793
3401 \begin{grammar} 3794 \begin{grammar}
3402 {\bf cascadeSection:} 3795 {\bf cascadeSection:}
3403 `{\escapegrammar ..}' (cascadeSelector arguments*) (assignableSelector arg uments*)* (assignmentOperator expressionWithoutCascade)? 3796 `{\escapegrammar ..}' (cascadeSelector arguments*) (assignableSelector arg uments*)* (assignmentOperator expressionWithoutCascade)?
3404 . 3797 .
3405 3798
3406 {\bf cascadeSelector:}`[' expression `]'; 3799 {\bf cascadeSelector:}`[' expression `]';
3407 identifier 3800 identifier
3408 . 3801 .
3409 \end{grammar} 3802 \end{grammar}
3410 3803
3804 \LMHash{}
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$)}. 3805 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$)}.
3412 3806
3413 \subsubsection{Super Invocation} 3807 \subsubsection{Super Invocation}
3414 \label{superInvocation} 3808 \LMLabel{superInvocation}
3415 3809
3810 \LMHash{}
3416 A super method invocation $i$ has the form 3811 A super method invocation $i$ has the form
3417 3812
3418 $\SUPER{}.m(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. 3813 $\SUPER{}.m(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$.
3419 3814
3815 \LMHash{}
3420 Evaluation of $i$ proceeds as follows: 3816 Evaluation of $i$ proceeds as follows:
3421 3817
3818 \LMHash{}
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$. 3819 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$.
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$. 3820 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$.
3424 3821
3822 \LMHash{}
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. 3823 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.
3426 3824
3825 \LMHash{}
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. 3826 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.
3428 3827
3828 \LMHash{}
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 3829 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
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}\}$. 3830 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}\}$.
3431 3831
3832 \LMHash{}
3432 If getter lookup has also failed, then a new instance $im$ of the predefined c lass \code{Invocation} is created, such that : 3833 If getter lookup has also failed, then a new instance $im$ of the predefined c lass \code{Invocation} is created, such that :
3433 \begin{itemize} 3834 \begin{itemize}
3434 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 3835 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
3435 \item \code{im.memberName} evaluates to \code{'m'}. 3836 \item \code{im.memberName} evaluates to \code{'m'}.
3436 \item \code{im.positionalArguments} evaluates to an immutable list with the same values as \code{[$o_1, \ldots, o_n$]}. 3837 \item \code{im.positionalArguments} evaluates to an immutable list with the same values as \code{[$o_1, \ldots, o_n$]}.
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}$\}}. 3838 \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}$\}}.
3438 \end{itemize} 3839 \end{itemize}
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 : 3840 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 :
3440 \begin{itemize} 3841 \begin{itemize}
3441 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 3842 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
3442 \item \code{im.memberName} evaluates to \code{noSuchMethod}. 3843 \item \code{im.memberName} evaluates to \code{noSuchMethod}.
3443 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$. 3844 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$.
3444 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 3845 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3445 \end{itemize} 3846 \end{itemize}
3446 3847
3447 and the result of this latter invocation is the result of evaluating $i$. 3848 and the result of this latter invocation is the result of evaluating $i$.
3448 3849
3449 3850
3851 \LMHash{}
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. 3852 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.
3451 3853
3854 \LMHash{}
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$. 3855 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$.
3453 % The following is not needed because it is specified in 'Binding Actuals to For mals" 3856 % The following is not needed because it is specified in 'Binding Actuals to For mals"
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$. 3857 %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$.
3455 3858
3456 3859
3457 3860
3458 3861
3459 \subsubsection{Sending Messages} 3862 \subsubsection{Sending Messages}
3863 \LMLabel{sendingMessages}
3460 3864
3461 \label{sendingMessages} 3865 \LMHash{}
3462
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. 3866 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.
3464 3867
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. 3868 \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.
3466 } 3869 }
3467 3870
3468 3871
3469 3872
3470 \subsection{ Property Extraction} 3873 \subsection{ Property Extraction}
3471 \label{propertyExtraction} 3874 \LMLabel{propertyExtraction}
3472 3875
3876 \LMHash{}
3473 {\em Property extraction} allows for a member of an object to be concisely extra cted from the object. 3877 {\em Property extraction} allows for a member of an object to be concisely extra cted from the object.
3474 A property extraction can be either: 3878 A property extraction can be either:
3475 \begin{enumerate} 3879 \begin{enumerate}
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 3880 \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
3477 \item A {\em getter invocation} which returns the result of invoking of a getter method. 3881 \item A {\em getter invocation} which returns the result of invoking of a getter method.
3478 \end{enumerate} 3882 \end{enumerate}
3479 3883
3884 \LMHash{}
3480 Evaluation of a property extraction $i$ of the form $e.m$ proceeds as follows: 3885 Evaluation of a property extraction $i$ of the form $e.m$ proceeds as follows:
3481 3886
3887 \LMHash{}
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$. 3888 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$.
3483 3889
3890 \LMHash{}
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. 3891 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.
3485 3892
3893 \LMHash{}
3486 If the getter lookup has failed, then a new instance $im$ of the predefined cla ss \code{Invocation} is created, such that : 3894 If the getter lookup has failed, then a new instance $im$ of the predefined cla ss \code{Invocation} is created, such that :
3487 \begin{itemize} 3895 \begin{itemize}
3488 \item \code{im.isGetter} evaluates to \code{\TRUE{}}. 3896 \item \code{im.isGetter} evaluates to \code{\TRUE{}}.
3489 \item \code{im.memberName} evaluates to \code{'m'}. 3897 \item \code{im.memberName} evaluates to \code{'m'}.
3490 \item \code{im.positionalArguments} evaluates to the value of \code{\CONST{} []} . 3898 \item \code{im.positionalArguments} evaluates to the value of \code{\CONST{} []} .
3491 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 3899 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3492 \end{itemize} 3900 \end{itemize}
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 : 3901 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 :
3494 \begin{itemize} 3902 \begin{itemize}
3495 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 3903 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
3496 \item \code{im.memberName} evaluates to \code{noSuchMethod}. 3904 \item \code{im.memberName} evaluates to \code{noSuchMethod}.
3497 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$. 3905 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$.
3498 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 3906 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3499 \end{itemize} 3907 \end{itemize}
3500 3908
3501 and the result of this latter invocation is the result of evaluating $i$. 3909 and the result of this latter invocation is the result of evaluating $i$.
3502 3910
3911 \LMHash{}
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. 3912 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.
3504 3913
3505 \commentary { 3914 \commentary {
3506 This precludes \code{int.toString} but not \code{(int).toString} because in the latter case, $e$ is a parenthesized expression. 3915 This precludes \code{int.toString} but not \code{(int).toString} because in the latter case, $e$ is a parenthesized expression.
3507 } 3916 }
3508 3917
3918 \LMHash{}
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: 3919 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:
3510 \begin{itemize} 3920 \begin{itemize}
3511 \item 3921 \item
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 3922 $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
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$. 3923 \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$.
3514 \end{itemize} 3924 \end{itemize}
3515 3925
3926 \LMHash{}
3516 If $i$ is a getter invocation, the static type of $i$ is: 3927 If $i$ is a getter invocation, the static type of $i$ is:
3517 \begin{itemize} 3928 \begin{itemize}
3518 \item The declared return type of $T.m$, if $T.m$ exists. 3929 \item The declared return type of $T.m$, if $T.m$ exists.
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$. 3930 \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$.
3520 \item The type \DYNAMIC{} otherwise. 3931 \item The type \DYNAMIC{} otherwise.
3521 \end{itemize} 3932 \end{itemize}
3522 3933
3934 \LMHash{}
3523 If $i$ is a closurization, its static type is as described in section \ref{closu rization}. 3935 If $i$ is a closurization, its static type is as described in section \ref{closu rization}.
3524 3936
3937 \LMHash{}
3525 Evaluation of a property extraction $i$ of the form $\SUPER.m$ proceeds as follo ws: 3938 Evaluation of a property extraction $i$ of the form $\SUPER.m$ proceeds as follo ws:
3526 3939
3940 \LMHash{}
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}). 3941 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}).
3528 3942
3943 \LMHash{}
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. 3944 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.
3530 3945
3946 \LMHash{}
3531 If the getter lookup has failed, then a new instance $im$ of the predefined cla ss \code{Invocation} is created, such that : 3947 If the getter lookup has failed, then a new instance $im$ of the predefined cla ss \code{Invocation} is created, such that :
3532 \begin{itemize} 3948 \begin{itemize}
3533 \item \code{im.isGetter} evaluates to \code{\TRUE{}}. 3949 \item \code{im.isGetter} evaluates to \code{\TRUE{}}.
3534 \item \code{im.memberName} evaluates to \code{'m'}. 3950 \item \code{im.memberName} evaluates to \code{'m'}.
3535 \item \code{im.positionalArguments} evaluates to the value of \code{\CONST{} []} . 3951 \item \code{im.positionalArguments} evaluates to the value of \code{\CONST{} []} .
3536 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 3952 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3537 \end{itemize} 3953 \end{itemize}
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 : 3954 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 :
3539 \begin{itemize} 3955 \begin{itemize}
3540 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 3956 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
3541 \item \code{im.memberName} evaluates to \code{noSuchMethod}. 3957 \item \code{im.memberName} evaluates to \code{noSuchMethod}.
3542 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$. 3958 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$.
3543 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 3959 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3544 \end{itemize} 3960 \end{itemize}
3545 3961
3546 and the result of this latter invocation is the result of evaluating $i$. 3962 and the result of this latter invocation is the result of evaluating $i$.
3547 3963
3964 \LMHash{}
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}. 3965 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}.
3549 3966
3550 3967
3551 \subsubsection{Closurization} 3968 \subsubsection{Closurization}
3552 \label{closurization} 3969 \LMLabel{closurization}
3553 3970
3971 \LMHash{}
3554 The {\em closurization of $o.m$} is defined to be equivalent to: 3972 The {\em closurization of $o.m$} is defined to be equivalent to:
3555 3973
3556 \begin{itemize} 3974 \begin{itemize}
3557 3975
3558 \item 3976 \item
3559 \begin{dartCode} 3977 \begin{dartCode}
3560 $(r_1, \ldots, r_n, \{p_1 : d_1, \ldots , p_k : d_k\})$ \{ 3978 $(r_1, \ldots, r_n, \{p_1 : d_1, \ldots , p_k : d_k\})$ \{
3561 \RETURN{} $ u.m(r_1, \ldots, r_n, p_1: p_1, \ldots, p_k: p_k);$ 3979 \RETURN{} $ u.m(r_1, \ldots, r_n, p_1: p_1, \ldots, p_k: p_k);$
3562 \} 3980 \}
3563 \end{dartCode} 3981 \end{dartCode}
(...skipping 29 matching lines...) Expand all
3593 4011
3594 \commentary{Observations: 4012 \commentary{Observations:
3595 \begin{enumerate} 4013 \begin{enumerate}
3596 \item One cannot closurize a getter or a setter. 4014 \item One cannot closurize a getter or a setter.
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. 4015 \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.
3598 \end{enumerate} 4016 \end{enumerate}
3599 } 4017 }
3600 4018
3601 4019
3602 4020
4021 \LMHash{}
3603 The closurization of $\SUPER{}.m$ with respect to superclass $S$ is defined to b e equivalent to: 4022 The closurization of $\SUPER{}.m$ with respect to superclass $S$ is defined to b e equivalent to:
3604 4023
3605 \begin{itemize} 4024 \begin{itemize}
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$. 4025 %\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$.
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$. 4026 %\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$.
3608 %\item 4027 %\item
3609 \item 4028 \item
3610 \begin{dartCode} 4029 \begin{dartCode}
3611 $(r_1, \ldots, r_n, \{p_1 : d_1, \ldots , p_k : d_k\})$\{ 4030 $(r_1, \ldots, r_n, \{p_1 : d_1, \ldots , p_k : d_k\})$\{
3612 \RETURN{} \SUPER{}$.m(r_1, \ldots, r_n, p_1: p_1, \ldots, p_k: p_k)$; 4031 \RETURN{} \SUPER{}$.m(r_1, \ldots, r_n, p_1: p_1, \ldots, p_k: p_k)$;
3613 \} 4032 \}
3614 \end{dartCode} 4033 \end{dartCode}
3615 4034
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$. 4035 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$.
3617 \item 4036 \item
3618 \begin{dartCode} 4037 \begin{dartCode}
3619 $(r_1, \ldots, r_n, [p_1 = d_1, \ldots , p_k = d_k])$\{ 4038 $(r_1, \ldots, r_n, [p_1 = d_1, \ldots , p_k = d_k])$\{
3620 \RETURN{} \SUPER{}$.m(r_1, \ldots, r_n, p_1, \ldots, p_k)$; 4039 \RETURN{} \SUPER{}$.m(r_1, \ldots, r_n, p_1, \ldots, p_k)$;
3621 \} 4040 \}
3622 \end{dartCode} 4041 \end{dartCode}
3623 4042
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$. 4043 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$.
3625 \end{itemize} 4044 \end{itemize}
3626 4045
4046 \LMHash{}
3627 Except that: 4047 Except that:
3628 \begin{enumerate} 4048 \begin{enumerate}
3629 \item iff \code{identical($o_1, o_2$)} then \cd{$o_1.m$ == $o_2.m$}. 4049 \item iff \code{identical($o_1, o_2$)} then \cd{$o_1.m$ == $o_2.m$}.
3630 \item 4050 \item
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{} . 4051 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{} .
3632 \end{enumerate} 4052 \end{enumerate}
3633 4053
3634 4054
3635 \subsection{ Assignment} 4055 \subsection{ Assignment}
3636 \label{assignment} 4056 \LMLabel{assignment}
3637 4057
4058 \LMHash{}
3638 An assignment changes the value associated with a mutable variable or property. 4059 An assignment changes the value associated with a mutable variable or property.
3639 4060
3640 \begin{grammar} 4061 \begin{grammar}
3641 {\bf assignmentOperator:}`=' ; 4062 {\bf assignmentOperator:}`=' ;
3642 compoundAssignmentOperator 4063 compoundAssignmentOperator
3643 . 4064 .
3644 \end{grammar} 4065 \end{grammar}
3645 4066
4067 \LMHash{}
3646 Evaluation of an assignment $a$ of the form $v$ \code{=} $e$ proceeds as follows : 4068 Evaluation of an assignment $a$ of the form $v$ \code{=} $e$ proceeds as follows :
3647 4069
3648 4070
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: 4071 %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:
3650 %\begin{itemize} 4072 %\begin{itemize}
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. 4073 % \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.
3652 % \item Otherwise, the assignment is equivalent to the assignment \code{ \THIS{} .$v$ = $e$}. 4074 % \item Otherwise, the assignment is equivalent to the assignment \code{ \THIS{} .$v$ = $e$}.
3653 % \end{itemize} 4075 % \end{itemize}
3654 4076
3655 %Otherwise, 4077 %Otherwise,
3656 4078
4079 \LMHash{}
3657 Let $d$ be the innermost declaration whose name is $v$ or $v=$, if it exists. 4080 Let $d$ be the innermost declaration whose name is $v$ or $v=$, if it exists.
3658 4081
4082 \LMHash{}
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. 4083 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.
3660 If no error occurs, the value of the assignment expression is $o$. 4084 If no error occurs, the value of the assignment expression is $o$.
3661 4085
4086 \LMHash{}
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$. 4087 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$.
3663 4088
4089 \LMHash{}
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$}. 4090 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$}.
3665 4091
4092 \LMHash{}
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. 4093 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.
3667 4094
4095 \LMHash{}
3668 Otherwise, the assignment is equivalent to the assignment \code{ \THIS{}.$v$ = $ e$}. 4096 Otherwise, the assignment is equivalent to the assignment \code{ \THIS{}.$v$ = $ e$}.
3669 4097
4098 \LMHash{}
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$. 4099 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$.
3671 4100
4101 \LMHash{}
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$. 4102 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$.
3673 4103
4104 \LMHash{}
3674 Evaluation of an assignment of the form $e_1.v$ \code{=} $e_2$ proceeds as follo ws: 4105 Evaluation of an assignment of the form $e_1.v$ \code{=} $e_2$ proceeds as follo ws:
3675 4106
4107 \LMHash{}
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$. 4108 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$.
3677 4109
4110 \LMHash{}
3678 If the setter lookup has failed, then a new instance $im$ of the predefined cla ss \code{Invocation} is created, such that : 4111 If the setter lookup has failed, then a new instance $im$ of the predefined cla ss \code{Invocation} is created, such that :
3679 \begin{itemize} 4112 \begin{itemize}
3680 \item \code{im.isSetter} evaluates to \code{\TRUE{}}. 4113 \item \code{im.isSetter} evaluates to \code{\TRUE{}}.
3681 \item \code{im.memberName} evaluates to \code{'v='}. 4114 \item \code{im.memberName} evaluates to \code{'v='}.
3682 \item \code{im.positionalArguments} evaluates to an immutable list with the same values as \code{[$o_2$]}. 4115 \item \code{im.positionalArguments} evaluates to an immutable list with the same values as \code{[$o_2$]}.
3683 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 4116 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3684 \end{itemize} 4117 \end{itemize}
3685 4118
4119 \LMHash{}
3686 Then the method \code{noSuchMethod()} is looked up in $o_1$ and invoked with ar gument $im$. 4120 Then the method \code{noSuchMethod()} is looked up in $o_1$ and invoked with ar gument $im$.
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 : 4121 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 :
3688 \begin{itemize} 4122 \begin{itemize}
3689 \item \code{im.isMethod} evaluates to \code{\TRUE{}}. 4123 \item \code{im.isMethod} evaluates to \code{\TRUE{}}.
3690 \item \code{im.memberName} evaluates to \code{noSuchMethod}. 4124 \item \code{im.memberName} evaluates to \code{noSuchMethod}.
3691 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$. 4125 \item \code{im.positionalArguments} evaluates to an immutable list whose sole el ement is $im$.
3692 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. 4126 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}.
3693 \end{itemize} 4127 \end{itemize}
3694 4128
4129 \LMHash{}
3695 The value of the assignment expression is $o_2$ irrespective of whether setter l ookup has failed or succeeded. 4130 The value of the assignment expression is $o_2$ irrespective of whether setter l ookup has failed or succeeded.
3696 4131
4132 \LMHash{}
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$. 4133 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$.
3698 4134
4135 \LMHash{}
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: 4136 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:
3700 \begin{itemize} 4137 \begin{itemize}
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 4138 \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
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=$. 4139 \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=$.
3703 \end{itemize} 4140 \end{itemize}
3704 4141
3705 4142
3706 4143
4144 \LMHash{}
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$. 4145 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$.
3708 4146
4147 \LMHash{}
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$. 4148 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$.
3710 4149
3711 % Should we add: It is a dynamic error if $e_1$ evaluates to an constant list o r map. 4150 % Should we add: It is a dynamic error if $e_1$ evaluates to an constant list o r map.
3712 4151
4152 \LMHash{}
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. 4153 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.
3714 4154
4155 \LMHash{}
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 `.'. 4156 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 `.'.
3716 4157
3717 4158
3718 4159
3719 \subsubsection{Compound Assignment} 4160 \subsubsection{Compound Assignment}
3720 \label{compoundAssignment} 4161 \LMLabel{compoundAssignment}
3721 4162
4163 \LMHash{}
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 4164 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
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$. 4165 \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$.
3724 4166
3725 4167
3726 \begin{grammar} 4168 \begin{grammar}
3727 {\bf compoundAssignmentOperator:}`*='; 4169 {\bf compoundAssignmentOperator:}`*=';
3728 `/='; 4170 `/=';
3729 `\~{}/='; 4171 `\~{}/=';
3730 `\%='; 4172 `\%=';
3731 `+='; 4173 `+=';
3732 `-='; 4174 `-=';
3733 `{\escapegrammar \lt \lt}='; 4175 `{\escapegrammar \lt \lt}=';
3734 `{\escapegrammar \gt \gt}='; 4176 `{\escapegrammar \gt \gt}=';
3735 `\&='; 4177 `\&=';
3736 `\^{}='; 4178 `\^{}=';
3737 `$|$=' 4179 `$|$='
3738 . 4180 .
3739 \end{grammar} 4181 \end{grammar}
3740 4182
3741 4183
3742 \subsection{ Conditional} 4184 \subsection{ Conditional}
3743 \label{conditional} 4185 \LMLabel{conditional}
3744 4186
4187 \LMHash{}
3745 A {\em conditional expression} evaluates one of two expressions based on a boole an condition. 4188 A {\em conditional expression} evaluates one of two expressions based on a boole an condition.
3746 4189
3747 \begin{grammar} 4190 \begin{grammar}
3748 {\bf conditionalExpression:} 4191 {\bf conditionalExpression:}
3749 logicalOrExpression (`?' expressionWithoutCascade `{\escapegrammar :}' expr essionWithoutCascade)? 4192 logicalOrExpression (`?' expressionWithoutCascade `{\escapegrammar :}' expr essionWithoutCascade)?
3750 . % the first branches could top level expressions, it seems, but certainl y NOT the second 4193 . % the first branches could top level expressions, it seems, but certainl y NOT the second
3751 \end{grammar} 4194 \end{grammar}
3752 4195
4196 \LMHash{}
3753 Evaluation of a conditional expression $c$ of the form $e_1 ? e_2 : e_3$ proceed s as follows: 4197 Evaluation of a conditional expression $c$ of the form $e_1 ? e_2 : e_3$ proceed s as follows:
3754 4198
4199 \LMHash{}
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$. 4200 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$.
3756 4201
4202 \LMHash{}
3757 If all of the following hold: 4203 If all of the following hold:
3758 \begin{itemize} 4204 \begin{itemize}
3759 \item $e_1$ shows that a variable $v$ has type $T$. 4205 \item $e_1$ shows that a variable $v$ has type $T$.
3760 \item $v$ is not potentially mutated in $e_2$ or within a closure. 4206 \item $v$ is not potentially mutated in $e_2$ or within a closure.
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$. 4207 \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$.
3762 \end{itemize} 4208 \end{itemize}
3763 4209
3764 then the type of $v$ is known to be $T$ in $e_2$. 4210 then the type of $v$ is known to be $T$ in $e_2$.
3765 4211
3766 4212
4213 \LMHash{}
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$. 4214 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$.
3768 4215
3769 4216
3770 \subsection{ Logical Boolean Expressions} 4217 \subsection{ Logical Boolean Expressions}
3771 \label{logicalBooleanExpressions} 4218 \LMLabel{logicalBooleanExpressions}
3772 4219
4220 \LMHash{}
3773 The logical boolean expressions combine boolean objects using the boolean conjun ction and disjunction operators. 4221 The logical boolean expressions combine boolean objects using the boolean conjun ction and disjunction operators.
3774 4222
3775 \begin{grammar} 4223 \begin{grammar}
3776 {\bf logicalOrExpression:} 4224 {\bf logicalOrExpression:}
3777 logicalAndExpression (`$||$' logicalAndExpression)* 4225 logicalAndExpression (`$||$' logicalAndExpression)*
3778 . 4226 .
3779 4227
3780 4228
3781 {\bf logicalAndExpression:} 4229 {\bf logicalAndExpression:}
3782 equalityExpression (`\&\&' equalityExpression)* 4230 equalityExpression (`\&\&' equalityExpression)*
3783 % bitwiseOrExpression (`\&\&' bitwiseOrExpression)* 4231 % bitwiseOrExpression (`\&\&' bitwiseOrExpression)*
3784 . 4232 .
3785 \end{grammar} 4233 \end{grammar}
3786 4234
4235 \LMHash{}
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$. 4236 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$.
3788 4237
4238 \LMHash{}
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$. 4239 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$.
3790 4240
4241 \LMHash{}
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$. 4242 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$.
3792 4243
4244 \LMHash{}
3793 A logical boolean expression $b$ of the form $e_1 \&\& e_2$ shows that a variabl e $v$ has type 4245 A logical boolean expression $b$ of the form $e_1 \&\& e_2$ shows that a variabl e $v$ has type
3794 $T$ if all of the following conditions hold: 4246 $T$ if all of the following conditions hold:
3795 \begin{itemize} 4247 \begin{itemize}
3796 \item Either $e_1$ shows that $v$ has type $T$ or $e_2$ shows that $v$ has type $T$. 4248 \item Either $e_1$ shows that $v$ has type $T$ or $e_2$ shows that $v$ has type $T$.
3797 \item $v$ is a local variable or formal parameter. 4249 \item $v$ is a local variable or formal parameter.
3798 \item The variable $v$ is not mutated in $e_2$ or within a closure. 4250 \item The variable $v$ is not mutated in $e_2$ or within a closure.
3799 \end{itemize} 4251 \end{itemize}
3800 4252
4253 \LMHash{}
3801 Furthermore, if all of the following hold: 4254 Furthermore, if all of the following hold:
3802 \begin{itemize} 4255 \begin{itemize}
3803 \item $e_1$ shows that $v$ has type $T$. 4256 \item $e_1$ shows that $v$ has type $T$.
3804 \item $v$ is not mutated in either $e_1$, $e_2$ or within a closure. 4257 \item $v$ is not mutated in either $e_1$, $e_2$ or within a closure.
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$. 4258 \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$.
3806 \end{itemize} 4259 \end{itemize}
3807 then the type of $v$ is known to be $T$ in $e_2$. 4260 then the type of $v$ is known to be $T$ in $e_2$.
3808 4261
4262 \LMHash{}
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}. 4263 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}.
3810 4264
3811 4265
3812 \subsection{ Equality} 4266 \subsection{ Equality}
3813 \label{equality} 4267 \LMLabel{equality}
3814 4268
4269 \LMHash{}
3815 Equality expressions test objects for equality. 4270 Equality expressions test objects for equality.
3816 4271
3817 \begin{grammar} 4272 \begin{grammar}
3818 {\bf equalityExpression:}relationalExpression (equalityOperator relationalExpres sion)?; 4273 {\bf equalityExpression:}relationalExpression (equalityOperator relationalExpres sion)?;
3819 \SUPER{} equalityOperator relationalExpression 4274 \SUPER{} equalityOperator relationalExpression
3820 . 4275 .
3821 4276
3822 {\bf equalityOperator:}`=='; 4277 {\bf equalityOperator:}`==';
3823 `!=' 4278 `!='
3824 . 4279 .
3825 \end{grammar} 4280 \end{grammar}
3826 4281
4282 \LMHash{}
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$. 4283 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$.
3828 4284
3829 4285
4286 \LMHash{}
3830 Evaluation of an equality expression $ee$ of the form \code{$e_1$ == $e_2$} proc eeds as follows: 4287 Evaluation of an equality expression $ee$ of the form \code{$e_1$ == $e_2$} proc eeds as follows:
3831 \begin{itemize} 4288 \begin{itemize}
3832 \item The expression $e_1$ is evaluated to an object $o_1$. 4289 \item The expression $e_1$ is evaluated to an object $o_1$.
3833 \item The expression $e_2$ is evaluated to an object $o_2$. 4290 \item The expression $e_2$ is evaluated to an object $o_2$.
3834 \item If either $o_1$ or $o_2$ is \NULL{}, then $ee$ evaluates to \code{identica l($o_1$, $o_2$)}. Otherwise, 4291 \item If either $o_1$ or $o_2$ is \NULL{}, then $ee$ evaluates to \code{identica l($o_1$, $o_2$)}. Otherwise,
3835 \item $ee$ is equivalent to the method invocation \code{$o_1$.==($o_2$)}. 4292 \item $ee$ is equivalent to the method invocation \code{$o_1$.==($o_2$)}.
3836 \end{itemize} 4293 \end{itemize}
3837 4294
3838 4295
4296 \LMHash{}
3839 Evaluation of an equality expression $ee$ of the form \code{\SUPER{} == $e$} pro ceeds as follows: 4297 Evaluation of an equality expression $ee$ of the form \code{\SUPER{} == $e$} pro ceeds as follows:
3840 \begin{itemize} 4298 \begin{itemize}
3841 \item The expression $e$ is evaluated to an object $o$. 4299 \item The expression $e$ is evaluated to an object $o$.
3842 \item If either \THIS{} or $o$ is \NULL{}, then $ee$ evaluates to \code{identica l(\THIS{}, $o$)}. Otherwise, 4300 \item If either \THIS{} or $o$ is \NULL{}, then $ee$ evaluates to \code{identica l(\THIS{}, $o$)}. Otherwise,
3843 \item $ee$ is equivalent to the method invocation \code{\SUPER{}.==($o$)}. 4301 \item $ee$ is equivalent to the method invocation \code{\SUPER{}.==($o$)}.
3844 \end{itemize} 4302 \end{itemize}
3845 4303
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: 4304 \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:
3847 4305
3848 \code{if (identical(\NULL{}, arg)) return \FALSE{};} 4306 \code{if (identical(\NULL{}, arg)) return \FALSE{};}
3849 4307
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{}. 4308 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{}.
3851 } 4309 }
3852 4310
4311 \LMHash{}
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$)}. 4312 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$)}.
3854 4313
3855 4314
3856 4315
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{}. 4316 %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{}.
3858 4317
3859 4318
4319 \LMHash{}
3860 The static type of an equality expression is \code{bool}. 4320 The static type of an equality expression is \code{bool}.
3861 4321
3862 4322
3863 \subsection{ Relational Expressions} 4323 \subsection{ Relational Expressions}
3864 \label{relationalExpressions} 4324 \LMLabel{relationalExpressions}
3865 4325
4326 \LMHash{}
3866 Relational expressions invoke the relational operators on objects. 4327 Relational expressions invoke the relational operators on objects.
3867 4328
3868 \begin{grammar} 4329 \begin{grammar}
3869 {\bf relationalExpression:}bitwiseOrExpression (typeTest $|$ typeCast $|$ relat ionalOperator bitwiseOrExpression)?; 4330 {\bf relationalExpression:}bitwiseOrExpression (typeTest $|$ typeCast $|$ relat ionalOperator bitwiseOrExpression)?;
3870 \SUPER{} relationalOperator bitwiseOrExpression 4331 \SUPER{} relationalOperator bitwiseOrExpression
3871 . 4332 .
3872 4333
3873 4334
3874 {\bf relationalOperator:}`{\escapegrammar \gt=}'; 4335 {\bf relationalOperator:}`{\escapegrammar \gt=}';
3875 `{\escapegrammar \gt}'; 4336 `{\escapegrammar \gt}';
3876 `{\escapegrammar \lt}='; 4337 `{\escapegrammar \lt}=';
3877 `{\escapegrammar \lt}' 4338 `{\escapegrammar \lt}'
3878 . 4339 .
3879 \end{grammar} 4340 \end{grammar}
3880 4341
4342 \LMHash{}
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$. 4343 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$.
3882 4344
4345 \LMHash{}
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$ )}. 4346 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$ )}.
3884 4347
3885 \subsection{ Bitwise Expressions} 4348 \subsection{ Bitwise Expressions}
3886 \label{bitwiseExpressions} 4349 \LMLabel{bitwiseExpressions}
3887 4350
4351 \LMHash{}
3888 Bitwise expressions invoke the bitwise operators on objects. 4352 Bitwise expressions invoke the bitwise operators on objects.
3889 4353
3890 \begin{grammar} 4354 \begin{grammar}
3891 {\bf bitwiseOrExpression:}bitwiseXorExpression (`$|$' bitwiseXorExpression)*; 4355 {\bf bitwiseOrExpression:}bitwiseXorExpression (`$|$' bitwiseXorExpression)*;
3892 \SUPER{} (`$|$' bitwiseXorExpression)+ 4356 \SUPER{} (`$|$' bitwiseXorExpression)+
3893 . 4357 .
3894 4358
3895 {\bf bitwiseXorExpression:}bitwiseAndExpression (`\^{}' bitwiseAndExpression)*; 4359 {\bf bitwiseXorExpression:}bitwiseAndExpression (`\^{}' bitwiseAndExpression)*;
3896 \SUPER{} (`\^{}' bitwiseAndExpression)+ 4360 \SUPER{} (`\^{}' bitwiseAndExpression)+
3897 . 4361 .
3898 4362
3899 {\bf bitwiseAndExpression:}shiftExpression (`\&' shiftExpression)*; 4363 {\bf bitwiseAndExpression:}shiftExpression (`\&' shiftExpression)*;
3900 \SUPER{} (`\&' shiftExpression)+ 4364 \SUPER{} (`\&' shiftExpression)+
3901 . 4365 .
3902 4366
3903 {\bf bitwiseOperator:}`\&'; 4367 {\bf bitwiseOperator:}`\&';
3904 `\^{}'; 4368 `\^{}';
3905 `$|$' 4369 `$|$'
3906 . 4370 .
3907 \end{grammar} 4371 \end{grammar}
3908 4372
4373 \LMHash{}
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$. 4374 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$.
3910 4375
4376 \LMHash{}
3911 A bitwise expression of the form $e_1$ $op$ $e_2$ is equivalent to the method invocation $e_1.op(e_2)$. 4377 A bitwise expression of the form $e_1$ $op$ $e_2$ is equivalent to the method invocation $e_1.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$)}. 4378 A bitwise expression of the form \code{\SUPER{} $op$ $e_2$} is equivalent to th e method invocation \code{\SUPER{}.op($e_2$)}.
3913 4379
3914 \commentary{ 4380 \commentary{
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. 4381 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.
3916 } 4382 }
3917 4383
3918 4384
3919 \subsection{ Shift} 4385 \subsection{ Shift}
3920 \label{shift} 4386 \LMLabel{shift}
3921 4387
4388 \LMHash{}
3922 Shift expressions invoke the shift operators on objects. 4389 Shift expressions invoke the shift operators on objects.
3923 4390
3924 \begin{grammar} 4391 \begin{grammar}
3925 {\bf shiftExpression:}additiveExpression (shiftOperator additiveExpression)*; 4392 {\bf shiftExpression:}additiveExpression (shiftOperator additiveExpression)*;
3926 \SUPER{} (shiftOperator additiveExpression)+ 4393 \SUPER{} (shiftOperator additiveExpression)+
3927 . 4394 .
3928 4395
3929 {\bf shiftOperator:}`{\escapegrammar \lt\lt'}; 4396 {\bf shiftOperator:}`{\escapegrammar \lt\lt'};
3930 `{\escapegrammar \gt \gt}' 4397 `{\escapegrammar \gt \gt}'
3931 . 4398 .
3932 \end{grammar} 4399 \end{grammar}
3933 4400
4401 \LMHash{}
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$. 4402 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$.
3935 4403
4404 \LMHash{}
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$)}. 4405 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$)}.
3937 4406
3938 \commentary{ 4407 \commentary{
3939 Note that this definition implies left-to-right evaluation order among shift exp ressions: 4408 Note that this definition implies left-to-right evaluation order among shift exp ressions:
3940 4409
3941 $e_1 << e_2 << e_3$ 4410 $e_1 << e_2 << e_3$
3942 4411
3943 is evaluated as $(e_1 << e_2 ).<< (e_3)$ which is equivalent to $(e_1 << e_2) << e_3$. 4412 is evaluated as $(e_1 << e_2 ).<< (e_3)$ which is equivalent to $(e_1 << e_2) << e_3$.
3944 The same holds for additive and multiplicative expressions. 4413 The same holds for additive and multiplicative expressions.
3945 } 4414 }
3946 4415
3947 \subsection{ Additive Expressions} 4416 \subsection{ Additive Expressions}
3948 \label{additiveExpressions} 4417 \LMLabel{additiveExpressions}
3949 4418
4419 \LMHash{}
3950 Additive expressions invoke the addition operators on objects. 4420 Additive expressions invoke the addition operators on objects.
3951 4421
3952 \begin{grammar} 4422 \begin{grammar}
3953 {\bf additiveExpression:}multiplicativeExpression (additiveOperator multiplicati veExpression)*; 4423 {\bf additiveExpression:}multiplicativeExpression (additiveOperator multiplicati veExpression)*;
3954 \SUPER{} (additiveOperator multiplicativeExpression)+ 4424 \SUPER{} (additiveOperator multiplicativeExpression)+
3955 . 4425 .
3956 4426
3957 {\bf additiveOperator:}`+'; 4427 {\bf additiveOperator:}`+';
3958 `-' 4428 `-'
3959 . 4429 .
3960 \end{grammar} 4430 \end{grammar}
3961 4431
4432 \LMHash{}
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$. 4433 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$.
3963 4434
4435 \LMHash{}
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$)} . 4436 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$)} .
3965 4437
4438 \LMHash{}
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}. 4439 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}.
3967 4440
3968 4441
3969 \subsection{ Multiplicative Expressions} 4442 \subsection{ Multiplicative Expressions}
3970 \label{multiplicativeExpressions} 4443 \LMLabel{multiplicativeExpressions}
3971 4444
4445 \LMHash{}
3972 Multiplicative expressions invoke the multiplication operators on objects. 4446 Multiplicative expressions invoke the multiplication operators on objects.
3973 4447
3974 \begin{grammar} 4448 \begin{grammar}
3975 {\bf multiplicativeExpression:}unaryExpression (multiplicativeOperator unaryExpr ession)*; 4449 {\bf multiplicativeExpression:}unaryExpression (multiplicativeOperator unaryExpr ession)*;
3976 \SUPER{} (multiplicativeOperator unaryExpression)+ 4450 \SUPER{} (multiplicativeOperator unaryExpression)+
3977 . 4451 .
3978 4452
3979 {\bf multiplicativeOperator:}`*'; 4453 {\bf multiplicativeOperator:}`*';
3980 `/'; 4454 `/';
3981 `\%'; 4455 `\%';
3982 `\~{}/' 4456 `\~{}/'
3983 . 4457 .
3984 4458
3985 \end{grammar} 4459 \end{grammar}
3986 4460
4461 \LMHash{}
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$. 4462 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$.
3988 4463
4464 \LMHash{}
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$)}. 4465 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$)}.
3990 4466
4467 \LMHash{}
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} . 4468 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} .
3992 4469
3993 \subsection{ Unary Expressions} 4470 \subsection{ Unary Expressions}
3994 \label{unaryExpressions} 4471 \LMLabel{unaryExpressions}
3995 4472
4473 \LMHash{}
3996 Unary expressions invoke unary operators on objects. 4474 Unary expressions invoke unary operators on objects.
3997 4475
3998 \begin{grammar} 4476 \begin{grammar}
3999 {\bf unaryExpression:}prefixOperator unaryExpression; 4477 {\bf unaryExpression:}prefixOperator unaryExpression;
4000 awaitExpression; 4478 awaitExpression;
4001 postfixExpression; 4479 postfixExpression;
4002 (minusOperator $|$ tildeOperator) \SUPER{}; 4480 (minusOperator $|$ tildeOperator) \SUPER{};
4003 incrementOperator assignableExpression 4481 incrementOperator assignableExpression
4004 . 4482 .
4005 4483
4006 {\bf prefixOperator:}minusOperator; 4484 {\bf prefixOperator:}minusOperator;
4007 negationOperator; 4485 negationOperator;
4008 tildeOperator 4486 tildeOperator
4009 . 4487 .
4010 4488
4011 4489
4012 {\bf minusOperator:}`-'; . 4490 {\bf minusOperator:}`-'; .
4013 4491
4014 4492
4015 {\bf negationOperator:}`!' ; 4493 {\bf negationOperator:}`!' ;
4016 . 4494 .
4017 4495
4018 {\bf tildeOperator:} `\~{}' 4496 {\bf tildeOperator:} `\~{}'
4019 . 4497 .
4020 4498
4021 4499
4022 \end{grammar} 4500 \end{grammar}
4023 4501
4502 \LMHash{}
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$. 4503 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$.
4025 4504
4505 \LMHash{}
4026 The expression $!e$ is equivalent to the expression $e?$ $ \FALSE{} :\TRUE{}$. 4506 The expression $!e$ is equivalent to the expression $e?$ $ \FALSE{} :\TRUE{}$.
4027 4507
4508 \LMHash{}
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}. 4509 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}.
4029 4510
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{}.-()}. 4511 %The expression $-e$ is equivalent to the method invocation \code{$e$.-()}. The expression \code{-\SUPER{}} is equivalent to the method invocation \code{\SUPE R{}.-()}.
4031 4512
4513 \LMHash{}
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()$}. 4514 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()$}.
4033 4515
4034 \subsection{ Await Expressions} 4516 \subsection{ Await Expressions}
4035 \label{awaitExpressions} 4517 \LMLabel{awaitExpressions}
4036 4518
4519 \LMHash{}
4037 An {\em await expression} allows code to yield control until an asynchronous ope ration (\ref{functions}) completes. 4520 An {\em await expression} allows code to yield control until an asynchronous ope ration (\ref{functions}) completes.
4038 4521
4039 \begin{grammar} 4522 \begin{grammar}
4040 {\bf awaitExpression:} 4523 {\bf awaitExpression:}
4041 \AWAIT{} unaryExpression 4524 \AWAIT{} unaryExpression
4042 \end{grammar} 4525 \end{grammar}
4043 4526
4527 \LMHash{}
4044 Evaluation of an await expression $a$ of the form \AWAIT{} $e$ proceeds as follo ws: 4528 Evaluation of an await expression $a$ of the form \AWAIT{} $e$ proceeds as follo ws:
4045 First, the expression $e$ is evaluated. Next: 4529 First, the expression $e$ is evaluated. Next:
4046 4530
4531 \LMHash{}
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$. 4532 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$.
4048 4533
4534 \LMHash{}
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$. 4535 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$.
4050 4536
4051 %Otherwise, the value of $a$ is the value of $e$. If evaluation of $e$ raises an exception $x$, $a$ raises $x$. 4537 %Otherwise, the value of $a$ is the value of $e$. If evaluation of $e$ raises an exception $x$, $a$ raises $x$.
4052 4538
4053 \commentary{ 4539 \commentary{
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. 4540 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.
4055 } 4541 }
4056 4542
4057 \rationale{ 4543 \rationale{
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. 4544 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.
4059 } 4545 }
4060 4546
4061 \commentary{ 4547 \commentary{
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. 4548 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.
4063 } 4549 }
4064 4550
4551 \LMHash{}
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$. 4552 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$.
4066 4553
4067 \rationale{ 4554 \rationale{
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}. 4555 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}.
4069 } 4556 }
4070 4557
4071 4558
4072 4559
4073 4560
4074 \subsection{ Postfix Expressions} 4561 \subsection{ Postfix Expressions}
4075 \label{postfixExpressions} 4562 \LMLabel{postfixExpressions}
4076 4563
4564 \LMHash{}
4077 Postfix expressions invoke the postfix operators on objects. 4565 Postfix expressions invoke the postfix operators on objects.
4078 4566
4079 \begin{grammar} 4567 \begin{grammar}
4080 {\bf postfixExpression:}assignableExpression postfixOperator; 4568 {\bf postfixExpression:}assignableExpression postfixOperator;
4081 primary selector* 4569 primary selector*
4082 . 4570 .
4083 4571
4084 {\bf postfixOperator:} 4572 {\bf postfixOperator:}
4085 incrementOperator 4573 incrementOperator
4086 . 4574 .
4087 4575
4088 {\bf selector:}assignableSelector; 4576 {\bf selector:}assignableSelector;
4089 arguments 4577 arguments
4090 . 4578 .
4091 4579
4092 {\bf incrementOperator:}`++'; 4580 {\bf incrementOperator:}`++';
4093 `-{}-' 4581 `-{}-'
4094 . 4582 .
4095 4583
4096 \end{grammar} 4584 \end{grammar}
4097 4585
4586 \LMHash{}
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$ . 4587 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$ .
4099 4588
4589 \LMHash{}
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\}()}. 4590 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\}()}.
4101 4591
4102 \rationale{The above ensures that if $v$ is a field, the getter gets called exac tly once. Likewise in the cases below. 4592 \rationale{The above ensures that if $v$ is a field, the getter gets called exac tly once. Likewise in the cases below.
4103 } 4593 }
4104 4594
4595 \LMHash{}
4105 A postfix expression of the form \code{$C.v$ ++} is equivalent to 4596 A postfix expression of the form \code{$C.v$ ++} is equivalent to
4106 4597
4107 \code{()\{var r = $C.v$; $C.v$ = r + 1; return r\}()}. 4598 \code{()\{var r = $C.v$; $C.v$ = r + 1; return r\}()}.
4108 4599
4600 \LMHash{}
4109 A postfix expression of the form \code{$e_1.v$++} is equivalent to 4601 A postfix expression of the form \code{$e_1.v$++} is equivalent to
4110 4602
4111 \code{(x)\{var r = x.v; x.v = r + 1; \RETURN{} r\}($e_1$)}. 4603 \code{(x)\{var r = x.v; x.v = r + 1; \RETURN{} r\}($e_1$)}.
4112 4604
4605 \LMHash{}
4113 A postfix expression of the form \code{$e_1[e_2]$++}, is equivalent to 4606 A postfix expression of the form \code{$e_1[e_2]$++}, is equivalent to
4114 4607
4115 \code{(a, i)\{var r = a[i]; a[i] = r + 1; return r\}($e_1$, $e_2$)}. 4608 \code{(a, i)\{var r = a[i]; a[i] = r + 1; return r\}($e_1$, $e_2$)}.
4116 4609
4610 \LMHash{}
4117 A postfix expression of the form \code{$v$-{}-}, where $v$ is an identifier, is equivalent to 4611 A postfix expression of the form \code{$v$-{}-}, where $v$ is an identifier, is equivalent to
4118 4612
4119 \code{()\{var r = $v$; $v$ = r - 1; return r\}()}. 4613 \code{()\{var r = $v$; $v$ = r - 1; return r\}()}.
4120 4614
4615 \LMHash{}
4121 A postfix expression of the form \code{$C.v$-{}-} is equivalent to 4616 A postfix expression of the form \code{$C.v$-{}-} is equivalent to
4122 4617
4123 \code{()\{var r = $C.v$; $C.v$ = r - 1; return r\}()}. 4618 \code{()\{var r = $C.v$; $C.v$ = r - 1; return r\}()}.
4124 4619
4620 \LMHash{}
4125 A postfix expression of the form \code{$e_1.v$-{}-} is equivalent to 4621 A postfix expression of the form \code{$e_1.v$-{}-} is equivalent to
4126 4622
4127 \code{(x)\{var r = x.v; x.v = r - 1; \RETURN{} r\}($e_1$)}. 4623 \code{(x)\{var r = x.v; x.v = r - 1; \RETURN{} r\}($e_1$)}.
4128 4624
4625 \LMHash{}
4129 A postfix expression of the form \code{$e_1[e_2]$-{}-}, is equivalent to 4626 A postfix expression of the form \code{$e_1[e_2]$-{}-}, is equivalent to
4130 4627
4131 \code{(a, i)\{var r = a[i]; a[i] = r - 1; return r\}($e_1$, $e_2$)}. 4628 \code{(a, i)\{var r = a[i]; a[i] = r - 1; return r\}($e_1$, $e_2$)}.
4132 4629
4133 4630
4134 \subsection{ Assignable Expressions} 4631 \subsection{ Assignable Expressions}
4135 \label{assignableExpressions} 4632 \LMLabel{assignableExpressions}
4136 4633
4634 \LMHash{}
4137 Assignable expressions are expressions that can appear on the left hand side of an assignment. 4635 Assignable expressions are expressions that can appear on the 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. 4636 This section describes how to evaluate these expressions when they do not consti tute the complete left hand side of an assignment.
4139 4637
4140 \rationale{ 4638 \rationale{
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. 4639 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.
4142 } 4640 }
4143 4641
4144 4642
4145 4643
4146 \begin{grammar} 4644 \begin{grammar}
4147 4645
4148 {\bf assignableExpression:}primary (argument* assignableSelector)+; 4646 {\bf assignableExpression:}primary (argument* assignableSelector)+;
4149 \SUPER{} assignableSelector; 4647 \SUPER{} assignableSelector;
4150 identifier 4648 identifier
4151 . 4649 .
4152 4650
4153 {\bf assignableSelector:}`[' expression `]'; % again, could be top level 4651 {\bf assignableSelector:}`[' expression `]'; % again, could be top level
4154 `{\escapegrammar .}' identifier 4652 `{\escapegrammar .}' identifier
4155 . 4653 .
4156 4654
4157 \end{grammar} 4655 \end{grammar}
4158 4656
4657 \LMHash{}
4159 An {\em assignable expression} is either: 4658 An {\em assignable expression} is either:
4160 \begin{itemize} 4659 \begin{itemize}
4161 \item An identifier. 4660 \item An identifier.
4162 \item An invocation of a getter (\ref{getters}) or list access operator on an ex pression $e$. 4661 \item An invocation of a getter (\ref{getters}) or list access operator on an ex pression $e$.
4163 \item An invocation of a getter or list access operator on \SUPER{}. 4662 \item An invocation of a getter or list access operator on \SUPER{}.
4164 \end{itemize} 4663 \end{itemize}
4165 4664
4166 4665
4666 \LMHash{}
4167 An assignable expression of the form $id$ is evaluated as an identifier expressi on (\ref{identifierReference}). 4667 An assignable expression of the form $id$ is evaluated as an identifier expressi on (\ref{identifierReference}).
4168 4668
4169 %An assignable expression of the form $e.id(a_1, \ldots, a_n)$ is evaluated as a method invocation (\ref{methodInvocation}). 4669 %An assignable expression of the form $e.id(a_1, \ldots, a_n)$ is evaluated as a method invocation (\ref{methodInvocation}).
4170 4670
4671 \LMHash{}
4171 An assignable expression of the form $e.id$ is evaluated as a property extractio n (\ref{propertyExtraction}). 4672 An assignable expression of the form $e.id$ is evaluated as a property extractio n (\ref{propertyExtraction}).
4172 4673
4674 \LMHash{}
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$. 4675 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$.
4174 4676
4677 \LMHash{}
4175 An assignable expression of the form \code{\SUPER{}.id} is evaluated as a prope rty extraction. 4678 An assignable expression of the form \code{\SUPER{}.id} is evaluated as a prope rty extraction.
4176 4679
4680 \LMHash{}
4177 An assignable expression of the form \code{\SUPER{}[$e_2$]} is equivalent to the method invocation \code{\SUPER{}.[]($e_2$)}. 4681 An assignable expression of the form \code{\SUPER{}[$e_2$]} is equivalent to the method invocation \code{\SUPER{}.[]($e_2$)}.
4178 4682
4179 \subsection{ Identifier Reference} 4683 \subsection{ Identifier Reference}
4180 \label{identifierReference} 4684 \LMLabel{identifierReference}
4181 4685
4686 \LMHash{}
4182 An {\em identifier expression} consists of a single identifier; it provides acce ss to an object via an unqualified name. 4687 An {\em identifier expression} consists of a single identifier; it provides acce ss to an object via an unqualified name.
4183 4688
4184 \begin{grammar} 4689 \begin{grammar}
4185 {\bf identifier:} 4690 {\bf identifier:}
4186 IDENTIFIER 4691 IDENTIFIER
4187 . 4692 .
4188 4693
4189 4694
4190 {\bf IDENTIFIER\_NO\_DOLLAR:} 4695 {\bf IDENTIFIER\_NO\_DOLLAR:}
4191 IDENTIFIER\_START\_NO\_DOLLAR IDENTIFIER\_PART\_NO\_DOLLAR* 4696 IDENTIFIER\_START\_NO\_DOLLAR IDENTIFIER\_PART\_NO\_DOLLAR*
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
4230 DIGIT 4735 DIGIT
4231 . 4736 .
4232 4737
4233 4738
4234 4739
4235 {\bf qualified:} 4740 {\bf qualified:}
4236 identifier (`{\escapegrammar .}' identifier)? 4741 identifier (`{\escapegrammar .}' identifier)?
4237 . 4742 .
4238 \end{grammar} 4743 \end{grammar}
4239 4744
4745 \LMHash{}
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. 4746 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.
4241 4747
4242 \rationale{ 4748 \rationale{
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. 4749 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.
4244 } 4750 }
4245 4751
4752 \LMHash{}
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*. 4753 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*.
4247 4754
4248 \rationale{ 4755 \rationale{
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. 4756 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.
4250 } 4757 }
4251 4758
4759 \LMHash{}
4252 Evaluation of an identifier expression $e$ of the form $id$ proceeds as follows: 4760 Evaluation of an identifier expression $e$ of the form $id$ proceeds as follows:
4253 4761
4254 4762
4763 \LMHash{}
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. 4764 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.
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. 4765 %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.
4257 4766
4258 \begin{itemize} 4767 \begin{itemize}
4259 \item if $d$ is a prefix $p$, a compile-time error occurs unless the token immed iately following $d$ is \code{'.'}. 4768 \item if $d$ is a prefix $p$, a compile-time error occurs unless the token immed iately following $d$ is \code{'.'}.
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$. 4769 \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$.
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. 4770 \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.
4262 4771
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}.)} 4772 %\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}.)}
4264 %\item If $d$ is a library variable then: 4773 %\item If $d$ is a library variable then:
4265 % \begin{itemize} 4774 % \begin{itemize}
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$. 4775 % \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$.
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$. 4776 \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$.
4268 % Otherwise 4777 % Otherwise
4269 % \item $e$ evaluates to the current binding of $id$. 4778 % \item $e$ evaluates to the current binding of $id$.
4270 % \end{itemize} 4779 % \end{itemize}
4271 \item If $d$ is a local variable or formal parameter then $e$ evaluates to the c urrent binding of $id$. 4780 \item If $d$ is a local variable or formal parameter then $e$ evaluates to the c urrent binding of $id$.
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.} 4781 %\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.}
4273 \item If $d$ is a static method, top-level function or local function then $e$ e valuates to the function defined by $d$. 4782 \item If $d$ is a static method, top-level function or local function then $e$ e valuates to the function defined by $d$.
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$. 4783 \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$.
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$. 4784 \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$.
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. 4785 \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.
4277 \item Otherwise, $e$ is equivalent to the property extraction (\ref{propertyExtr action}) \THIS{}.$id$. 4786 \item Otherwise, $e$ is equivalent to the property extraction (\ref{propertyExtr action}) \THIS{}.$id$.
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? 4787 % 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?
4279 \end{itemize} 4788 \end{itemize}
4280 4789
4790 \LMHash{}
4281 The static type of $e$ is determined as follows: 4791 The static type of $e$ is determined as follows:
4282 4792
4283 \begin{itemize} 4793 \begin{itemize}
4284 \item If $d$ is a class, type alias or type parameter the static type of $e$ is \code{Type}. 4794 \item If $d$ is a class, type alias or type parameter the static type of $e$ is \code{Type}.
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$. 4795 \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$.
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$. 4796 \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$.
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$. 4797 \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$.
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$. 4798 \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$.
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{}. 4799 \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{}.
4290 \item Otherwise, the static type of $e$ is the type of the property extraction ( \ref{propertyExtraction}) \THIS{}.$id$. 4800 \item Otherwise, the static type of $e$ is the type of the property extraction ( \ref{propertyExtraction}) \THIS{}.$id$.
4291 \end{itemize} 4801 \end{itemize}
4292 4802
4293 \commentary{Note that if one declares a setter, we bind to the corresponding ge tter even if it does not exist.} 4803 \commentary{Note that if one declares a setter, we bind to the corresponding ge tter even if it does not exist.}
4294 4804
4295 \rationale{ 4805 \rationale{
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. 4806 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.
4297 } 4807 }
4298 4808
4809 \LMHash{}
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. 4810 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.
4300 4811
4301 \subsection{ Type Test} 4812 \subsection{ Type Test}
4302 \label{typeTest} 4813 \LMLabel{typeTest}
4303 4814
4815 \LMHash{}
4304 The {\em is-expression} tests if an object is a member of a type. 4816 The {\em is-expression} tests if an object is a member of a type.
4305 4817
4306 \begin{grammar} 4818 \begin{grammar}
4307 {\bf typeTest:} 4819 {\bf typeTest:}
4308 isOperator type 4820 isOperator type
4309 . 4821 .
4310 4822
4311 4823
4312 {\bf isOperator:} 4824 {\bf isOperator:}
4313 \IS{} `!'? 4825 \IS{} `!'?
4314 . 4826 .
4315 \end{grammar} 4827 \end{grammar}
4316 4828
4829 \LMHash{}
4317 Evaluation of the is-expression \code{$e$ \IS{} $T$} proceeds as follows: 4830 Evaluation of the is-expression \code{$e$ \IS{} $T$} proceeds as follows:
4318 4831
4832 \LMHash{}
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. 4833 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.
4320 4834
4321 \commentary{It follows that \code{$e$ \IS{} Object} is always true. This makes s ense in a language where everything is an object. 4835 \commentary{It follows that \code{$e$ \IS{} Object} is always true. This makes s ense in a language where everything is an object.
4322 4836
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. 4837 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.
4324 } 4838 }
4325 4839
4840 \LMHash{}
4326 The is-expression \code{$e$ \IS{}! $T$} is equivalent to \code{!($e$ \IS{} $T$)} . 4841 The is-expression \code{$e$ \IS{}! $T$} is equivalent to \code{!($e$ \IS{} $T$)} .
4327 4842
4328 % Add flow dependent types 4843 % Add flow dependent types
4329 4844
4330 4845
4846 \LMHash{}
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{}$. 4847 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{}$.
4332 4848
4333 \rationale{ 4849 \rationale{
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. 4850 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.
4335 4851
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. 4852 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.
4337 4853
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). 4854 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).
4339 4855
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$. 4856 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$.
4341 } 4857 }
4342 4858
4859 \LMHash{}
4343 The static type of an is-expression is \code{bool}. 4860 The static type of an is-expression is \code{bool}.
4344 4861
4345 4862
4346 \subsection{ Type Cast} 4863 \subsection{ Type Cast}
4347 \label{typeCast} 4864 \LMLabel{typeCast}
4348 4865
4866 \LMHash{}
4349 The {\em cast expression} ensures that an object is a member of a type. 4867 The {\em cast expression} ensures that an object is a member of a type.
4350 4868
4351 \begin{grammar} 4869 \begin{grammar}
4352 {\bf typeCast:} 4870 {\bf typeCast:}
4353 asOperator type 4871 asOperator type
4354 . 4872 .
4355 4873
4356 4874
4357 {\bf asOperator:} 4875 {\bf asOperator:}
4358 \AS{} 4876 \AS{}
4359 . 4877 .
4360 \end{grammar} 4878 \end{grammar}
4361 4879
4880 \LMHash{}
4362 Evaluation of the cast expression \code{$e$ \AS{} $T$} proceeds as follows: 4881 Evaluation of the cast expression \code{$e$ \AS{} $T$} proceeds as follows:
4363 4882
4883 \LMHash{}
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$. 4884 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$.
4365 In all other cases, a \code{CastError} is thrown. 4885 In all other cases, a \code{CastError} is thrown.
4366 4886
4887 \LMHash{}
4367 The static type of a cast expression \code{$e$ \AS{} $T$} is $T$. 4888 The static type of a cast expression \code{$e$ \AS{} $T$} is $T$.
4368 4889
4369 4890
4370 \section{Statements} 4891 \section{Statements}
4371 \label{statements} 4892 \LMLabel{statements}
4372 4893
4373 \begin{grammar} 4894 \begin{grammar}
4374 {\bf statements:} 4895 {\bf statements:}
4375 statement* 4896 statement*
4376 . 4897 .
4377 4898
4378 4899
4379 {\bf statement:} 4900 {\bf statement:}
4380 label* nonLabelledStatement 4901 label* nonLabelledStatement
4381 . 4902 .
(...skipping 12 matching lines...) Expand all
4394 returnStatement; 4915 returnStatement;
4395 yieldStatement; 4916 yieldStatement;
4396 yieldEachStatement; 4917 yieldEachStatement;
4397 expressionStatement; 4918 expressionStatement;
4398 assertStatement; 4919 assertStatement;
4399 localFunctionDeclaration 4920 localFunctionDeclaration
4400 . 4921 .
4401 \end{grammar} 4922 \end{grammar}
4402 4923
4403 \subsection{Blocks} 4924 \subsection{Blocks}
4404 \label{blocks} 4925 \LMLabel{blocks}
4405 4926
4927 \LMHash{}
4406 A {\em block statement} supports sequencing of code. 4928 A {\em block statement} supports sequencing of code.
4407 4929
4930 \LMHash{}
4408 Execution of a block statement $\{s_1, \ldots, s_n\}$ proceeds as follows: 4931 Execution of a block statement $\{s_1, \ldots, s_n\}$ proceeds as follows:
4409 4932
4933 \LMHash{}
4410 For $i \in 1 .. n, s_i$ is executed. 4934 For $i \in 1 .. n, s_i$ is executed.
4411 4935
4936 \LMHash{}
4412 A block statement introduces a new scope, which is nested in the lexically enclo sing scope in which the block statement appears. 4937 A block statement introduces a new scope, which is nested in the lexically enclo sing scope in which the block statement appears.
4413 4938
4414 4939
4415 4940
4416 \subsection{Expression Statements} 4941 \subsection{Expression Statements}
4417 \label{expressionStatements} 4942 \LMLabel{expressionStatements}
4418 4943
4944 \LMHash{}
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. 4945 An {\em expression statement} consists of an expression other than a non-constan t map literal (\ref{maps}) that has no explicit type arguments.
4420 4946
4421 \rationale{ 4947 \rationale{
4422 The restriction on maps is designed to resolve an ambiguity in the grammar, whe n a statement begins with \{. 4948 The restriction on maps is designed to resolve an ambiguity in the grammar, whe n a statement begins with \{.
4423 } 4949 }
4424 4950
4425 \begin{grammar} 4951 \begin{grammar}
4426 {\bf expressionStatement:} 4952 {\bf expressionStatement:}
4427 expression? `{\escapegrammar ;}' 4953 expression? `{\escapegrammar ;}'
4428 . 4954 .
4429 \end{grammar} 4955 \end{grammar}
4430 4956
4957 \LMHash{}
4431 Execution of an expression statement \code{$e$;} proceeds by evaluating $e$. 4958 Execution of an expression statement \code{$e$;} proceeds by evaluating $e$.
4432 4959
4960 \LMHash{}
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. 4961 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.
4434 4962
4435 \subsection{Local Variable Declaration} 4963 \subsection{Local Variable Declaration}
4436 \label{localVariableDeclaration} 4964 \LMLabel{localVariableDeclaration}
4437 4965
4438 4966
4967 \LMHash{}
4439 A {\em variable declaration statement }declares a new local variable. 4968 A {\em variable declaration statement }declares a new local variable.
4440 4969
4441 \begin{grammar} 4970 \begin{grammar}
4442 {\bf localVariableDeclaration:} 4971 {\bf localVariableDeclaration:}
4443 initializedVariableDeclaration {\escapegrammar';'} 4972 initializedVariableDeclaration {\escapegrammar';'}
4444 . 4973 .
4445 \end{grammar} 4974 \end{grammar}
4446 4975
4976 \LMHash{}
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: 4977 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:
4448 4978
4979 \LMHash{}
4449 The expression $e$ is evaluated to an object $o$. Then, the variable $v$ is set to $o$. 4980 The expression $e$ is evaluated to an object $o$. Then, the variable $v$ is set to $o$.
4450 4981
4982 \LMHash{}
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{};$. 4983 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{};$.
4452 4984
4453 \commentary{ 4985 \commentary{
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;}. 4986 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;}.
4455 } 4987 }
4456 4988
4457 \rationale{ 4989 \rationale{
4458 To do otherwise would undermine the optionally typed nature of Dart, causing typ e annotations to modify program behavior. 4990 To do otherwise would undermine the optionally typed nature of Dart, causing typ e annotations to modify program behavior.
4459 } 4991 }
4460 4992
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$. 4993 %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$.
4462 4994
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$. 4995 %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$.
4464 4996
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$. 4997 %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$.
4466 4998
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$. 4999 %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$.
4468 5000
4469 %\rationale{ 5001 %\rationale{
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. 5002 %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.
4471 %} 5003 %}
4472 5004
4473 5005
4474 \subsection{Local Function Declaration} 5006 \subsection{Local Function Declaration}
5007 \LMLabel{localFunctionDeclaration}
4475 5008
4476 \label{localFunctionDeclaration} 5009 \LMHash{}
4477
4478 A function declaration statement declares a new local function (\ref{functionDec larations}). 5010 A function declaration statement declares a new local function (\ref{functionDec larations}).
4479 5011
4480 \begin{grammar} 5012 \begin{grammar}
4481 {\bf localFunctionDeclaration:} 5013 {\bf localFunctionDeclaration:}
4482 functionSignature functionBody 5014 functionSignature functionBody
4483 . 5015 .
4484 \end{grammar} 5016 \end{grammar}
4485 5017
5018 \LMHash{}
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. 5019 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.
4487 5020
4488 5021
4489 \commentary{ This implies that local functions can be directly recursive, but no t mutually recursive. Consider these examples: 5022 \commentary{ This implies that local functions can be directly recursive, but no t mutually recursive. Consider these examples:
4490 } 5023 }
4491 5024
4492 \begin{dartCode} 5025 \begin{dartCode}
4493 f(x) =$>$ x++; // a top level function 5026 f(x) =$>$ x++; // a top level function
4494 top() \{ // another top level function 5027 top() \{ // another top level function
4495 f(3); // illegal 5028 f(3); // illegal
(...skipping 23 matching lines...) Expand all
4519 \} 5052 \}
4520 \end{dartCode} 5053 \end{dartCode}
4521 5054
4522 \rationale{ 5055 \rationale{
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. 5056 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.
4524 } 5057 }
4525 5058
4526 % elaborate on function identity and equality, runtime type. Likewsie in functio n expressions (closures) and declarations 5059 % elaborate on function identity and equality, runtime type. Likewsie in functio n expressions (closures) and declarations
4527 5060
4528 \subsection{If} 5061 \subsection{If}
4529 \label{if} 5062 \LMLabel{if}
4530 5063
5064 \LMHash{}
4531 The {\em if statement} allows for conditional execution of statements. 5065 The {\em if statement} allows for conditional execution of statements.
4532 5066
4533 \begin{grammar} 5067 \begin{grammar}
4534 {\bf ifStatement:} 5068 {\bf ifStatement:}
4535 \IF{} `(' expression `)' statement ( \ELSE{} statement)? % we could allow top level expression 5069 \IF{} `(' expression `)' statement ( \ELSE{} statement)? % we could allow top level expression
4536 . 5070 .
4537 \end{grammar} 5071 \end{grammar}
4538 5072
4539 Execution of an if statement of the form \code {\IF{} (}$b$\code{)}$s_1$ \code{ \ELSE{} } $s_2$ proceeds as follows: 5073 Execution of an if statement of the form \code {\IF{} (}$b$\code{)}$s_1$ \code{ \ELSE{} } $s_2$ proceeds as follows:
4540 5074
5075 \LMHash{}
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. 5076 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.
4542 5077
4543 5078
4544 \commentary { 5079 \commentary {
4545 Put another way, \code {\IF{} (}$b$\code{)}$s_1$ \code{\ELSE{} } $s_2$ is equiv alent to 5080 Put another way, \code {\IF{} (}$b$\code{)}$s_1$ \code{\ELSE{} } $s_2$ is equiv alent to
4546 \code {\IF{} (}$b$\code{)}$\{s_1\}$ \code{\ELSE{} } $\{s_2\}$ 5081 \code {\IF{} (}$b$\code{)}$\{s_1\}$ \code{\ELSE{} } $\{s_2\}$
4547 } 5082 }
4548 5083
4549 \rationale { 5084 \rationale {
4550 The reason for this equivalence is to catch errors such as 5085 The reason for this equivalence is to catch errors such as
4551 } 5086 }
4552 \begin{dartCode} 5087 \begin{dartCode}
4553 \VOID{} main() \{ 5088 \VOID{} main() \{
4554 \IF{} (somePredicate) 5089 \IF{} (somePredicate)
4555 \VAR{} v = 2; 5090 \VAR{} v = 2;
4556 print(v); 5091 print(v);
4557 \} 5092 \}
4558 \end{dartCode} 5093 \end{dartCode}
4559 5094
4560 \rationale { 5095 \rationale {
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. 5096 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.
4562 } 5097 }
4563 5098
5099 \LMHash{}
4564 It is a static type warning if the type of the expression $b$ may not be assig ned to \code{bool}. 5100 It is a static type warning if the type of the expression $b$ may not be assig ned to \code{bool}.
4565 5101
5102 \LMHash{}
4566 If: 5103 If:
4567 \begin{itemize} 5104 \begin{itemize}
4568 \item $b$ shows that a variable $v$ has type $T$. 5105 \item $b$ shows that a variable $v$ has type $T$.
4569 \item $v$ is not potentially mutated in $s_1$ or within a closure. 5106 \item $v$ is not potentially mutated in $s_1$ or within a closure.
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$. 5107 \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$.
4571 \end{itemize} 5108 \end{itemize}
4572 then the type of $v$ is known to be $T$ in $s_1$. 5109 then the type of $v$ is known to be $T$ in $s_1$.
4573 5110
5111 \LMHash{}
4574 An if statement of the form \code {\IF{} (}$b$\code{)}$s_1$ is equivalent to t he if statement 5112 An if statement of the form \code {\IF{} (}$b$\code{)}$s_1$ is equivalent to t he if statement
4575 5113
4576 \code {\IF{} (}$b$\code{)}$s_1$ \code{\ELSE{} \{\}}. 5114 \code {\IF{} (}$b$\code{)}$s_1$ \code{\ELSE{} \{\}}.
4577 5115
4578 5116
4579 5117
4580 \subsection{For} 5118 \subsection{For}
4581 \label{for} 5119 \LMLabel{for}
4582 5120
5121 \LMHash{}
4583 The {\em for statement} supports iteration. 5122 The {\em for statement} supports iteration.
4584 5123
4585 \begin{grammar} 5124 \begin{grammar}
4586 {\bf forStatement:} 5125 {\bf forStatement:}
4587 \AWAIT? \FOR{} `(' forLoopParts `)' statement 5126 \AWAIT? \FOR{} `(' forLoopParts `)' statement
4588 . 5127 .
4589 5128
4590 {\bf forLoopParts:}forInitializerStatement expression? `{\escapegrammar ;}' expr essionList?; 5129 {\bf forLoopParts:}forInitializerStatement expression? `{\escapegrammar ;}' expr essionList?;
4591 declaredIdentifier \IN{} expression; 5130 declaredIdentifier \IN{} expression;
4592 identifier \IN{} expression 5131 identifier \IN{} expression
4593 . 5132 .
4594 5133
4595 {\bf forInitializerStatement:}localVariableDeclaration `{\escapegrammar ;}'; 5134 {\bf forInitializerStatement:}localVariableDeclaration `{\escapegrammar ;}';
4596 expression? `{\escapegrammar ;}' 5135 expression? `{\escapegrammar ;}'
4597 . 5136 .
4598 \end{grammar} 5137 \end{grammar}
4599 5138
5139 \LMHash{}
4600 The for statement has three forms - the traditional for loop and two forms of t he for-in statement - synchronous and asynchronous. 5140 The for statement has three forms - the traditional for loop and two forms of t he for-in statement - synchronous and asynchronous.
4601 5141
4602 \subsubsection{For Loop} 5142 \subsubsection{For Loop}
4603 \label{forLoop} 5143 \LMLabel{forLoop}
4604 5144
4605 5145
5146 \LMHash{}
4606 Execution of a for statement of the form \code{ \FOR{} (\VAR{} $v = e_0$ ; $c$ ; $e$) $s$} proceeds as follows: 5147 Execution of a for statement of the form \code{ \FOR{} (\VAR{} $v = e_0$ ; $c$ ; $e$) $s$} proceeds as follows:
4607 5148
5149 \LMHash{}
4608 If $c$ is empty then let $c^\prime$ be \TRUE{} otherwise let $c^\prime$ be $c$. 5150 If $c$ is empty then let $c^\prime$ be \TRUE{} otherwise let $c^\prime$ be $c$.
4609 5151
5152 \LMHash{}
4610 First the variable declaration statement \VAR{} $v = e_0$ is executed. Then: 5153 First the variable declaration statement \VAR{} $v = e_0$ is executed. Then:
4611 \begin{enumerate} 5154 \begin{enumerate}
4612 \item 5155 \item
4613 \label{beginFor} 5156 \label{beginFor}
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}. 5157 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}.
4615 \item 5158 \item
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 5159 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
4617 \ref{beginIteration}. 5160 \ref{beginIteration}.
4618 \item 5161 \item
4619 \label{beginIteration} 5162 \label{beginIteration}
4620 The statement $[v^\prime/v]\{s\}$ is executed. 5163 The statement $[v^\prime/v]\{s\}$ is executed.
4621 \item 5164 \item
4622 \label{allocateFreshVar} 5165 \label{allocateFreshVar}
4623 Let $v^{\prime\prime}$ be a fresh variable. $v^{\prime\prime}$ is bound to the value of $v^\prime$. 5166 Let $v^{\prime\prime}$ be a fresh variable. $v^{\prime\prime}$ is bound to the value of $v^\prime$.
4624 \item 5167 \item
4625 The expression $[v^{\prime\prime}/v]e$ is evaluated, and the process recurses at step 5168 The expression $[v^{\prime\prime}/v]e$ is evaluated, and the process recurses at step
4626 \ref{beginFor}. 5169 \ref{beginFor}.
4627 \end{enumerate} 5170 \end{enumerate}
4628 5171
4629 \rationale{ 5172 \rationale{
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. 5173 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.
4631 5174
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. 5175 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.
4633 } 5176 }
4634 5177
5178 \LMHash{}
4635 It is a static warning if the static type of $c$ may not be assigned to \cd{bool }. 5179 It is a static warning if the static type of $c$ may not be assigned to \cd{bool }.
4636 5180
4637 %A for statement of the form \code{ \FOR{} ($d$ ; $c$; $e$) $s$} is equivalent t o the the following code: 5181 %A for statement of the form \code{ \FOR{} ($d$ ; $c$; $e$) $s$} is equivalent t o the the following code:
4638 5182
4639 %\code{ 5183 %\code{
4640 %\{$d$; 5184 %\{$d$;
4641 %\WHILE{} ($c$) \{ 5185 %\WHILE{} ($c$) \{
4642 % \{$s$\} 5186 % \{$s$\}
4643 % $e$; 5187 % $e$;
4644 %\}\} 5188 %\}\}
4645 %} 5189 %}
4646 5190
4647 %If $c$ is empty, it is interpreted as \TRUE{}. 5191 %If $c$ is empty, it is interpreted as \TRUE{}.
4648 5192
4649 \subsubsection{For-in} 5193 \subsubsection{For-in}
4650 \label{for-in} 5194 \LMLabel{for-in}
4651 5195
5196 \LMHash{}
4652 A for statement of the form \code{ \FOR{} ($finalConstVarOrType?$ id \IN{} $e$) $s$} is equivalent to the following code: 5197 A for statement of the form \code{ \FOR{} ($finalConstVarOrType?$ id \IN{} $e$) $s$} is equivalent to the following code:
4653 5198
4654 \begin{dartCode} 5199 \begin{dartCode}
4655 var n0 = $e$.iterator; 5200 var n0 = $e$.iterator;
4656 \WHILE{} (n0.moveNext()) \{ 5201 \WHILE{} (n0.moveNext()) \{
4657 $finalConstVarOrType?$ id = n0.current; 5202 $finalConstVarOrType?$ id = n0.current;
4658 $s$ 5203 $s$
4659 \} 5204 \}
4660 \end{dartCode} 5205 \end{dartCode}
4661 where \code{n0} is an identifier that does not occur anywhere in the program. 5206 where \code{n0} is an identifier that does not occur anywhere in the program.
4662 5207
4663 \commentary{ 5208 \commentary{
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. 5209 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.
4665 } 5210 }
4666 5211
4667 \subsubsection{Asynchronous For-in} 5212 \subsubsection{Asynchronous For-in}
4668 \label{asynchronousFor-in} 5213 \LMLabel{asynchronousFor-in}
4669 5214
5215 \LMHash{}
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. 5216 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.
4671 5217
5218 \LMHash{}
4672 Execution of a for-in statement of the form \code{\AWAIT{} \FOR{} (finalConstVa rOrType? id \IN{} $e$) $s$} proceeds as follows: 5219 Execution of a for-in statement of the form \code{\AWAIT{} \FOR{} (finalConstVa rOrType? id \IN{} $e$) $s$} proceeds as follows:
4673 5220
5221 \LMHash{}
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}. 5222 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}.
4675 5223
5224 \LMHash{}
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}). 5225 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}).
4677 5226
5227 \LMHash{}
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. 5228 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.
4679 5229
4680 \rationale{ 5230 \rationale{
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. 5231 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.
4682 } 5232 }
4683 5233
5234 \LMHash{}
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. 5235 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.
4685 5236
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.} 5237 \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.}
4687 5238
4688 5239
4689 \subsection{While} 5240 \subsection{While}
4690 \label{while} 5241 \LMLabel{while}
4691 5242
5243 \LMHash{}
4692 The while statement supports conditional iteration, where the condition is evalu ated prior to the loop. 5244 The while statement supports conditional iteration, where the condition is evalu ated prior to the loop.
4693 5245
4694 \begin{grammar} 5246 \begin{grammar}
4695 {\bf whileStatement:} 5247 {\bf whileStatement:}
4696 \WHILE{} `(' expression `)' statement % could do top level here, and in f or 5248 \WHILE{} `(' expression `)' statement % could do top level here, and in f or
4697 . 5249 .
4698 \end{grammar} 5250 \end{grammar}
4699 5251
5252 \LMHash{}
4700 Execution of a while statement of the form \code{\WHILE{} ($e$) $s$;} proceeds as follows: 5253 Execution of a while statement of the form \code{\WHILE{} ($e$) $s$;} proceeds as follows:
4701 5254
5255 \LMHash{}
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. 5256 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.
4703 5257
5258 \LMHash{}
4704 It is a static type warning if the static type of $e$ may not be assigned to \co de{bool}. 5259 It is a static type warning if the static type of $e$ may not be assigned to \co de{bool}.
4705 5260
4706 5261
4707 \subsection{Do} 5262 \subsection{Do}
4708 \label{do} 5263 \LMLabel{do}
4709 5264
5265 \LMHash{}
4710 The do statement supports conditional iteration, where the condition is evaluate d after the loop. 5266 The do statement supports conditional iteration, where the condition is evaluate d after the loop.
4711 5267
4712 \begin{grammar} 5268 \begin{grammar}
4713 {\bf doStatement:} 5269 {\bf doStatement:}
4714 \DO{} statement \WHILE{} `(' expression `)' `{\escapegrammar ;}'% could do t op level here 5270 \DO{} statement \WHILE{} `(' expression `)' `{\escapegrammar ;}'% could do t op level here
4715 . 5271 .
4716 \end{grammar} 5272 \end{grammar}
4717 5273
4718 5274
5275 \LMHash{}
4719 Execution of a do statement of the form \code{\DO{} $s$ \WHILE{} ($e$);} proceed s as follows: 5276 Execution of a do statement of the form \code{\DO{} $s$ \WHILE{} ($e$);} proceed s as follows:
4720 5277
5278 \LMHash{}
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. 5279 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.
4722 5280
5281 \LMHash{}
4723 It is a static type warning if the static type of $e$ may not be assigned to \co de{bool}. 5282 It is a static type warning if the static type of $e$ may not be assigned to \co de{bool}.
4724 5283
4725 \subsection{Switch} 5284 \subsection{Switch}
4726 \label{switch} 5285 \LMLabel{switch}
4727 5286
5287 \LMHash{}
4728 The {\em switch statement} supports dispatching control among a large number of cases. 5288 The {\em switch statement} supports dispatching control among a large number of cases.
4729 5289
4730 \begin{grammar} 5290 \begin{grammar}
4731 {\bf switchStatement:} 5291 {\bf switchStatement:}
4732 \SWITCH{} `(' expression `)' `\{' switchCase* defaultCase? `\}'% could do top level here and in cases 5292 \SWITCH{} `(' expression `)' `\{' switchCase* defaultCase? `\}'% could do top level here and in cases
4733 . 5293 .
4734 5294
4735 5295
4736 {\bf switchCase:} 5296 {\bf switchCase:}
4737 label* (\CASE{} expression `{\escapegrammar :}') statements 5297 label* (\CASE{} expression `{\escapegrammar :}') statements
4738 . 5298 .
4739 5299
4740 {\bf defaultCase:} 5300 {\bf defaultCase:}
4741 label* \DEFAULT{} `{\escapegrammar :}' statements 5301 label* \DEFAULT{} `{\escapegrammar :}' statements
4742 . 5302 .
4743 \end{grammar} 5303 \end{grammar}
4744 5304
5305 \LMHash{}
4745 Given a switch statement of the form 5306 Given a switch statement of the form
4746 5307
4747 \begin{dartCode} 5308 \begin{dartCode}
4748 \SWITCH{} ($e$) \{ 5309 \SWITCH{} ($e$) \{
4749 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ 5310 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$
4750 $\ldots$ 5311 $\ldots$
4751 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ 5312 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$
4752 \DEFAULT{}: $s_{n+1}$ 5313 \DEFAULT{}: $s_{n+1}$
4753 \} 5314 \}
4754 \end{dartCode} 5315 \end{dartCode}
(...skipping 11 matching lines...) Expand all
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: 5327 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:
4767 \begin{itemize} 5328 \begin{itemize}
4768 \item instances of the same class $C$, for all $k \in 1..n$, or 5329 \item instances of the same class $C$, for all $k \in 1..n$, or
4769 \item instances of a class that implements \cd{int}, for all $k \in 1..n$, or 5330 \item instances of a class that implements \cd{int}, for all $k \in 1..n$, or
4770 \item instances of a class that implements \cd{String}, for all $k \in 1..n$. 5331 \item instances of a class that implements \cd{String}, for all $k \in 1..n$.
4771 \end{itemize} 5332 \end{itemize}
4772 5333
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. 5334 \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.
4774 } 5335 }
4775 5336
5337 \LMHash{}
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}. 5338 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}.
4777 5339
4778 \rationale{ 5340 \rationale{
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. 5341 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.
4780 5342
4781 } 5343 }
4782 5344
4783 \commentary{ 5345 \commentary{
4784 The \SWITCH{} statement should only be used in very limited situations (e.g., i nterpreters or scanners). 5346 The \SWITCH{} statement should only be used in very limited situations (e.g., i nterpreters or scanners).
4785 } 5347 }
4786 5348
5349 \LMHash{}
4787 Execution of a switch statement of the form 5350 Execution of a switch statement of the form
4788 5351
4789 \begin{dartCode} 5352 \begin{dartCode}
4790 \SWITCH{} ($e$) \{ 5353 \SWITCH{} ($e$) \{
4791 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ 5354 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$
4792 $\ldots$ 5355 $\ldots$
4793 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ 5356 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$
4794 \DEFAULT{}: $s_{n+1}$ 5357 \DEFAULT{}: $s_{n+1}$
4795 \} 5358 \}
4796 \end{dartCode} 5359 \end{dartCode}
4797 5360
4798 or the form 5361 or the form
4799 5362
4800 \begin{dartCode} 5363 \begin{dartCode}
4801 \SWITCH{} ($e$) \{ 5364 \SWITCH{} ($e$) \{
4802 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ 5365 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$
4803 $\ldots$ 5366 $\ldots$
4804 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ 5367 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$
4805 \} 5368 \}
4806 \end{dartCode} 5369 \end{dartCode}
4807 5370
4808 proceeds as follows: 5371 proceeds as follows:
4809 5372
5373 \LMHash{}
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$. 5374 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$.
4811 5375
4812 \commentary{Note that if there are no case clauses ($n = 0$), the type of $e$ do es not matter.} 5376 \commentary{Note that if there are no case clauses ($n = 0$), the type of $e$ do es not matter.}
4813 5377
5378 \LMHash{}
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}$. 5379 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}$.
4815 5380
5381 \LMHash{}
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. 5382 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.
4817 5383
5384 \LMHash{}
4818 Execution of a \CASE{} clause \CASE{} $e_{k}: s_{k}$ of a switch statement 5385 Execution of a \CASE{} clause \CASE{} $e_{k}: s_{k}$ of a switch statement
4819 5386
4820 \begin{dartCode} 5387 \begin{dartCode}
4821 \SWITCH{} ($e$) \{ 5388 \SWITCH{} ($e$) \{
4822 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ 5389 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$
4823 $\ldots$ 5390 $\ldots$
4824 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ 5391 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$
4825 \DEFAULT{}: $s_{n+1}$ 5392 \DEFAULT{}: $s_{n+1}$
4826 \} 5393 \}
4827 \end{dartCode} 5394 \end{dartCode}
4828 5395
4829 proceeds as follows: 5396 proceeds as follows:
4830 5397
5398 \LMHash{}
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$. 5399 The expression \code{$e_k$ == id} is evaluated to an object $o$ which is then su bjected to boolean conversion yielding a value $v$.
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}$. 5400 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}$.
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. 5401 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.
4834 If execution reaches the point after $s_h$ then a runtime error occurs, unless $h = n+1$. 5402 If execution reaches the point after $s_h$ then a runtime error occurs, unless $h = n+1$.
4835 5403
5404 \LMHash{}
4836 Execution of a \CASE{} clause \CASE{} $e_{k}: s_{k}$ of a switch statement 5405 Execution of a \CASE{} clause \CASE{} $e_{k}: s_{k}$ of a switch statement
4837 5406
4838 \begin{dartCode} 5407 \begin{dartCode}
4839 \SWITCH{} ($e$) \{ 5408 \SWITCH{} ($e$) \{
4840 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ 5409 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$
4841 $\ldots$ 5410 $\ldots$
4842 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ 5411 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$
4843 \} 5412 \}
4844 \end{dartCode} 5413 \end{dartCode}
4845 5414
4846 proceeds as follows: 5415 proceeds as follows:
4847 5416
5417 \LMHash{}
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$. 5418 The expression \code{$e_k$ == id} is evaluated to an object $o$ which is then su bjected to boolean conversion yielding a value $v$.
4849 If $v$ is not \TRUE{} the following case, \CASE{} $e_{k+1}: s_{k+1}$ is execut ed if it exists. 5419 If $v$ is not \TRUE{} the following case, \CASE{} $e_{k+1}: s_{k+1}$ is execut ed 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. 5420 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.
4851 If execution reaches the point after $s_h$ then a runtime error occurs, unless $h = n$. 5421 If execution reaches the point after $s_h$ then a runtime error occurs, unless $h = n$.
4852 5422
4853 5423
4854 \commentary{ 5424 \commentary{
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 . 5425 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 .
4856 } 5426 }
4857 5427
5428 \LMHash{}
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. 5429 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.
4859 5430
4860 \rationale{ 5431 \rationale{
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) . 5432 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) .
4862 5433
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.: 5434 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.:
4864 } 5435 }
4865 5436
4866 \begin{dartCode} 5437 \begin{dartCode}
4867 \SWITCH{} (x) \{ 5438 \SWITCH{} (x) \{
4868 \CASE{} 1: \TRY{} \{ $\ldots$ \RETURN{};\} \FINALLY{} \{ $\ldots$ \RETURN{};\} 5439 \CASE{} 1: \TRY{} \{ $\ldots$ \RETURN{};\} \FINALLY{} \{ $\ldots$ \RETURN{};\}
4869 \} 5440 \}
4870 \end{dartCode} 5441 \end{dartCode}
4871 5442
4872 \rationale{ 5443 \rationale{
4873 Very elaborate code in a case clause is probably bad style in any case, and su ch code can always be refactored. 5444 Very elaborate code in a case clause is probably bad style in any case, and su ch code can always be refactored.
4874 } 5445 }
4875 5446
5447 \LMHash{}
4876 It is a static warning if all of the following conditions hold: 5448 It is a static warning if all of the following conditions hold:
4877 \begin{itemize} 5449 \begin{itemize}
4878 \item The switch statement does not have a default clause. 5450 \item The switch statement does not have a default clause.
4879 \item The static type of $e$ is an enumerated typed with elements $id_1, \ldots , id_n$. 5451 \item The static type of $e$ is an enumerated typed with elements $id_1, \ldots , id_n$.
4880 \item The sets $\{e_1, \ldots, e_k\} $ and $\{id_1, \ldots, id_n\}$ are not the same. 5452 \item The sets $\{e_1, \ldots, e_k\} $ and $\{id_1, \ldots, id_n\}$ are not the same.
4881 \end{itemize} 5453 \end{itemize}
4882 5454
4883 \commentary{ 5455 \commentary{
4884 In other words, a warning will be issued if a switch statement over an enum is n ot exhaustive. 5456 In other words, a warning will be issued if a switch statement over an enum is n ot exhaustive.
4885 } 5457 }
4886 5458
4887 5459
4888 \subsection{ Rethrow} 5460 \subsection{ Rethrow}
4889 \label{rethrow} 5461 \LMLabel{rethrow}
4890 5462
4891 5463
5464 \LMHash{}
4892 The {\em rethrow statement} is used to re-raise an exception. 5465 The {\em rethrow statement} is used to re-raise an exception.
4893 5466
4894 \begin{grammar} 5467 \begin{grammar}
4895 {\bf rethrowStatement:} 5468 {\bf rethrowStatement:}
4896 \RETHROW{} `{\escapegrammar ;}' 5469 \RETHROW{} `{\escapegrammar ;}'
4897 . 5470 .
4898 \end{grammar} 5471 \end{grammar}
4899 5472
5473 \LMHash{}
4900 Execution of a \code{\RETHROW{}} statement proceeds as follows: 5474 Execution of a \code{\RETHROW{}} statement proceeds as follows:
4901 5475
5476 \LMHash{}
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}). 5477 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}).
4903 5478
4904 \rationale{ 5479 \rationale{
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. 5480 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.
4906 } 5481 }
4907 5482
5483 \LMHash{}
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$. 5484 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$.
4909 5485
5486 \LMHash{}
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. 5487 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.
4911 5488
4912 \rationale{ 5489 \rationale{
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. 5490 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.
4914 } 5491 }
4915 5492
5493 \LMHash{}
4916 Otherwise, control is transferred to the innermost enclosing exception handler. 5494 Otherwise, control is transferred to the innermost enclosing exception handler.
4917 5495
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.} 5496 \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.}
4919 5497
5498 \LMHash{}
4920 It is a compile-time error if a \code{\RETHROW{}} statement is not enclosed wit hin an \ON-\CATCH{} clause. 5499 It is a compile-time error if a \code{\RETHROW{}} statement is not enclosed wit hin an \ON-\CATCH{} clause.
4921 5500
4922 5501
4923 5502
4924 \subsection{ Try} 5503 \subsection{ Try}
4925 \label{try} 5504 \LMLabel{try}
4926 5505
5506 \LMHash{}
4927 The try statement supports the definition of exception handling code in a struct ured way. 5507 The try statement supports the definition of exception handling code in a struct ured way.
4928 5508
4929 \begin{grammar} 5509 \begin{grammar}
4930 {\bf tryStatement:} 5510 {\bf tryStatement:}
4931 \TRY{} block (onPart+ finallyPart? $|$ finallyPart) 5511 \TRY{} block (onPart+ finallyPart? $|$ finallyPart)
4932 . 5512 .
4933 5513
4934 {\bf onPart:}catchPart block; 5514 {\bf onPart:}catchPart block;
4935 \ON{} type catchPart? block 5515 \ON{} type catchPart? block
4936 . 5516 .
4937 5517
4938 {\bf catchPart:} 5518 {\bf catchPart:}
4939 \CATCH{} `(' identifier (`,' identifier)? `)' 5519 \CATCH{} `(' identifier (`,' identifier)? `)'
4940 . 5520 .
4941 5521
4942 {\bf finallyPart:} 5522 {\bf finallyPart:}
4943 \FINALLY{} block 5523 \FINALLY{} block
4944 . 5524 .
4945 \end{grammar} 5525 \end{grammar}
4946 5526
5527 \LMHash{}
4947 A try statement consists of a block statement, followed by at least one of: 5528 A try statement consists of a block statement, followed by at least one of:
4948 \begin{enumerate} 5529 \begin{enumerate}
4949 \item 5530 \item
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. 5531 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.
4951 \item 5532 \item
4952 A \FINALLY{} clause, which consists of a block statement. 5533 A \FINALLY{} clause, which consists of a block statement.
4953 \end{enumerate} 5534 \end{enumerate}
4954 5535
4955 \rationale{ 5536 \rationale{
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. 5537 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.
4957 } 5538 }
4958 5539
5540 \LMHash{}
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. 5541 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.
4960 5542
4961 \commentary { 5543 \commentary {
4962 It is of course a static warning if $T$ is a deferred or malformed type. 5544 It is of course a static warning if $T$ is a deferred or malformed type.
4963 } 5545 }
4964 5546
5547 \LMHash{}
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}. 5548 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}.
4966 5549
4967 5550
5551 \LMHash{}
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. 5552 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.
4969 5553
4970 5554
5555 \LMHash{}
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$}. 5556 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$}.
4972 5557
4973 5558
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{}. 5559 %If an explicit type is associated with of $p_2$, it is a static warning if that type is not \code{Object} or \DYNAMIC{}.
4975 5560
5561 \LMHash{}
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. 5562 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.
4977 %\begin{enumerate} 5563 %\begin{enumerate}
4978 %\item Started execution after the currently executing function. 5564 %\item Started execution after the currently executing function.
4979 %\item Had not completed execution at the point where the exception caught by th e currently executing \ON{}-\CATCH{} clause was initially thrown. 5565 %\item Had not completed execution at the point where the exception caught by th e currently executing \ON{}-\CATCH{} clause was initially thrown.
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.} 5566 %\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.}
4981 %\end{enumerate} 5567 %\end{enumerate}
4982 5568
4983 \commentary{ 5569 \commentary{
4984 This implies that no synthetic function activations may be added to the trace, n or may any source level activations be omitted. 5570 This implies that no synthetic function activations may be added to the trace, n or may any source level activations be omitted.
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. 5571 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
4996 5582
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. 5583 % 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.
4998 5584
4999 % Is this controversial? We were thinking of viewing the trace as a List<Invoca tion>, 5585 % Is this controversial? We were thinking of viewing the trace as a List<Invoca tion>,
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. 5586 % 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.
5001 5587
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. } 5588 \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. }
5003 5589
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. 5590 % A position can be represented via a Token. If we make that part of the core r eflection facility, we can state this here.
5005 5591
5592 \LMHash{}
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: 5593 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:
5007 5594
5595 \LMHash{}
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. 5596 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.
5009 5597
5010 5598
5599 \LMHash{}
5011 A finally clause \FINALLY{} $s$ defines an exception handler $h$ that executes a s follows: 5600 A finally clause \FINALLY{} $s$ defines an exception handler $h$ that executes a s follows:
5012 5601
5602 \LMHash{}
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. 5603 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.
5014 5604
5015 \rationale{ 5605 \rationale{
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. 5606 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.
5017 } 5607 }
5018 5608
5609 \LMHash{}
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: 5610 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:
5020 \begin{itemize} 5611 \begin{itemize}
5021 \item 5612 \item
5022 if there is a dynamically enclosing error handler $g$ defined by a \FINALLY{} c lause in $m$, control is transferred to $g$. 5613 if there is a dynamically enclosing error handler $g$ defined by a \FINALLY{} c lause in $m$, control is transferred to $g$.
5023 \item 5614 \item
5024 Otherwise $m$ terminates. 5615 Otherwise $m$ terminates.
5025 \end{itemize} 5616 \end{itemize}
5026 5617
5027 Otherwise, execution resumes at the end of the try statement. 5618 Otherwise, execution resumes at the end of the try statement.
5028 5619
5620 \LMHash{}
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. 5621 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.
5030 5622
5623 \LMHash{}
5031 Execution of a \FINALLY{} clause \FINALLY{} $s$ of a try statement proceeds as f ollows: 5624 Execution of a \FINALLY{} clause \FINALLY{} $s$ of a try statement proceeds as f ollows:
5032 5625
5626 \LMHash{}
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. 5627 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.
5034 5628
5035 5629
5630 \LMHash{}
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: 5631 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:
5037 5632
5633 \LMHash{}
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. 5634 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.
5039 5635
5040 \commentary{ 5636 \commentary{
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). 5637 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).
5042 5638
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 . 5639 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 .
5044 5640
5045 If a matching \ON{}-\CATCH{} was found, it will execute first, and then the \FIN ALLY{} clause will be executed. 5641 If a matching \ON{}-\CATCH{} was found, it will execute first, and then the \FIN ALLY{} clause will be executed.
5046 5642
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. 5643 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.
5048 5644
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. 5645 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.
5050 } 5646 }
5051 5647
5648 \LMHash{}
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{} $\{\}$}. 5649 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{} $\{\}$}.
5053 5650
5054 5651
5055 \subsection{ Return} 5652 \subsection{ Return}
5056 \label{return} 5653 \LMLabel{return}
5057 5654
5655 \LMHash{}
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}). 5656 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}).
5059 5657
5060 5658
5061 \begin{grammar} 5659 \begin{grammar}
5062 {\bf returnStatement:} 5660 {\bf returnStatement:}
5063 \RETURN{} expression? `{\escapegrammar ;}' % could do top level here 5661 \RETURN{} expression? `{\escapegrammar ;}' % could do top level here
5064 . 5662 .
5065 \end{grammar} 5663 \end{grammar}
5066 5664
5067 \commentary{ 5665 \commentary{
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. 5666 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.
5069 } 5667 }
5070 5668
5669 \LMHash{}
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. 5670 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.
5072 5671
5672 \LMHash{}
5073 Executing a return statement \code{\RETURN{} $e$;} proceeds as follows: 5673 Executing a return statement \code{\RETURN{} $e$;} proceeds as follows:
5074 5674
5675 \LMHash{}
5075 First the expression $e$ is evaluated, producing an object $o$. Next: 5676 First the expression $e$ is evaluated, producing an object $o$. Next:
5076 \begin{itemize} 5677 \begin{itemize}
5077 \item 5678 \item
5078 The current return value is set to $o$ and the current exception (\ref{throw}) a nd active stack trace (\ref{try}) become undefined. 5679 The current return value is set to $o$ and the current exception (\ref{throw}) a nd active stack trace (\ref{try}) become undefined.
5079 \item 5680 \item
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$. 5681 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$.
5081 \item 5682 \item
5082 Otherwise execution of the current method terminates. 5683 Otherwise execution of the current method terminates.
5083 \end{itemize} 5684 \end{itemize}
5084 5685
5085 \commentary{ 5686 \commentary{
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}. 5687 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}.
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. 5688 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.
5088 } 5689 }
5089 5690
5691 \LMHash{}
5090 Let $T$ be the static type of $e$ and let $f$ be the immediately enclosing funct ion. 5692 Let $T$ be the static type of $e$ and let $f$ be the immediately enclosing funct ion.
5091 5693
5694 \LMHash{}
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$. 5695 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$.
5093 5696
5697 \LMHash{}
5094 Let $S$ be the runtime type of $o$. In checked mode: 5698 Let $S$ be the runtime type of $o$. In checked mode:
5095 \begin{itemize} 5699 \begin{itemize}
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$. 5700 \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$.
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$. 5701 \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$.
5098 \end{itemize} 5702 \end{itemize}
5099 5703
5704 \LMHash{}
5100 It is a compile-time error if a return statement of the form \code{\RETURN{} $e$ ;} appears in a generative constructor (\ref{generativeConstructors}). 5705 It is a compile-time error if a return statement of the form \code{\RETURN{} $e$ ;} appears in a generative constructor (\ref{generativeConstructors}).
5101 5706
5102 \rationale{ 5707 \rationale{
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. 5708 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.
5104 } 5709 }
5105 5710
5711 \LMHash{}
5106 It is a compile-time error if a return statement of the form \code{\RETURN{} $e$ ;} appears in a generator function. 5712 It is a compile-time error if a return statement of the form \code{\RETURN{} $e$ ;} appears in a generator function.
5107 5713
5108 \rationale{ 5714 \rationale{
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. 5715 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.
5110 } 5716 }
5111 5717
5718 \LMHash{}
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: 5719 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:
5113 \begin{itemize} 5720 \begin{itemize}
5114 \item $f$ is synchronous and the return type of $f$ may not be assigned to \VOI D{} (\ref{typeVoid}) or, 5721 \item $f$ is synchronous and the return type of $f$ may not be assigned to \VOI D{} (\ref{typeVoid}) or,
5115 \item $f$ is asynchronous and the return type of $f$ may not be assigned to \co de{Future$<$Null$>$}. 5722 \item $f$ is asynchronous and the return type of $f$ may not be assigned to \co de{Future$<$Null$>$}.
5116 \end{itemize} 5723 \end{itemize}
5117 5724
5118 \commentary{ 5725 \commentary{
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. 5726 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.
5120 } 5727 }
5121 \rationale{This helps catch situations where users forget to return a value in a return statement.} 5728 \rationale{This helps catch situations where users forget to return a value in a return statement.}
5122 5729
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.} 5730 \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.}
5124 5731
5732 \LMHash{}
5125 A return statement with no expression, \code{\RETURN;} is executed as follows: 5733 A return statement with no expression, \code{\RETURN;} is executed as follows:
5126 5734
5735 \LMHash{}
5127 If the immediately enclosing function $f$ is a generator, then: 5736 If the immediately enclosing function $f$ is a generator, then:
5128 \begin{itemize} 5737 \begin{itemize}
5129 \item 5738 \item
5130 The current return value is set to \NULL{}. 5739 The current return value is set to \NULL{}.
5131 \item 5740 \item
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$. 5741 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$.
5133 \item 5742 \item
5134 Otherwise, execution of the current method terminates. 5743 Otherwise, execution of the current method terminates.
5135 \end{itemize} 5744 \end{itemize}
5136 5745
5746 \LMHash{}
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{};}. 5747 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{};}.
5138 5748
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{};} 5749 \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{};}
5140 %in a \VOID{} function; neither is it illegal 5750 %in a \VOID{} function; neither is it illegal
5141 in a generative constructor. The rules relate only to the specific syntactic for m \code{\RETURN{} $e$;}. 5751 in a generative constructor. The rules relate only to the specific syntactic for m \code{\RETURN{} $e$;}.
5142 } 5752 }
5143 5753
5144 5754
5145 \rationale{ 5755 \rationale{
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. 5756 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.
5147 5757
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. 5758 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.
5149 } 5759 }
5150 5760
5761 \LMHash{}
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$;}. 5762 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$;}.
5152 5763
5153 5764
5154 5765
5155 5766
5156 \subsection{ Labels} 5767 \subsection{ Labels}
5157 \label{labels} 5768 \LMLabel{labels}
5158 5769
5770 \LMHash{}
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$. 5771 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$.
5160 5772
5161 \rationale{The sole role of labels is to provide targets for the break (\ref{bre ak}) and continue (\ref{continue}) statements.} 5773 \rationale{The sole role of labels is to provide targets for the break (\ref{bre ak}) and continue (\ref{continue}) statements.}
5162 5774
5163 %\Q{Are labels in a separate namespace? Bug 49774299} 5775 %\Q{Are labels in a separate namespace? Bug 49774299}
5164 5776
5165 \begin{grammar} 5777 \begin{grammar}
5166 {\bf label:} 5778 {\bf label:}
5167 identifier `{\escapegrammar :}' 5779 identifier `{\escapegrammar :}'
5168 . 5780 .
5169 \end{grammar} 5781 \end{grammar}
5170 5782
5783 \LMHash{}
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. 5784 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.
5172 5785
5786 \LMHash{}
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$. 5787 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$.
5174 5788
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. 5789 \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.
5176 } 5790 }
5177 5791
5178 5792
5179 \subsection{ Break} 5793 \subsection{ Break}
5180 \label{break} 5794 \LMLabel{break}
5181 5795
5796 \LMHash{}
5182 The {\em break statement} consists of the reserved word \BREAK{} and an optional label (\ref{labels}). 5797 The {\em break statement} consists of the reserved word \BREAK{} and an optional label (\ref{labels}).
5183 5798
5184 \begin{grammar} 5799 \begin{grammar}
5185 {\bf breakStatement:} 5800 {\bf breakStatement:}
5186 \BREAK{} identifier? `{\escapegrammar ;}' 5801 \BREAK{} identifier? `{\escapegrammar ;}'
5187 . 5802 .
5188 \end{grammar} 5803 \end{grammar}
5189 5804
5805 \LMHash{}
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$. 5806 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$.
5191 5807
5808 \LMHash{}
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$. 5809 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$.
5193 5810
5194 5811
5195 5812
5196 \subsection{ Continue} 5813 \subsection{ Continue}
5197 \label{continue} 5814 \LMLabel{continue}
5198 5815
5816 \LMHash{}
5199 The {\em continue statement} consists of the reserved word \CONTINUE{} and an op tional label (\ref{labels}). 5817 The {\em continue statement} consists of the reserved word \CONTINUE{} and an op tional label (\ref{labels}).
5200 5818
5201 \begin{grammar} 5819 \begin{grammar}
5202 {\bf continueStatement:} 5820 {\bf continueStatement:}
5203 \CONTINUE{} identifier? `{\escapegrammar ;}' 5821 \CONTINUE{} identifier? `{\escapegrammar ;}'
5204 . 5822 .
5205 \end{grammar} 5823 \end{grammar}
5206 5824
5825 \LMHash{}
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. 5826 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.
5208 5827
5209 \commentary{ 5828 \commentary{
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. 5829 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.
5211 } 5830 }
5212 5831
5832 \LMHash{}
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$. 5833 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$.
5214 5834
5215 \subsection{ Yield and Yield-Each} 5835 \subsection{ Yield and Yield-Each}
5216 \label{yieldAndYieldEach} 5836 \LMLabel{yieldAndYieldEach}
5217 5837
5218 \subsubsection{ Yield} 5838 \subsubsection{ Yield}
5219 \label{yield} 5839 \LMLabel{yield}
5220 5840
5841 \LMHash{}
5221 The {\em yield statement} adds an element to the result of a generator function (\ref{functions}). 5842 The {\em yield statement} adds an element to the result of a generator function (\ref{functions}).
5222 5843
5223 \begin{grammar} 5844 \begin{grammar}
5224 {\bf yieldStatement:} 5845 {\bf yieldStatement:}
5225 \YIELD{} expression `{\escapegrammar ;}' 5846 \YIELD{} expression `{\escapegrammar ;}'
5226 . 5847 .
5227 \end{grammar} 5848 \end{grammar}
5228 5849
5850 \LMHash{}
5229 Execution of a statement $s$ of the form \code{\YIELD{} $e$;} proceeds as follo ws: 5851 Execution of a statement $s$ of the form \code{\YIELD{} $e$;} proceeds as follo ws:
5230 5852
5853 \LMHash{}
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. 5854 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.
5232 5855
5856 \LMHash{}
5233 Next, $o$ is added to the iterable or stream associated with the immediately enc losing function. 5857 Next, $o$ is added to the iterable or stream associated with the immediately enc losing function.
5234 5858
5859 \LMHash{}
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. 5860 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.
5236 5861
5237 \rationale{ 5862 \rationale{
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. 5863 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.
5239 } 5864 }
5240 5865
5866 \LMHash{}
5241 If the enclosing function $m$ is marked \SYNC* (\ref{functions}) then: 5867 If the enclosing function $m$ is marked \SYNC* (\ref{functions}) then:
5242 \begin{itemize} 5868 \begin{itemize}
5243 \item 5869 \item
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$. 5870 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$.
5245 \item 5871 \item
5246 The current call to \code{moveNext()} returns \TRUE. 5872 The current call to \code{moveNext()} returns \TRUE.
5247 \end{itemize} 5873 \end{itemize}
5248 5874
5875 \LMHash{}
5249 It is a compile-time error if a yield statement appears in a function that is no t a generator function. 5876 It is a compile-time error if a yield statement appears in a function that is no t a generator function.
5250 5877
5878 \LMHash{}
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: 5879 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:
5252 \begin{itemize} 5880 \begin{itemize}
5253 \item 5881 \item
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$. 5882 the body of $f$ is marked \ASYNC* and the type \code{Stream$<$T$>$} may not be assigned to the declared return type of $f$.
5255 \item 5883 \item
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$. 5884 the body of $f$ is marked \SYNC* and the type \code{Iterable$<$T$>$} may not be assigned to the declared return type of $f$.
5257 \end{itemize} 5885 \end{itemize}
5258 5886
5259 5887
5260 \subsubsection{ Yield-Each} 5888 \subsubsection{ Yield-Each}
5261 \label{yieldEach} 5889 \LMLabel{yieldEach}
5262 5890
5891 \LMHash{}
5263 The {\em yield-each statement} adds a series of values to the result of a gener ator function (\ref{functions}). 5892 The {\em yield-each statement} adds a series of values to the result of a gener ator function (\ref{functions}).
5264 5893
5265 \begin{grammar} 5894 \begin{grammar}
5266 {\bf yieldEachStatement:} 5895 {\bf yieldEachStatement:}
5267 \YIELD* expression `{\escapegrammar ;}' 5896 \YIELD* expression `{\escapegrammar ;}'
5268 . 5897 .
5269 \end{grammar} 5898 \end{grammar}
5270 5899
5900 \LMHash{}
5271 Execution of a statement s of the form \code{\YIELD* $e$;} proceeds as follows: 5901 Execution of a statement s of the form \code{\YIELD* $e$;} proceeds as follows:
5272 5902
5903 \LMHash{}
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$: 5904 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$:
5274 \begin{itemize} 5905 \begin{itemize}
5275 \item 5906 \item
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. 5907 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.
5277 \item 5908 \item
5278 $x$ is added to the iterable or stream associated with $m$ in the order it appe ars in $o$. 5909 $x$ is added to the iterable or stream associated with $m$ in the order it appe ars in $o$.
5279 \item 5910 \item
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. 5911 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.
5281 \end{itemize} 5912 \end{itemize}
5282 5913
5914 \LMHash{}
5283 If the enclosing function is marked \SYNC* (\ref{functions}) then: 5915 If the enclosing function is marked \SYNC* (\ref{functions}) then:
5284 \begin{itemize} 5916 \begin{itemize}
5285 \item 5917 \item
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$. 5918 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$.
5287 \item 5919 \item
5288 The current call to \code{moveNext()} returns \TRUE. 5920 The current call to \code{moveNext()} returns \TRUE.
5289 \end{itemize} 5921 \end{itemize}
5290 5922
5923 \LMHash{}
5291 It is a compile-time error if a yield-each statement appears in a function that is not a generator function. 5924 It is a compile-time error if a yield-each statement appears in a function that is not a generator function.
5292 5925
5926 \LMHash{}
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$. 5927 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$.
5294 5928
5295 5929
5296 \subsection{ Assert} 5930 \subsection{ Assert}
5297 \label{assert} 5931 \LMLabel{assert}
5298 5932
5933 \LMHash{}
5299 An {\em assert statement} is used to disrupt normal execution if a given boolean condition does not hold. 5934 An {\em assert statement} is used to disrupt normal execution if a given boolean condition does not hold.
5300 5935
5301 \begin{grammar} 5936 \begin{grammar}
5302 {\bf assertStatement:} 5937 {\bf assertStatement:}
5303 assert `(' conditionalExpression `)' `{\escapegrammar ;}' 5938 assert `(' conditionalExpression `)' `{\escapegrammar ;}'
5304 . 5939 .
5305 \end{grammar} 5940 \end{grammar}
5306 5941
5942 \LMHash{}
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: 5943 The assert statement has no effect in production mode. In checked mode, executio n of an assert statement \code{\ASSERT{}($e$);} proceeds as follows:
5308 5944
5945 \LMHash{}
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$. 5946 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$.
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. 5947 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.
5311 5948
5312 %\Q{Might be cleaner to define it as \code{if (!$e$) \{\THROW{} \NEW{} Assertion Error();\}} (in checked mode only). 5949 %\Q{Might be cleaner to define it as \code{if (!$e$) \{\THROW{} \NEW{} Assertion Error();\}} (in checked mode only).
5313 %What about an error message as part of the assert?} 5950 %What about an error message as part of the assert?}
5314 5951
5952 \LMHash{}
5315 It is a static type warning if the type of $e$ may not be assigned to either \ code{bool} or $() \rightarrow$ \code{bool}. 5953 It is a static type warning if the type of $e$ may not be assigned to either \ code{bool} or $() \rightarrow$ \code{bool}.
5316 5954
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. 5955 \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.
5318 } 5956 }
5319 5957
5320 %If a lexically visible declaration named \code{assert} is in scope, an assert s tatement 5958 %If a lexically visible declaration named \code{assert} is in scope, an assert s tatement
5321 %\code{\ASSERT{} (e); } 5959 %\code{\ASSERT{} (e); }
5322 %is interpreted as an expression statement \code{(assert(e));} . 5960 %is interpreted as an expression statement \code{(assert(e));} .
5323 5961
5324 %\rationale{ 5962 %\rationale{
5325 %Since \ASSERT{} is a built-in identifier, one might define a function or method with this name. 5963 %Since \ASSERT{} is a built-in identifier, one might define a function or method with this name.
5326 %It is impossible to distinguish as \ASSERT{} statement from a method invocation in such a situation. 5964 %It is impossible to distinguish as \ASSERT{} statement from a method invocation in such a situation.
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.,} 5965 %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.,}
5328 5966
5329 %\begin{dartCode} 5967 %\begin{dartCode}
5330 % assert(bool b)\{print('My Personal Assertion \$b');\} 5968 % assert(bool b)\{print('My Personal Assertion \$b');\}
5331 5969
5332 % assert\_puzzler() \{ 5970 % assert\_puzzler() \{
5333 % (assert(\TRUE{})); // prints true 5971 % (assert(\TRUE{})); // prints true
5334 % assert(\TRUE{}); // would do nothing 5972 % assert(\TRUE{}); // would do nothing
5335 % (assert(\FALSE{})); // prints false 5973 % (assert(\FALSE{})); // prints false
5336 % assert(\FALSE{}); // would throw if asserts enabled, or do nothing otherwise 5974 % assert(\FALSE{}); // would throw if asserts enabled, or do nothing otherwise
5337 % \} 5975 % \}
5338 5976
5339 %\end{dartCode} 5977 %\end{dartCode}
5340 5978
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.} 5979 %\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.}
5342 5980
5343 \section{Libraries and Scripts} 5981 \section{Libraries and Scripts}
5344 \label{librariesAndScripts} 5982 \LMLabel{librariesAndScripts}
5345 5983
5984 \LMHash{}
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}). 5985 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}).
5347 5986
5987 \LMHash{}
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$. 5988 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$.
5349 5989
5350 \begin{grammar} 5990 \begin{grammar}
5351 {\bf topLevelDefinition:}classDefinition; 5991 {\bf topLevelDefinition:}classDefinition;
5352 enumType; 5992 enumType;
5353 % classDefinitionOrInterfaceInjection; 5993 % classDefinitionOrInterfaceInjection;
5354 % interfaceDefinitionOrInterfaceInjection; 5994 % interfaceDefinitionOrInterfaceInjection;
5355 % mixinApplication; 5995 % mixinApplication;
5356 typeAlias; 5996 typeAlias;
5357 \EXTERNAL{}? functionSignature `{\escapegrammar ;}'; 5997 \EXTERNAL{}? functionSignature `{\escapegrammar ;}';
(...skipping 30 matching lines...) Expand all
5388 . 6028 .
5389 6029
5390 {\bf libraryName:} 6030 {\bf libraryName:}
5391 metadata \LIBRARY{} identifier (`{\escapegrammar .}' identifier)* `{\escapegr ammar ;}' 6031 metadata \LIBRARY{} identifier (`{\escapegrammar .}' identifier)* `{\escapegr ammar ;}'
5392 . 6032 .
5393 6033
5394 {\bf importOrExport:}libraryImport ; 6034 {\bf importOrExport:}libraryImport ;
5395 libraryExport 6035 libraryExport
5396 \end{grammar} 6036 \end{grammar}
5397 6037
6038 \LMHash{}
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. 6039 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.
5399 6040
5400 \commentary{ 6041 \commentary{
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. 6042 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.
5402 } 6043 }
5403 6044
6045 \LMHash{}
5404 An implicitly named library has the empty string as its name. 6046 An implicitly named library has the empty string as its name.
5405 6047
5406 \rationale{ 6048 \rationale{
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. 6049 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.
5408 } 6050 }
5409 6051
5410 \commentary{ 6052 \commentary{
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. 6053 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.
5412 } 6054 }
5413 6055
6056 \LMHash{}
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. 6057 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.
5415 6058
6059 \LMHash{}
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. 6060 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.
5417 6061
5418 \commentary{Since top level privates are not imported, using the top level priva tes of another library is never possible. } 6062 \commentary{Since top level privates are not imported, using the top level priva tes of another library is never possible. }
5419 6063
6064 \LMHash{}
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$. 6065 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$.
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}). 6066 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}).
5422 6067
5423 6068
5424 \subsection{Imports} 6069 \subsection{Imports}
5425 \label{imports} 6070 \LMLabel{imports}
5426 6071
6072 \LMHash{}
5427 An {\em import} specifies a library to be used in the scope of another library. 6073 An {\em import} specifies a library to be used in the scope of another library.
5428 \begin{grammar} 6074 \begin{grammar}
5429 {\bf libraryImport:} 6075 {\bf libraryImport:}
5430 metadata importSpecification 6076 metadata importSpecification
5431 . 6077 .
5432 6078
5433 {\bf importSpecification:} 6079 {\bf importSpecification:}
5434 \IMPORT{} uri (\AS{} identifier)? combinator* `{\escapegrammar ;}'; 6080 \IMPORT{} uri (\AS{} identifier)? combinator* `{\escapegrammar ;}';
5435 \IMPORT{} uri \DEFERRED{} \AS{} identifier combinator* `{\escapegrammar ; }' 6081 \IMPORT{} uri \DEFERRED{} \AS{} identifier combinator* `{\escapegrammar ; }'
5436 . 6082 .
5437 6083
5438 {\bf combinator:}\SHOW{} identifierList; 6084 {\bf combinator:}\SHOW{} identifierList;
5439 \HIDE{} identifierList 6085 \HIDE{} identifierList
5440 . 6086 .
5441 6087
5442 {\bf identifierList:} 6088 {\bf identifierList:}
5443 identifier (, identifier)* 6089 identifier (, identifier)*
5444 \end{grammar} 6090 \end{grammar}
5445 6091
5446 6092
6093 \LMHash{}
5447 An import specifies a URI $x$ where the declaration of an imported library is to be found. 6094 An import specifies a URI $x$ where the declaration of an imported library is to be found.
5448 6095
6096 \LMHash{}
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. 6097 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.
5450 6098
6099 \LMHash{}
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. 6100 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.
5452 6101
6102 \LMHash{}
5453 It is a static warning if the specified URI of a deferred import does not refer to a library declaration. 6103 It is a static warning if the specified URI of a deferred import does not refer to a library declaration.
5454 6104
5455 \rationale{ 6105 \rationale{
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. 6106 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.
5457 } 6107 }
5458 6108
5459 6109
6110 \LMHash{}
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. 6111 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.
5461 6112
6113 \LMHash{}
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. 6114 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.
5463 6115
6116 \LMHash{}
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{}. 6117 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{}.
5465 6118
6119 \LMHash{}
5466 Let $I$ be an import directive that refers to a URI via the string $s_1$. Evalua tion of $I$ proceeds as follows: 6120 Let $I$ be an import directive that refers to a URI via the string $s_1$. Evalua tion of $I$ proceeds as follows:
5467 6121
6122 \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$. 6123 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$.
5469 The deferred prefix object has the following methods: 6124 The deferred prefix object has the following methods:
5470 6125
5471 \begin{itemize} 6126 \begin{itemize}
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. 6127 \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.
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. 6128 \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.
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. 6129 \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.
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. 6130 \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.
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. 6131 \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.
5477 \end{itemize} 6132 \end{itemize}
5478 6133
6134 \LMHash{}
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. 6135 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.
5480 6136
6137 \LMHash{}
5481 The effect of a repeated call to \code{$p$.loadLibrary} is as follows: 6138 The effect of a repeated call to \code{$p$.loadLibrary} is as follows:
5482 \begin{itemize} 6139 \begin{itemize}
5483 \item 6140 \item
5484 If another call to \code{$p$.loadLibrary} has already succeeded, the repeated ca ll also succeeds. 6141 If another call to \code{$p$.loadLibrary} has already succeeded, the repeated ca ll also succeeds.
5485 Otherwise, 6142 Otherwise,
5486 \item 6143 \item
5487 If another call to to \code{$p$.loadLibrary} has failed: 6144 If another call to to \code{$p$.loadLibrary} has failed:
5488 \begin{itemize} 6145 \begin{itemize}
5489 \item 6146 \item
5490 If the failure is due to a compilation error, the repeated call fails for the sa me reason. 6147 If the failure is due to a compilation error, the repeated call fails for the sa me reason.
5491 \item 6148 \item
5492 If the failure is due to other causes, the repeated call behaves as if no previo us call had been made. 6149 If the failure is due to other causes, the repeated call behaves as if no previo us call had been made.
5493 \end{itemize} 6150 \end{itemize}
5494 \end{itemize} 6151 \end{itemize}
5495 6152
5496 \commentary{ 6153 \commentary{
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. 6154 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.
5498 6155
5499 We do not specify what value the future returned resolves to. 6156 We do not specify what value the future returned resolves to.
5500 } 6157 }
5501 6158
6159 \LMHash{}
5502 If $I$ is an immediate import then, first 6160 If $I$ is an immediate import then, first
5503 6161
5504 \begin{itemize} 6162 \begin{itemize}
5505 \item 6163 \item
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. 6164 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.
5507 } 6165 }
5508 \item Otherwise, the contents of the URI denoted by $s_1$ have been compiled int o a library $B$ within the current isolate. 6166 \item Otherwise, the contents of the URI denoted by $s_1$ have been compiled int o a library $B$ within the current isolate.
5509 \end{itemize} 6167 \end{itemize}
5510 6168
5511 6169
6170 \LMHash{}
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$: 6171 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$:
5513 \begin{itemize} 6172 \begin{itemize}
5514 \item If $C_i$ is of the form 6173 \item If $C_i$ is of the form
5515 6174
5516 \code{\SHOW{} $id_1, \ldots, id_k$} 6175 \code{\SHOW{} $id_1, \ldots, id_k$}
5517 6176
5518 then let $NS_i = \SHOW{}([id_1, \ldots, id_k], NS_{i-1}$) 6177 then let $NS_i = \SHOW{}([id_1, \ldots, id_k], NS_{i-1}$)
5519 6178
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. 6179 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.
5521 6180
5522 \item If $C_i$ is of the form 6181 \item If $C_i$ is of the form
5523 6182
5524 \code{\HIDE{} $id_1, \ldots, id_k$} 6183 \code{\HIDE{} $id_1, \ldots, id_k$}
5525 6184
5526 then let $NS_i = \HIDE{}([id_1, \ldots, id_k], NS_{i-1}$) 6185 then let $NS_i = \HIDE{}([id_1, \ldots, id_k], NS_{i-1}$)
5527 6186
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. 6187 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.
5529 \end{itemize} 6188 \end{itemize}
5530 6189
6190 \LMHash{}
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: 6191 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:
5532 6192
5533 \begin{itemize} 6193 \begin{itemize}
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$. 6194 \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$.
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$. 6195 \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$.
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$. 6196 \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$.
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$. 6197 \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$.
5538 \end{itemize} 6198 \end{itemize}
5539 6199
6200 \LMHash{}
5540 Otherwise, let $NS = NS_n$. 6201 Otherwise, let $NS = NS_n$.
5541 It is a compile-time error if the current library declares a top-level member na med $p$. 6202 It is a compile-time error if the current library declares a top-level member na med $p$.
5542 6203
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 6204 % 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
5544 % either. After all, p isn't actually available as a stand alone name. 6205 % either. After all, p isn't actually available as a stand alone name.
5545 6206
6207 \LMHash{}
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: 6208 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:
5547 \begin{itemize} 6209 \begin{itemize}
5548 \item 6210 \item
5549 a top-level declaration with the name $k$ exists in $L$, OR 6211 a top-level declaration with the name $k$ exists in $L$, OR
5550 \item a prefix clause of the form \AS{} $k$ is used in $L$. 6212 \item a prefix clause of the form \AS{} $k$ is used in $L$.
5551 \end{itemize} 6213 \end{itemize}
5552 6214
5553 \rationale{The greatly increases the chance that a member can be added to a libr ary without breaking its importers.} 6215 \rationale{The greatly increases the chance that a member can be added to a libr ary without breaking its importers.}
5554 6216
6217 \LMHash{}
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 6218 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
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: 6219 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:
5557 6220
5558 %an import of a system library and an import of a non-system library: 6221 %an import of a system library and an import of a non-system library:
5559 \begin{itemize} 6222 \begin{itemize}
5560 \item The import of $L_1$ is implicitly extended by a \code{\HIDE{} $N$} clause. 6223 \item The import of $L_1$ is implicitly extended by a \code{\HIDE{} $N$} clause.
5561 \item A static warning is issued. 6224 \item A static warning is issued.
5562 \end{itemize} 6225 \end{itemize}
5563 6226
5564 \rationale { 6227 \rationale {
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. 6228 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.
5566 6229
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. 6230 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.
5568 } 6231 }
5569 6232
6233 \LMHash{}
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: 6234 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:
5571 \begin{itemize} 6235 \begin{itemize}
5572 \item A static warning occurs. 6236 \item A static warning occurs.
5573 \item If $N$ is referenced as a function, getter or setter, a \code{NoSuchMethod Error} is thrown. 6237 \item If $N$ is referenced as a function, getter or setter, a \code{NoSuchMethod Error} is thrown.
5574 \item If $N$ is referenced as a type, it is treated as a malformed type. 6238 \item If $N$ is referenced as a type, it is treated as a malformed type.
5575 6239
5576 \end{itemize} 6240 \end{itemize}
5577 6241
6242 \LMHash{}
5578 We say that the namespace $NS$ {\em has been imported into} $L$. 6243 We say that the namespace $NS$ {\em has been imported into} $L$.
5579 6244
5580 \commentary{ 6245 \commentary{
5581 It is neither an error nor a warning if $N$ is introduced by two or more import s but never referred to. 6246 It is neither an error nor a warning if $N$ is introduced by two or more import s but never referred to.
5582 } 6247 }
5583 6248
5584 \rationale{ 6249 \rationale{
5585 The policy above makes libraries more robust in the face of additions made to th eir imports. 6250 The policy above makes libraries more robust in the face of additions made to th eir imports.
5586 6251
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. 6252 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.
5588 6253
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. 6254 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.
5590 6255
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. 6256 %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.
5592 } 6257 }
5593 6258
6259 \LMHash{}
5594 It is a static warning to import two different libraries with the same name. 6260 It is a static warning to import two different libraries with the same name.
5595 6261
5596 \commentary{ 6262 \commentary{
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. 6263 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.
5598 } 6264 }
5599 6265
5600 \commentary{Note that no errors or warnings are given if one hides or shows a na me that is not in a namespace.} 6266 \commentary{Note that no errors or warnings are given if one hides or shows a na me that is not in a namespace.}
5601 \rationale{ 6267 \rationale{
5602 This prevents situations where removing a name from a library would cause breaka ge of a client library. 6268 This prevents situations where removing a name from a library would cause breaka ge of a client library.
5603 } 6269 }
5604 6270
6271 \LMHash{}
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 6272 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
5606 6273
5607 \code{\IMPORT{} `dart:core';} 6274 \code{\IMPORT{} `dart:core';}
5608 6275
5609 unless the importing library explicitly imports \code{dart:core}. 6276 unless the importing library explicitly imports \code{dart:core}.
5610 6277
5611 \commentary{ 6278 \commentary{
5612 Any import of \code{dart:core}, even if restricted via \SHOW{}, \HIDE{} or \AS{} , preempts the automatic import. 6279 Any import of \code{dart:core}, even if restricted via \SHOW{}, \HIDE{} or \AS{} , preempts the automatic import.
5613 } 6280 }
5614 6281
5615 \rationale{ 6282 \rationale{
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. 6283 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.
5617 } 6284 }
5618 6285
5619 \subsection{Exports} 6286 \subsection{Exports}
5620 \label{exports} 6287 \LMLabel{exports}
5621 6288
6289 \LMHash{}
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}. 6290 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}.
5623 6291
5624 \begin{grammar} 6292 \begin{grammar}
5625 {\bf libraryExport:} 6293 {\bf libraryExport:}
5626 metadata \EXPORT{} uri combinator* `{\escapegrammar ;}' 6294 metadata \EXPORT{} uri combinator* `{\escapegrammar ;}'
5627 . 6295 .
5628 \end{grammar} 6296 \end{grammar}
5629 6297
6298 \LMHash{}
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. 6299 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.
5631 6300
6301 \LMHash{}
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. 6302 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.
5633 6303
6304 \LMHash{}
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}. 6305 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}.
5635 6306
6307 \LMHash{}
5636 Let $E$ be an export directive that refers to a URI via the string $s_1$. Evalua tion of $E$ proceeds as follows: 6308 Let $E$ be an export directive that refers to a URI via the string $s_1$. Evalua tion of $E$ proceeds as follows:
5637 6309
6310 \LMHash{}
5638 First, 6311 First,
5639 6312
5640 \begin{itemize} 6313 \begin{itemize}
5641 \item 6314 \item
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$. 6315 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$.
5643 \item Otherwise, the contents of the URI denoted by $s_1$ have been compiled int o a library $B$ within the current isolate. 6316 \item Otherwise, the contents of the URI denoted by $s_1$ have been compiled int o a library $B$ within the current isolate.
5644 \end{itemize} 6317 \end{itemize}
5645 6318
5646 6319
6320 \LMHash{}
5647 Let $NS_0$ be the exported namespace of $B$. Then, for each combinator clause $C _i, i \in 1..n$ in $E$: 6321 Let $NS_0$ be the exported namespace of $B$. Then, for each combinator clause $C _i, i \in 1..n$ in $E$:
5648 \begin{itemize} 6322 \begin{itemize}
5649 \item If $C_i$ is of the form \code{\SHOW{} $id_1, \ldots, id_k$} then let 6323 \item If $C_i$ is of the form \code{\SHOW{} $id_1, \ldots, id_k$} then let
5650 6324
5651 $NS_i = \SHOW{}([id_1, \ldots, id_k], NS_{i-1}$). 6325 $NS_i = \SHOW{}([id_1, \ldots, id_k], NS_{i-1}$).
5652 \item If $C_i$ is of the form \code{\HIDE{} $id_1, \ldots, id_k$} 6326 \item If $C_i$ is of the form \code{\HIDE{} $id_1, \ldots, id_k$}
5653 6327
5654 then let $NS_i = \HIDE{}([id_1, \ldots, id_k], NS_{i-1}$). 6328 then let $NS_i = \HIDE{}([id_1, \ldots, id_k], NS_{i-1}$).
5655 \end{itemize} 6329 \end{itemize}
5656 6330
6331 \LMHash{}
5657 For each 6332 For each
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$. 6333 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$.
5659 6334
6335 \LMHash{}
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: 6336 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:
5661 %an export of a system library and an export of a non-system library: 6337 %an export of a system library and an export of a non-system library:
5662 \begin{itemize} 6338 \begin{itemize}
5663 \item The export of $L_1$ is implicitly extended by a \code{\HIDE{} $N$} clause. 6339 \item The export of $L_1$ is implicitly extended by a \code{\HIDE{} $N$} clause.
5664 \item A static warning is issued. 6340 \item A static warning is issued.
5665 \end{itemize} 6341 \end{itemize}
5666 6342
5667 \rationale{ 6343 \rationale{
5668 See the discussion in section \ref{imports} for the reasoning behind this rule. 6344 See the discussion in section \ref{imports} for the reasoning behind this rule.
5669 } 6345 }
5670 6346
6347 \LMHash{}
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$. 6348 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$.
5672 6349
6350 \LMHash{}
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. 6351 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.
5674 6352
5675 6353
5676 6354
5677 \subsection{Parts} 6355 \subsection{Parts}
5678 \label{parts} 6356 \LMLabel{parts}
5679 6357
6358 \LMHash{}
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. 6359 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.
5681 6360
6361 \LMHash{}
5682 A {\em part directive} specifies a URI where a Dart compilation unit that should be incorporated into the current library may be found. 6362 A {\em part directive} specifies a URI where a Dart compilation unit that should be incorporated into the current library may be found.
5683 6363
5684 \begin{grammar} 6364 \begin{grammar}
5685 {\bf partDirective:} 6365 {\bf partDirective:}
5686 metadata \PART{} uri `{\escapegrammar ;}' 6366 metadata \PART{} uri `{\escapegrammar ;}'
5687 . 6367 .
5688 6368
5689 {\bf partHeader:} 6369 {\bf partHeader:}
5690 metadata \PART{} \OF{} identifier (`{\escapegrammar .}' identifier)* `{\es capegrammar ;}' 6370 metadata \PART{} \OF{} identifier (`{\escapegrammar .}' identifier)* `{\es capegrammar ;}'
5691 . 6371 .
5692 {\bf partDeclaration:} 6372 {\bf partDeclaration:}
5693 partHeader topLevelDefinition* EOF 6373 partHeader topLevelDefinition* EOF
5694 . 6374 .
5695 \end{grammar} 6375 \end{grammar}
5696 6376
6377 \LMHash{}
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. 6378 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.
5698 6379
6380 \LMHash{}
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. 6381 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.
5700 6382
5701 \subsection{Scripts} 6383 \subsection{Scripts}
5702 \label{scripts} 6384 \LMLabel{scripts}
5703 6385
6386 \LMHash{}
5704 A {\em script} is a library whose exported namespace (\ref{exports}) includes a top-level function \code{main}. 6387 A {\em script} is a library whose exported namespace (\ref{exports}) includes a top-level function \code{main}.
5705 A script $S$ may be executed as follows: 6388 A script $S$ may be executed as follows:
5706 6389
6390 \LMHash{}
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: 6391 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:
5708 \begin{enumerate} 6392 \begin{enumerate}
5709 \item An object whose runtime type implements \code{List$<$String$>$}. 6393 \item An object whose runtime type implements \code{List$<$String$>$}.
5710 \item The initial message of the current isolate $i$ as determined by the invoca tion of \code{Isolate.spawnUri} that spawned $i$. 6394 \item The initial message of the current isolate $i$ as determined by the invoca tion of \code{Isolate.spawnUri} that spawned $i$.
5711 \end{enumerate} 6395 \end{enumerate}
5712 6396
6397 \LMHash{}
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. 6398 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.
5714 6399
5715 \commentary { 6400 \commentary {
5716 Note that if \code{main} requires more than two arguments, a run time error will occur. 6401 Note that if \code{main} requires more than two arguments, a run time error will occur.
5717 } 6402 }
5718 6403
5719 \rationale{ 6404 \rationale{
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. 6405 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.
5721 } 6406 }
5722 6407
5723 \commentary { 6408 \commentary {
5724 A Dart program will typically be executed by executing a script. 6409 A Dart program will typically be executed by executing a script.
5725 } 6410 }
5726 6411
5727 \subsection{URIs} 6412 \subsection{URIs}
5728 \label{uris} 6413 \LMLabel{uris}
5729 6414
6415 \LMHash{}
5730 URIs are specified by means of string literals: 6416 URIs are specified by means of string literals:
5731 6417
5732 \begin{grammar} 6418 \begin{grammar}
5733 {\bf uri:} 6419 {\bf uri:}
5734 stringLiteral 6420 stringLiteral
5735 . 6421 .
5736 \end{grammar} 6422 \end{grammar}
5737 6423
6424 \LMHash{}
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. 6425 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.
5739 6426
6427 \LMHash{}
5740 This specification does not discuss the interpretation of URIs, with the followi ng exceptions. 6428 This specification does not discuss the interpretation of URIs, with the followi ng exceptions.
5741 6429
5742 \rationale{ 6430 \rationale{
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. 6431 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.
5744 } 6432 }
5745 6433
6434 \LMHash{}
5746 A URI of the form \code{dart:$s$} is interpreted as a reference to a system libr ary (\ref{imports}) $s$. 6435 A URI of the form \code{dart:$s$} is interpreted as a reference to a system libr ary (\ref{imports}) $s$.
5747 6436
6437 \LMHash{}
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. 6438 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.
5749 6439
5750 \commentary{ 6440 \commentary{
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. 6441 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.
5752 } 6442 }
5753 6443
5754 \rationale{ 6444 \rationale{
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). 6445 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).
5756 } 6446 }
5757 6447
6448 \LMHash{}
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. 6449 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.
5759 6450
5760 \commentary{This means it is dependent on the embedder.} 6451 \commentary{This means it is dependent on the embedder.}
5761 6452
5762 6453
5763 \section{Types} 6454 \section{Types}
5764 \label{types} 6455 \LMLabel{types}
5765 6456
6457 \LMHash{}
5766 Dart supports optional typing based on interface types. 6458 Dart supports optional typing based on interface types.
5767 6459
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. 6460 \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.
5769 } 6461 }
5770 6462
5771 \subsection{Static Types} 6463 \subsection{Static Types}
5772 \label{staticTypes} 6464 \LMLabel{staticTypes}
5773 6465
6466 \LMHash{}
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. 6467 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.
5775 6468
5776 \begin{grammar} 6469 \begin{grammar}
5777 {\bf type:} 6470 {\bf type:}
5778 typeName typeArguments? 6471 typeName typeArguments?
5779 . 6472 .
5780 6473
5781 {\bf typeName:} 6474 {\bf typeName:}
5782 qualified 6475 qualified
5783 . 6476 .
5784 6477
5785 {\bf typeArguments:} 6478 {\bf typeArguments:}
5786 '<' typeList '>' 6479 '<' typeList '>'
5787 . 6480 .
5788 6481
5789 {\bf typeList:} 6482 {\bf typeList:}
5790 type (',' type)* 6483 type (',' type)*
5791 . 6484 .
5792 \end{grammar} 6485 \end{grammar}
5793 6486
6487 \LMHash{}
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: 6488 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:
5795 \begin{itemize} 6489 \begin{itemize}
5796 \item Running the static checker on a program $P$ is not required for compiling and running $P$. 6490 \item Running the static checker on a program $P$ is not required for compiling and running $P$.
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. 6491 \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.
5798 \end{itemize} 6492 \end{itemize}
5799 6493
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. 6494 \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.
5801 } 6495 }
5802 6496
5803 %\Q{Should we do something with respect to non-nullable types?} 6497 %\Q{Should we do something with respect to non-nullable types?}
5804 6498
6499 \LMHash{}
5805 A type $T$ is {\em malformed} iff: 6500 A type $T$ is {\em malformed} iff:
5806 \begin{itemize} 6501 \begin{itemize}
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. 6502 \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.
5808 \item $T$ denotes a type variable in the enclosing lexical scope, but occurs in the signature or body of a static member. 6503 \item $T$ denotes a type variable in the enclosing lexical scope, but occurs in the signature or body of a static member.
5809 \item $T$ is a parameterized type of the form $G<S_1, \ldots , S_n>$, and $G$ i s malformed. 6504 \item $T$ is a parameterized type of the form $G<S_1, \ldots , S_n>$, and $G$ i s malformed.
5810 \item $T$ denotes declarations that were imported from multiple imports clauses. 6505 \item $T$ denotes declarations that were imported from multiple imports clauses.
5811 %Either $G$ or $S_i, i \in 1.. n$ are malformed. 6506 %Either $G$ or $S_i, i \in 1.. n$ are malformed.
5812 % \item $G$ is not a generic type with $n$ type parameters. 6507 % \item $G$ is not a generic type with $n$ type parameters.
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$. 6508 % \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$.
5814 % \end{itemize} 6509 % \end{itemize}
5815 \end{itemize} 6510 \end{itemize}
5816 6511
6512 \LMHash{}
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. 6513 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.
5818 6514
5819 \rationale{ 6515 \rationale{
5820 This ensures that the developer is spared a series of cascading warnings as the malformed type interacts with other types. 6516 This ensures that the developer is spared a series of cascading warnings as the malformed type interacts with other types.
5821 } 6517 }
5822 6518
6519 \LMHash{}
5823 A type $T$ is {\em deferred} iff it is of the form $p.T$ where $p$ is a deferred prefix. 6520 A type $T$ is {\em deferred} iff it is of the form $p.T$ where $p$ is a deferred prefix.
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. 6521 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.
5825 6522
5826 6523
5827 \subsubsection{Type Promotion} 6524 \subsubsection{Type Promotion}
5828 \label{typePromotion} 6525 \LMLabel{typePromotion}
5829 6526
6527 \LMHash{}
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. 6528 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.
5831 6529
6530 \LMHash{}
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}). 6531 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}).
5833 6532
6533 \LMHash{}
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}). 6534 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}).
5835 6535
5836 6536
5837 \subsection{Dynamic Type System} 6537 \subsection{Dynamic Type System}
5838 \label{dynamicTypeSystem} 6538 \LMLabel{dynamicTypeSystem}
5839 6539
6540 \LMHash{}
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. 6541 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.
5841 6542
5842 \commentary{ 6543 \commentary{
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. 6544 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.
5844 6545
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. 6546 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.
5846 6547
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. 6548 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.
5848 6549
5849 } 6550 }
5850 6551
5851 %It is a run-time type error to access an undeclared type outside . 6552 %It is a run-time type error to access an undeclared type outside .
5852 6553
6554 \LMHash{}
5853 %It is a dynamic type error if a malformed type is used in a subtype test. 6555 %It is a dynamic type error if a malformed type is used in a subtype test.
5854 In checked mode, it is a dynamic type error if a deferred, malformed or malbound ed (\ref{parameterizedTypes}) 6556 In checked mode, it is a dynamic type error if a deferred, malformed or malbound ed (\ref{parameterizedTypes})
5855 type is used in a subtype test. 6557 type is used in a subtype test.
5856 6558
5857 %In production mode, an undeclared type is treated as an instance of type \DYNAM IC{}. 6559 %In production mode, an undeclared type is treated as an instance of type \DYNAM IC{}.
5858 6560
5859 \commentary{Consider the following program} 6561 \commentary{Consider the following program}
5860 6562
5861 \begin{dartCode} 6563 \begin{dartCode}
5862 \TYPEDEF{} F(bool x); 6564 \TYPEDEF{} F(bool x);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
5924 bool b = x is I; 6626 bool b = x is I;
5925 \end{dartCode} 6627 \end{dartCode}
5926 6628
5927 \commentary{ 6629 \commentary{
5928 \code{b} is bound to \TRUE, but in checked mode the second line causes a dynamic type error. 6630 \code{b} is bound to \TRUE, but in checked mode the second line causes a dynamic type error.
5929 } 6631 }
5930 6632
5931 6633
5932 6634
5933 \subsection{Type Declarations} 6635 \subsection{Type Declarations}
5934 \label{typeDeclarations} 6636 \LMLabel{typeDeclarations}
5935 6637
5936 \subsubsection{Typedef} 6638 \subsubsection{Typedef}
5937 \label{typedef} 6639 \LMLabel{typedef}
5938 6640
6641 \LMHash{}
5939 A {\em type alias} declares a name for a type expression. 6642 A {\em type alias} declares a name for a type expression.
5940 6643
5941 6644
5942 \begin{grammar} 6645 \begin{grammar}
5943 6646
5944 {\bf typeAlias:} 6647 {\bf typeAlias:}
5945 metadata \TYPEDEF{} typeAliasBody 6648 metadata \TYPEDEF{} typeAliasBody
5946 . 6649 .
5947 6650
5948 {\bf typeAliasBody:} 6651 {\bf typeAliasBody:}
5949 functionTypeAlias 6652 functionTypeAlias
5950 . 6653 .
5951 6654
5952 {\bf functionTypeAlias:} 6655 {\bf functionTypeAlias:}
5953 functionPrefix typeParameters? formalParameterList '{\escapegrammar ;}' 6656 functionPrefix typeParameters? formalParameterList '{\escapegrammar ;}'
5954 . 6657 .
5955 6658
5956 {\bf functionPrefix:} 6659 {\bf functionPrefix:}
5957 returnType? identifier 6660 returnType? identifier
5958 . 6661 .
5959 6662
5960 \end{grammar} 6663 \end{grammar}
5961 6664
6665 \LMHash{}
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{}. 6666 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{}.
5963 6667
6668 \LMHash{}
5964 It is a compile-time error if any default values are specified in the signature of a function type alias. 6669 It is a compile-time error if any default values are specified in the signature of a function type alias.
5965 %A typedef may only refer to itself via the bounds of its generic parameters. 6670 %A typedef may only refer to itself via the bounds of its generic parameters.
5966 Any self reference in a typedef, either directly, or recursively via another ty pedef, is a compile time error. 6671 Any self reference in a typedef, either directly, or recursively via another ty pedef, is a compile time error.
5967 %via a chain of references that does not include a class declaration. 6672 %via a chain of references that does not include a class declaration.
5968 6673
5969 6674
5970 6675
5971 \subsection{Interface Types} 6676 \subsection{Interface Types}
5972 \label{interfaceTypes} 6677 \LMLabel{interfaceTypes}
5973 6678
6679 \LMHash{}
5974 The implicit interface of class $I$ is a direct supertype of the implicit interf ace of class $J$ iff: 6680 The implicit interface of class $I$ is a direct supertype of the implicit interf ace of class $J$ iff:
5975 \begin{itemize} 6681 \begin{itemize}
5976 \item 6682 \item
5977 If $I$ is \code{Object}, and $J$ has no \EXTENDS{} clause% and no interface inje ction declaration has extended $J. 6683 If $I$ is \code{Object}, and $J$ has no \EXTENDS{} clause% and no interface inje ction declaration has extended $J.
5978 \item 6684 \item
5979 If $I$ is listed in the \EXTENDS{} clause of $J$% or an interface injection decl aration has extended $J$ with $I$ 6685 If $I$ is listed in the \EXTENDS{} clause of $J$% or an interface injection decl aration has extended $J$ with $I$
5980 . 6686 .
5981 \item If $I$ is listed in the \IMPLEMENTS{} clause of $J$ 6687 \item If $I$ is listed in the \IMPLEMENTS{} clause of $J$
5982 6688
5983 \item If $I$ is listed in the \WITH{} clause of $J$ 6689 \item If $I$ is listed in the \WITH{} clause of $J$
5984 6690
5985 \item If $J$ is a mixin application (\ref{mixinApplication}) of the mixin of $I$ . 6691 \item If $J$ is a mixin application (\ref{mixinApplication}) of the mixin of $I$ .
5986 \end{itemize} 6692 \end{itemize}
5987 6693
5988 \commentary{ 6694 \commentary{
5989 6695
5990 6696
5991 } 6697 }
5992 6698
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. 6699 %\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.
5994 %} 6700 %}
5995 6701
6702 \LMHash{}
5996 A type $T$ is more specific than a type $S$, written $T << S$, if one of the fo llowing conditions is met: 6703 A type $T$ is more specific than a type $S$, written $T << S$, if one of the fo llowing conditions is met:
5997 \begin{itemize} 6704 \begin{itemize}
5998 \item $T$ is $S$. 6705 \item $T$ is $S$.
5999 \item T is $\bot$. 6706 \item T is $\bot$.
6000 \item S is \DYNAMIC{}. 6707 \item S is \DYNAMIC{}.
6001 \item $S$ is a direct supertype of $T$. 6708 \item $S$ is a direct supertype of $T$.
6002 \item $T$ is a type parameter and $S$ is the upper bound of $T$. 6709 \item $T$ is a type parameter and $S$ is the upper bound of $T$.
6003 \item $T$ is a type parameter and $S$ is \cd{Object}. 6710 \item $T$ is a type parameter and $S$ is \cd{Object}.
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: 6711 \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:
6005 $T_i << S_i, 1 \le i \le n$ 6712 $T_i << S_i, 1 \le i \le n$
6006 \item $T$ and $S$ are both function types, and $T << S$ under the rules of secti on \ref{functionTypes}. 6713 \item $T$ and $S$ are both function types, and $T << S$ under the rules of secti on \ref{functionTypes}.
6007 \item $T$ is a function type and $S$ is \cd{Function}. 6714 \item $T$ is a function type and $S$ is \cd{Function}.
6008 \item $T << U$ and $U << S$. 6715 \item $T << U$ and $U << S$.
6009 \end{itemize} 6716 \end{itemize}
6010 6717
6718 \LMHash{}
6011 $<<$ is a partial order on types. 6719 $<<$ is a partial order on types.
6012 $T$ is a subtype of $S$, written $T <: S$, iff $[\bot/\DYNAMIC{}]T << S$. 6720 $T$ is a subtype of $S$, written $T <: S$, iff $[\bot/\DYNAMIC{}]T << S$.
6013 6721
6014 \rationale{ 6722 \rationale{
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: 6723 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:
6016 $List <: List<String>$ and $List<int> <: List$, but $List<int>$ is not a subtype of $List<String>$. 6724 $List <: List<String>$ and $List<int> <: List$, but $List<int>$ is not a subtype of $List<String>$.
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. 6725 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.
6018 } 6726 }
6019 6727
6728 \LMHash{}
6020 $S$ is a supertype of $T$, written $S :> T$, iff $T$ is a subtype of $S$. 6729 $S$ is a supertype of $T$, written $S :> T$, iff $T$ is a subtype of $S$.
6021 6730
6022 \commentary{The supertypes of an interface are its direct supertypes and their s upertypes. } 6731 \commentary{The supertypes of an interface are its direct supertypes and their s upertypes. }
6023 6732
6733 \LMHash{}
6024 An interface type $T$ may be assigned to a type $S$, written $T \Longleftrighta rrow S$, iff either $T <: S$ or $S <: T$. 6734 An interface type $T$ may be assigned to a type $S$, written $T \Longleftrighta rrow S$, iff either $T <: S$ or $S <: T$.
6025 6735
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. 6736 \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.
6027 6737
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. 6738 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.
6029 } 6739 }
6030 6740
6031 \subsection{Function Types} 6741 \subsection{Function Types}
6032 \label{functionTypes} 6742 \LMLabel{functionTypes}
6033 6743
6744 \LMHash{}
6034 Function types come in two variants: 6745 Function types come in two variants:
6035 \begin{enumerate} 6746 \begin{enumerate}
6036 \item 6747 \item
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$. 6748 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$.
6038 \item 6749 \item
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$. 6750 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$.
6040 \end{enumerate} 6751 \end{enumerate}
6041 6752
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: 6753 %$(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:
6043 %\begin{enumerate} 6754 %\begin{enumerate}
6044 %\item Either 6755 %\item Either
6045 %\begin{itemize} 6756 %\begin{itemize}
6046 %\item $S$ is \VOID{}, Or 6757 %\item $S$ is \VOID{}, Or
6047 %\item $T \Longleftrightarrow S$. 6758 %\item $T \Longleftrightarrow S$.
6048 %\end{itemize} 6759 %\end{itemize}
6049 %\item$ \forall i \in 1 .. n, T_i \Longleftrightarrow S_i$. 6760 %\item$ \forall i \in 1 .. n, T_i \Longleftrightarrow S_i$.
6050 %\end{enumerate} 6761 %\end{enumerate}
6051 6762
6763 \LMHash{}
6052 %A function type $(T_1, \ldots T_n, [T_{n+1} \ldots, T_{n+k}]) \rightarrow T$ i s a subtype of the 6764 %A function type $(T_1, \ldots T_n, [T_{n+1} \ldots, T_{n+k}]) \rightarrow T$ i s a subtype of the
6053 % the line below revises the rule to be more liberal 6765 % the line below revises the rule to be more liberal
6054 A function type $(T_1, \ldots T_{k}, [T_{k+1} \ldots, T_{n+m}]) \rightarrow T$ is a subtype of the 6766 A function type $(T_1, \ldots T_{k}, [T_{k+1} \ldots, T_{n+m}]) \rightarrow T$ is a subtype of the
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: 6767 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:
6056 \begin{enumerate} 6768 \begin{enumerate}
6057 \item Either 6769 \item Either
6058 \begin{itemize} 6770 \begin{itemize}
6059 \item $S$ is \VOID{}, Or 6771 \item $S$ is \VOID{}, Or
6060 \item $T \Longleftrightarrow S$. 6772 \item $T \Longleftrightarrow S$.
6061 \end{itemize} 6773 \end{itemize}
6062 \item $\forall i \in 1 .. n, T_i \Longleftrightarrow S_i$. 6774 \item $\forall i \in 1 .. n, T_i \Longleftrightarrow S_i$.
6063 \end{enumerate} 6775 \end{enumerate}
6064 6776
6065 6777
6778 \LMHash{}
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: 6779 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:
6067 \begin{enumerate} 6780 \begin{enumerate}
6068 \item Either 6781 \item Either
6069 \begin{itemize} 6782 \begin{itemize}
6070 \item $S$ is \VOID{}, Or 6783 \item $S$ is \VOID{}, Or
6071 \item $T \Longleftrightarrow S$. 6784 \item $T \Longleftrightarrow S$.
6072 \end{itemize} 6785 \end{itemize}
6073 \item $\forall i \in 1 .. n, T_i \Longleftrightarrow S_i$. 6786 \item $\forall i \in 1 .. n, T_i \Longleftrightarrow S_i$.
6074 \item $k \ge m$ and $y_i \in \{x_1, \ldots, x_k\}, i \in 1 .. m$. 6787 \item $k \ge m$ and $y_i \in \{x_1, \ldots, x_k\}, i \in 1 .. m$.
6075 %\{x_1, \ldots, x_k\}$ is a superset of $\{y_1, \ldots, y_m\}$. 6788 %\{x_1, \ldots, x_k\}$ is a superset of $\{y_1, \ldots, y_m\}$.
6076 \item For all $y_i \in \{y_1, \ldots, y_m\}, y_i = x_j \Rightarrow T_j \Longlef trightarrow S_i$ 6789 \item For all $y_i \in \{y_1, \ldots, y_m\}, y_i = x_j \Rightarrow T_j \Longlef trightarrow S_i$
6077 \end{enumerate} 6790 \end{enumerate}
6078 6791
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$. 6792 %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$.
6080 6793
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?} 6794 %\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?}
6082 6795
6083 %We write $(T_1, \ldots, T_n) \rightarrow T$ as a shorthand for the type $(T_1, \ldots, T_n, []) \rightarrow T$. 6796 %We write $(T_1, \ldots, T_n) \rightarrow T$ as a shorthand for the type $(T_1, \ldots, T_n, []) \rightarrow T$.
6084 6797
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. 6798 %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.
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$. 6799 % 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$.
6087 6800
6801 \LMHash{}
6088 In addition, the following subtype rules apply: 6802 In addition, the following subtype rules apply:
6089 6803
6090 6804
6091 $(T_1, \ldots, T_n, []) \rightarrow T <: (T_1, \ldots, T_n) \rightarrow T$. 6805 $(T_1, \ldots, T_n, []) \rightarrow T <: (T_1, \ldots, T_n) \rightarrow T$.
6092 6806
6093 $(T_1, \ldots, T_n) \rightarrow T <: (T_1, \ldots, T_n, \{\}) \rightarrow T$. 6807 $(T_1, \ldots, T_n) \rightarrow T <: (T_1, \ldots, T_n, \{\}) \rightarrow T$.
6094 6808
6095 $(T_1, \ldots, T_n, \{\}) \rightarrow T <: (T_1, \ldots, T_n) \rightarrow T$. 6809 $(T_1, \ldots, T_n, \{\}) \rightarrow T <: (T_1, \ldots, T_n) \rightarrow T$.
6096 6810
6097 $(T_1, \ldots, T_n) \rightarrow T <: (T_1, \ldots, T_n, []) \rightarrow T$. 6811 $(T_1, \ldots, T_n) \rightarrow T <: (T_1, \ldots, T_n, []) \rightarrow T$.
6098 6812
6099 \rationale{ 6813 \rationale{
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. 6814 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.
6101 } 6815 }
6102 6816
6817 \LMHash{}
6103 A function type $T$ may be assigned to a function type $S$, written $T \Longlef trightarrow S$, iff $T <: S$. 6818 A function type $T$ may be assigned to a function type $S$, written $T \Longlef trightarrow S$, iff $T <: S$.
6104 6819
6820 \LMHash{}
6105 % ensure that Object and dynamic may be assign dot a function type 6821 % ensure that Object and dynamic may be assign dot a function type
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}. 6822 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}.
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()}. 6823 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()}.
6108 6824
6109 6825
6110 6826
6111 6827
6112 %\commentary{Need to specify how a function values dynamic type is derived from its static signature.} 6828 %\commentary{Need to specify how a function values dynamic type is derived from its static signature.}
6113 6829
6830 \LMHash{}
6114 A function type $(T_1, \ldots T_{k}, [T_{k+1} \ldots, T_{n+m}]) \rightarrow T$ is a more specific than the 6831 A function type $(T_1, \ldots T_{k}, [T_{k+1} \ldots, T_{n+m}]) \rightarrow T$ is a more specific than the
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: 6832 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:
6116 \begin{enumerate} 6833 \begin{enumerate}
6117 \item Either 6834 \item Either
6118 \begin{itemize} 6835 \begin{itemize}
6119 \item $S$ is \VOID{}, Or 6836 \item $S$ is \VOID{}, Or
6120 \item $T << S$. 6837 \item $T << S$.
6121 \end{itemize} 6838 \end{itemize}
6122 \item $\forall i \in 1 .. n, T_i << S_i$. 6839 \item $\forall i \in 1 .. n, T_i << S_i$.
6123 \end{enumerate} 6840 \end{enumerate}
6124 6841
6125 6842
6843 \LMHash{}
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: 6844 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:
6127 \begin{enumerate} 6845 \begin{enumerate}
6128 \item Either 6846 \item Either
6129 \begin{itemize} 6847 \begin{itemize}
6130 \item $S$ is \VOID{}, Or 6848 \item $S$ is \VOID{}, Or
6131 \item $T << S$. 6849 \item $T << S$.
6132 \end{itemize} 6850 \end{itemize}
6133 \item $\forall i \in 1 .. n, T_i << S_i$. 6851 \item $\forall i \in 1 .. n, T_i << S_i$.
6134 \item $k \ge m$ and $y_i \in \{x_1, \ldots, x_k\}, i \in 1 .. m$. 6852 \item $k \ge m$ and $y_i \in \{x_1, \ldots, x_k\}, i \in 1 .. m$.
6135 %\{x_1, \ldots, x_k\}$ is a superset of $\{y_1, \ldots, y_m\}$. 6853 %\{x_1, \ldots, x_k\}$ is a superset of $\{y_1, \ldots, y_m\}$.
6136 \item For all $y_i \in \{y_1, \ldots, y_m\}, y_i = x_j \Rightarrow T_j << S_i$ 6854 \item For all $y_i \in \{y_1, \ldots, y_m\}, y_i = x_j \Rightarrow T_j << S_i$
6137 \end{enumerate} 6855 \end{enumerate}
6138 6856
6857 \LMHash{}
6139 Furthermore, if $F$ is a function type, $F << \code{Function}$. 6858 Furthermore, if $F$ is a function type, $F << \code{Function}$.
6140 6859
6141 6860
6142 \subsection{Type \DYNAMIC{}} 6861 \subsection{Type \DYNAMIC{}}
6143 \label{typeDynamic} 6862 \LMLabel{typeDynamic}
6144 6863
6864 \LMHash{}
6145 The type \DYNAMIC{} denotes the unknown type. 6865 The type \DYNAMIC{} denotes the unknown type.
6146 6866
6867 \LMHash{}
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. 6868 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.
6148 6869
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{}>$. 6870 \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{}>$.
6150 } 6871 }
6151 6872
6873 \LMHash{}
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{}. 6874 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{}.
6153 Type \DYNAMIC{} has properties for every possible identifier. These properties all have type \DYNAMIC{}. 6875 Type \DYNAMIC{} has properties for every possible identifier. These properties all have type \DYNAMIC{}.
6154 6876
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. 6877 \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.
6156 6878
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: 6879 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:
6158 6880
6159 (1) \code{typedAPI(G\lt{String}\gt g)\{...\}} 6881 (1) \code{typedAPI(G\lt{String}\gt g)\{...\}}
6160 6882
6161 6883
6162 (2) \code{typedAPI(new G()); } 6884 (2) \code{typedAPI(new G()); }
6163 6885
6164 6886
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 6887 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
6166 6888
6167 (3) \code{typedAPI(new G\lt{String}\gt());} 6889 (3) \code{typedAPI(new G\lt{String}\gt());}
6168 6890
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. 6891 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.
6170 6892
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. 6893 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.
6172 } 6894 }
6173 6895
6896 \LMHash{}
6174 The name \DYNAMIC{} denotes a \cd{Type} object even though \DYNAMIC{} is not a c lass. 6897 The name \DYNAMIC{} denotes a \cd{Type} object even though \DYNAMIC{} is not a c lass.
6175 6898
6176 %\rationale { 6899 %\rationale {
6177 %Type objects reify the runtime types of instances. No instance ever has type \D YNAMIC{}. 6900 %Type objects reify the runtime types of instances. No instance ever has type \D YNAMIC{}.
6178 %} 6901 %}
6179 6902
6180 \subsection{Type Void} 6903 \subsection{Type Void}
6181 \label{typeVoid} 6904 \LMLabel{typeVoid}
6182 6905
6906 \LMHash{}
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. 6907 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.
6184 6908
6185 \commentary{ 6909 \commentary{
6186 For example, as a type argument, or as the type of a variable or parameter 6910 For example, as a type argument, or as the type of a variable or parameter
6187 6911
6188 Void is not an interface type. 6912 Void is not an interface type.
6189 6913
6190 The only subtype relations that pertain to void are therefore: 6914 The only subtype relations that pertain to void are therefore:
6191 \begin{itemize} 6915 \begin{itemize}
6192 \item 6916 \item
(...skipping 14 matching lines...) Expand all
6207 \commentary {The name \VOID{} does not denote a \cd{Type} object.} 6931 \commentary {The name \VOID{} does not denote a \cd{Type} object.}
6208 6932
6209 \rationale { 6933 \rationale {
6210 It is syntacticly illegal to use \VOID{} as an expression, and it would make no sense to do so. 6934 It is syntacticly illegal to use \VOID{} as an expression, and it would make no sense to do so.
6211 Type objects reify the runtime types of instances. No instance ever has type \VO ID{}. 6935 Type objects reify the runtime types of instances. No instance ever has type \VO ID{}.
6212 } 6936 }
6213 6937
6214 6938
6215 6939
6216 \subsection{Parameterized Types} 6940 \subsection{Parameterized Types}
6217 \label{parameterizedTypes} 6941 \LMLabel{parameterizedTypes}
6218 6942
6943 \LMHash{}
6219 A {\em parameterized type} is an invocation of a generic type declaration. 6944 A {\em parameterized type} is an invocation of a generic type declaration.
6220 6945
6946 \LMHash{}
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{}. 6947 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{}.
6222 6948
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. 6949 \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.
6224 } 6950 }
6225 6951
6952 \LMHash{}
6226 Otherwise, let 6953 Otherwise, let
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$. 6954 $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$.
6228 6955
6229 \commentary{ 6956 \commentary{
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}. 6957 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}.
6231 } 6958 }
6232 6959
6960 \LMHash{}
6233 Any use of a malbounded type gives rise to a static warning. 6961 Any use of a malbounded type gives rise to a static warning.
6234 6962
6963 \LMHash{}
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 . 6964 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 .
6236 6965
6237 6966
6238 6967
6239 6968
6240 6969
6241 \subsubsection{Actual Type of Declaration} 6970 \subsubsection{Actual Type of Declaration}
6242 \label{actualTypeOfADeclaration} 6971 \LMLabel{actualTypeOfADeclaration}
6243 6972
6973 \LMHash{}
6244 A type $T$ {\em depends on a type parameter} $U$ iff: 6974 A type $T$ {\em depends on a type parameter} $U$ iff:
6245 \begin{itemize} 6975 \begin{itemize}
6246 \item $T$ is $U$. 6976 \item $T$ is $U$.
6247 \item $T$ is a parameterized type, and one of the type arguments of $T$ depends on $U$. 6977 \item $T$ is a parameterized type, and one of the type arguments of $T$ depends on $U$.
6248 \end{itemize} 6978 \end{itemize}
6249 6979
6980 \LMHash{}
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 6981 Let $T$ be the declared type of a declaration $d$, as it appears in the program source. The {\em actual type} of $d$ is
6251 6982
6252 \begin{itemize} 6983 \begin{itemize}
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$. 6984 \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$.
6254 \item $T$ otherwise. 6985 \item $T$ otherwise.
6255 \end{itemize} 6986 \end{itemize}
6256 6987
6257 \subsubsection{Least Upper Bounds} 6988 \subsubsection{Least Upper Bounds}
6258 \label{leastUpperBounds} 6989 \LMLabel{leastUpperBounds}
6259 6990
6991 \LMHash{}
6260 % does this diverge in some cases? 6992 % does this diverge in some cases?
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$, 6993 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$,
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$. 6994 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$.
6263 6995
6996 \LMHash{}
6264 The least upper bound of \DYNAMIC{} and any type $T$ is \DYNAMIC{}. 6997 The least upper bound of \DYNAMIC{} and any type $T$ is \DYNAMIC{}.
6265 The least upper bound of \VOID{} and any type $T \ne \DYNAMIC{}$ is \VOID{}. 6998 The least upper bound of \VOID{} and any type $T \ne \DYNAMIC{}$ is \VOID{}.
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$. 6999 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$.
6267 7000
7001 \LMHash{}
6268 The least upper bound relation is symmetric and reflexive. 7002 The least upper bound relation is symmetric and reflexive.
6269 7003
6270 % Function types 7004 % Function types
6271 7005
7006 \LMHash{}
6272 The least upper bound of a function type and an interface type $T$ is the least upper bound of \cd{Function} and $T$. 7007 The least upper bound of a function type and an interface type $T$ is the least upper bound of \cd{Function} and $T$.
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: 7008 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:
6274 \begin{itemize} 7009 \begin{itemize}
6275 \item If 7010 \item If
6276 7011
6277 $F= (T_1 \ldots T_r, [T_{r+1}, \ldots, T_n]) \longrightarrow T_0$, 7012 $F= (T_1 \ldots T_r, [T_{r+1}, \ldots, T_n]) \longrightarrow T_0$,
6278 7013
6279 $G= (S_1 \ldots S_r, [S_{r+1}, \ldots, S_k]) \longrightarrow S_0$ 7014 $G= (S_1 \ldots S_r, [S_{r+1}, \ldots, S_k]) \longrightarrow S_0$
6280 7015
6281 where $k \le n$ then the least upper bound of $F$ and $G$ is 7016 where $k \le n$ then the least upper bound of $F$ and $G$ is
(...skipping 22 matching lines...) Expand all
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 7039 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
6305 the least upper bound of $F$ and $G$ is 7040 the least upper bound of $F$ and $G$ is
6306 7041
6307 $(L_1 \ldots L_r, \{ X_m$ $x_m, \ldots, X_n$ $x_n\}) \longrightarrow L_0$ 7042 $(L_1 \ldots L_r, \{ X_m$ $x_m, \ldots, X_n$ $x_n\}) \longrightarrow L_0$
6308 7043
6309 where $L_i$ is the least upper bound of $T_i$ and $S_i, i \in 0..r$ 7044 where $L_i$ is the least upper bound of $T_i$ and $S_i, i \in 0..r$
6310 \end{itemize} 7045 \end{itemize}
6311 7046
6312 7047
6313 \section{Reference} 7048 \section{Reference}
6314 \label{reference} 7049 \LMLabel{reference}
6315 7050
6316 \subsection{Lexical Rules} 7051 \subsection{Lexical Rules}
6317 \label{lexicalRules} 7052 \LMLabel{lexicalRules}
6318 7053
7054 \LMHash{}
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. 7055 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.
6320 7056
6321 \subsubsection{Reserved Words} 7057 \subsubsection{Reserved Words}
6322 \label{reservedWords} 7058 \LMLabel{reservedWords}
6323 7059
7060 \LMHash{}
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. 7061 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.
6325 7062
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{}. 7063 \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{}.
6327 7064
6328 7065
6329 7066
6330 %\Q{Unicode characters.} 7067 %\Q{Unicode characters.}
6331 7068
6332 \begin{grammar} 7069 \begin{grammar}
6333 {\bf LETTER:}`a' {\escapegrammar ..} `z'; 7070 {\bf LETTER:}`a' {\escapegrammar ..} `z';
6334 `A' {\escapegrammar ..}`Z' 7071 `A' {\escapegrammar ..}`Z'
6335 . 7072 .
6336 7073
6337 {\bf DIGIT:} 7074 {\bf DIGIT:}
6338 `0' {\escapegrammar ..} `9' 7075 `0' {\escapegrammar ..} `9'
6339 . 7076 .
6340 7077
6341 {\bf WHITESPACE:} 7078 {\bf WHITESPACE:}
6342 (`$\backslash$t' $|$ ` ' $|$ NEWLINE)+ 7079 (`$\backslash$t' $|$ ` ' $|$ NEWLINE)+
6343 . 7080 .
6344 \end{grammar} 7081 \end{grammar}
6345 7082
6346 \subsubsection{Comments} 7083 \subsubsection{Comments}
6347 \label{comments} 7084 \LMLabel{comments}
6348 7085
7086 \LMHash{}
6349 {\em Comments} are sections of program text that are used for documentation. 7087 {\em Comments} are sections of program text that are used for documentation.
6350 7088
6351 \begin{grammar}{\bf SINGLE\_LINE\_COMMENT:} 7089 \begin{grammar}{\bf SINGLE\_LINE\_COMMENT:}
6352 `//' \~{}(NEWLINE)* (NEWLINE)? 7090 `//' \~{}(NEWLINE)* (NEWLINE)?
6353 . 7091 .
6354 7092
6355 {\bf MULTI\_LINE\_COMMENT:} 7093 {\bf MULTI\_LINE\_COMMENT:}
6356 `/*' (MULTI\_LINE\_COMMENT $|$ \~{} `*/')* `*/' 7094 `/*' (MULTI\_LINE\_COMMENT $|$ \~{} `*/')* `*/'
6357 . 7095 .
6358 \end{grammar} 7096 \end{grammar}
6359 7097
7098 \LMHash{}
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. . 7099 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. .
6361 7100
7101 \LMHash{}
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. 7102 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.
6363 7103
7104 \LMHash{}
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. 7105 {\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.
6365 7106
7107 \LMHash{}
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. 7108 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.
6367 7109
7110 \LMHash{}
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. 7111 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.
6369 7112
7113 \LMHash{}
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 . 7114 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 .
6371 7115
6372 7116
6373 7117
6374 7118
6375 7119
6376 %\subsection{Grammar} 7120 %\subsection{Grammar}
6377 \subsection{Operator Precedence} 7121 \subsection{Operator Precedence}
6378 \label{operatorPrecedence} 7122 \LMLabel{operatorPrecedence}
6379 7123
7124 \LMHash{}
6380 Operator precedence is given implicitly by the grammar. 7125 Operator precedence is given implicitly by the grammar.
6381 7126
6382 \commentary{The following non-normative table may be helpful 7127 \commentary{The following non-normative table may be helpful
6383 \newline 7128 \newline
6384 7129
6385 \begin{tabular}{| r | r | r | r |} 7130 \begin{tabular}{| r | r | r | r |}
6386 \hline 7131 \hline
6387 Description & Operator & Associativity & Precedence \\ 7132 Description & Operator & Associativity & Precedence \\
6388 \hline 7133 \hline
6389 Unary postfix & ., e++, e--, e1[e2], e1() , () & None & 15 \\ 7134 Unary postfix & ., e++, e--, e1[e2], e1() , () & None & 15 \\
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
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. 7175 \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.
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 7176 \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
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. 7177 \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.
6433 \item The names of type variables are short (preferably single letter). Examples : T, S, K, V , E. 7178 \item The names of type variables are short (preferably single letter). Examples : T, S, K, V , E.
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. 7179 \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.
6435 \end{itemize} 7180 \end{itemize}
6436 } 7181 }
6437 7182
6438 7183
6439 \end{document} 7184 \end{document}
7185
7186 [Text after \end{document} is ignored, hence we do not need "%"]
7187 ----------------------------------------------------------------------
7188
7189 * On Location Markers
7190
7191 This is a description of location markers, giving some information
7192 about the underlying motivation and rationale, the actual
7193 implementation, and the relevant tool support.
7194
7195 ** What is a Location Marker?
7196
7197 In order to support more fine-grained update propagation from this
7198 language specification to artifacts that depend on it, location
7199 markers have been added. The idea is that each logical unit (section,
7200 subsection, etc) and each paragraph containing normative text should
7201 be addressable using these markers, such that source code (compilers
7202 and other tools, tests, etc.) can contain location markers, and the
7203 corresponding location in the spec may be looked up using standard
7204 document viewer search features.
7205
7206 An SHA1 hash value of the text is associated with each location
7207 marker, such that changes in the text will incur changes in this hash
7208 value. Consequently, source code in tools/tests that depend on
7209 specific parts of the spec may be flagged for revision by checking
7210 whether these hash values have changed: If a given test T depends on
7211 a paragraph with hash value V in the spec, and the search for V fails
7212 in a new version of the spec, then that paragraph has changed and T
7213 should be revisited and possible revised.
7214
7215 As a result, the search for parts of source code and similar artifacts
7216 in likely need of updates because of spec changes can be performed
7217 mechanically, which should help ensure that the conformance of all
7218 artifacts depending on this spec is maintained more easily, and hence
7219 more consistently. Note that it makes no difference whether the need
7220 for an update has arisen in a very recent version of the spec or it
7221 has existed for a long time, because the hash value just remains
7222 different as long as the text is different from what it was when the
7223 location marker was harvested from the spec.
7224
7225 ** LaTeX Commands Supporting Location Markers
7226
7227 Concretely, this is based on the commands \LMHash and \LMLabel.
7228 \LMHash{V} is used to add the text V in the margin, intended to mark
7229 a paragraph of normative text with the SHA1 hash value of the text, V.
7230 \LMLabel{L} has the effect of \label{L}, and moreover it shows the
7231 text sec:L in the margin. In order to indicate a dependency on a
7232 section or subsection an \LMLabel location marker is used, and in
7233 order to indicate a dependency on a specific paragraph, the hash value
7234 of that paragraph is used.
7235
7236 In this file, each normative paragraph has had the command \LMHash{}
7237 added at the beginning, such that each of these paragraphs can be
7238 decorated with their hash value. Similarly, all \section{}s,
7239 \subsection{}s, \subsubsection{}s, and \paragraph{}s have had
7240 their \label commands changed to \LMLabel, such that they are
7241 decorated with logical names.
7242
7243 ** Rationale
7244
7245 The design of location markers was proposed by Erik Ernst and
7246 developed through discussions with several others, in particular Gilad
7247 Bracha and Lars Bak. Some discussions along the way that gave rise to
7248 the given design are outlined below.
7249
7250 The basic idea is that a hash value based on the actual text will
7251 serve well to identify a piece of text, because it will change
7252 whenever the text changes, and it remains the same if the text is
7253 moved to a different location; in other words, it characterizes the
7254 text itself, independently of the rest of the document. Hence:
7255
7256 - references to specific paragraphs in the spec are easy to create:
7257 copy the marker and paste it into the source code (but see below
7258 why this uses an extra indirection as far as possible)
7259
7260 - such references would be robust in the sense that they depend on
7261 the actual text alone, i.e., they would not be invalidated by
7262 updates to section numbers, relocation of the paragraph, or
7263 updates to text in different paragraphs; as Lars mentioned, we
7264 should use a "stripped" version of the text, removing comments,
7265 normalizing white space, etc., which would make the refs even more
7266 robust in case of "inessential" changes
7267
7268 - artifacts depending on a given part of the spec that was
7269 changed could easily be pointed out: After an update to a
7270 part of the spec, that artifact would hold a marker associated
7271 with a hash value which does not any more occur in the spec,
7272 maintainers of the artifact would then receive a notification
7273 ("test1773 depends on a part of the spec that was updated").
7274 Nice tool support would show them the paragraph in the most recent
7275 version of the spec as well as the old version that the artifact
7276 used to depend on, and a comparison of the two would help
7277 clarifying what needs fixing because of this change, if anything.
7278
7279 However, there is a conflict in this scenario: Lars pointed out that
7280 it is very inconvenient to have to create a lot of revision control
7281 commits (e.g., new versions of tests), just because a large number of
7282 artifacts depend on a specific hash value that changed, if that change
7283 has no real impact on each of those artifacts. The obvious solution
7284 to this problem would be to use symbolic names and keep the actual
7285 hash values out of the primary artifacts.
7286
7287 This approach has been used for \section{}s, \subsection{}s, etc., by
7288 using their labels as location markers. For instance, dependency on
7289 \subsubsection{New} would be marked as a dependency on 'sec:new',
7290 which will (most likely) exist with the same label in the spec for a
7291 long time. To detect a need for updates, the hash value associated
7292 with \subsubsection{New} from the date of the latest check of this
7293 kind to the dependent artifact should be compared with the current
7294 hash value for the same \subsubsection{}: The artifact should be
7295 revisited iff those hash values differ. As an easy approximation to
7296 this scheme, the hash values for all location markers would be
7297 computed for each spec update, and the location markers that have new
7298 hash values should cause revisits to all artifacts depending on that
7299 location marker.
7300
7301 The symbolic location markers on larger units like \section{}
7302 etc. enable location marking in a hierarchical fashion: Dependencies
7303 on a \subsubsection{} or on a \section{} can be chosen according to
7304 the actual needs with each dependent artifact. In general, fine
7305 granularity helps avoiding false positives, where an update somewhere
7306 in a large unit will flag too many dependent artifacts for revisits.
7307 In contrast, coarse granularity enables other artifacts to declare the
7308 actual dependencies when small units would be impractical because the
7309 artifact depends on so many of them. But there is a problem at the
7310 bottom of this hierarchy, namely with paragraphs.
7311
7312 It would be very inconvenient to have to invent a logical name for
7313 every paragraph. Similarly, using a simple paragraph numbering would
7314 be unstable (add one new paragraph in the beginning of a section, and
7315 all the rest have new numbers, creating a massive flood of false
7316 update alerts, or, even worse, corrupting the declared dependencies in
7317 artifacts because they point to the wrong paragraphs).
7318
7319 Hence, paragraphs have no other label than their actual hash value.
7320 Artifacts that depend on very specific elements in the spec may
7321 declare so by using an actual hash value for a given paragraph, and in
7322 return they pay in terms of potential updates to the marker when that
7323 paragraph changes, even in cases where the actual change makes no
7324 difference for that particular artifact. This choice of granularity
7325 vs. stability is up to the creator of each artifact.
7326
7327 ** Maintenance of this document
7328
7329 The invariant that each normative paragraph is associated with a line
7330 containing the text \LMHash{} should be maintained. Extra occurrences
7331 of \LMHash{} can be added if needed, e.g., in order to make
7332 individual \item{}s in itemized lists addressable. Each \LM.. command
7333 must occur on a separate line. \LMHash{} must occur immediately
7334 before the associated paragraph, and \LMLabel must occur immediately
7335 after the associated \section{}, \subsection{} etc.
7336
7337 ----------------------------------------------------------------------
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