OLD | NEW |
1 \documentclass{article} | 1 \documentclass{article} |
2 \usepackage{epsfig} | 2 \usepackage{epsfig} |
3 \usepackage{dart} | 3 \usepackage{dart} |
4 \usepackage{bnf} | 4 \usepackage{bnf} |
5 \usepackage{hyperref} | 5 \usepackage{hyperref} |
6 \newcommand{\code}[1]{{\sf #1}} | 6 \newcommand{\code}[1]{{\sf #1}} |
7 \title{Dart Programming Language Specification \\ | 7 \title{Dart Programming Language Specification \\ |
8 {\large Draft Version 0.8}} | 8 {\large Version 1.0}} |
9 \author{The Dart Team} | 9 \author{The Dart Team} |
10 \begin{document} | 10 \begin{document} |
11 \maketitle | 11 \maketitle |
12 | 12 |
13 \tableofcontents | 13 \tableofcontents |
14 | 14 |
| 15 |
15 \newpage | 16 \newpage |
16 | 17 |
17 \pagestyle{myheadings} | 18 \pagestyle{myheadings} |
18 \markright{{\bf Draft} Dart Programming Language Specification {\bf Draft}} | 19 \markright{Dart Programming Language Specification} |
19 | 20 |
20 \section{Notes} | 21 \section{Notes} |
21 | 22 |
22 Expect the contents and language rules to change over time. | |
23 %Please mail comments to gbracha@google.com. | |
24 | |
25 \subsection{Licensing} | 23 \subsection{Licensing} |
26 \label{licensing} | 24 \label{licensing} |
27 | 25 |
28 | 26 |
29 Except as otherwise noted at http://code.google.com/policies.html\#restrictions,
the content of this document is licensed under the Creative Commons Attribution
3.0 License available at: | 27 Except as otherwise noted at http://code.google.com/policies.html\#restrictions,
the content of this document is licensed under the Creative Commons Attribution
3.0 License available at: |
30 | 28 |
31 http://creativecommons.org/licenses/by/3.0/ | 29 http://creativecommons.org/licenses/by/3.0/ |
32 | 30 |
33 and code samples are licensed under the BSD license available at | 31 and code samples are licensed under the BSD license available at |
34 | 32 |
35 http://code.google.com/google\_bsd\_license.html. | 33 http://code.google.com/google\_bsd\_license.html. |
36 | 34 |
37 \subsection{Change Log} | |
38 \label{changes} | |
39 | |
40 \subsubsection{Changes Since Version 0.02} | |
41 | |
42 The following changes have been made in version 0.03 since version 0.02. In addi
tion, various typographical errors have been corrected. The changes are listed b
y section number. | |
43 | |
44 \ref{notation}: Expanded examples of grammar. | |
45 | |
46 \ref{factories}: Corrected reference to undefined production {\em typeVariables}
to {\em typeParameters}. | |
47 | |
48 \ref{superinterfaces}: Removed static warning when imported superinterface of a
class contains private members. | |
49 | |
50 The former section on factories and constructors in interfaces (now removed): Re
moved redundant prohibition on default values. | |
51 | |
52 \ref{interfaceSuperinterfaces}: Removed static warning when imported superinterf
ace of an interface contains private members. | |
53 | |
54 \ref{expressions}: Fixed typo in grammar. | |
55 | |
56 \ref{new}, \ref{const} : made explicit accessibility requirement for class being
constructed. | |
57 | |
58 \ref{const}: make clear that referenced constructor must be marked \CONST{}. | |
59 | |
60 \ref{superInvocation}: fixed botched sentence where superclass $S$ is introduced
. | |
61 | |
62 \ref{postfixExpressions}: qualified definition of $v++$ so it is clear that $v$
is an identifier. | |
63 | |
64 | |
65 | |
66 \subsubsection{Changes Since Version 0.03} | |
67 | |
68 \ref{instanceMethods}. The former section on interface methods (now removed): Ad
ded missing requirement that overriding methods have same number of required par
ameters and all optional parameters as overridden method, in same order. | |
69 | |
70 \ref{generics}: Added prohibition against cyclic type hierarchy for type parame
ters. | |
71 | |
72 \ref{instanceCreation}: Clarified requirements on use of parameterized types in
instance creation expressions. | |
73 | |
74 \ref{bindingActualsToFormals}: Added requirement that $q_i$ are distinct. | |
75 | |
76 \ref{staticInvocation}. Static method invocation determines the function (which
may involve evaluating a getter) before evaluating the arguments, so that static
invocation and top-level function invocation agree. | |
77 | |
78 \ref{typeTest}: Added missing test that type being tested against is in scope an
d is indeed a type. | |
79 | |
80 \ref{forLoop}: Changed for loop to introduce fresh variable for each iteration. | |
81 | |
82 \ref{parameterizedTypes}: Malformed parameterized types generate warnings, not e
rrors(except when used in reified contexts like instance creation and superclass
es/interfaces). | |
83 | |
84 | |
85 \subsubsection{Changes Since Version 0.04} | |
86 | |
87 Added hyperlinks in PDF. | |
88 | |
89 \ref{operators}: Removed unary plus operator. Clarified that operator formals mu
st be required. | |
90 | |
91 \ref{constantConstructors}: Filled in a lot of missing detail. | |
92 | |
93 The former section on factories and constructors in interfaces (now removed): Al
lowed factory class to be declared via a qualified name. | |
94 | |
95 \ref{numbers}: Changed production for $Number$. | |
96 | |
97 \ref{const}: Added requirements that actuals be constant, rules for dealing with
inappropriate types of actuals, and examples. Also explicitly prohibit type par
ameters. | |
98 | |
99 \ref{functionExpressionInvocation}: Modified final bullet to keep it inline with
similar clauses in other sections. Exact wording of these sections also tweaked
slightly. | |
100 | |
101 \ref{unaryExpressions}: Specified ! operator. Eliminated section on prefix expr
essions and moved contents to section on unary expressions. | |
102 | |
103 \ref{lexicalRules}: Specified unicode form of Dart source. | |
104 | |
105 | |
106 \subsubsection{Changes Since Version 0.05} | |
107 | |
108 \ref{generativeConstructors}: Clarified how initializing formals can act as opti
onal parameters of generative constructors. | |
109 | |
110 \ref{factories}: Treat factories as constructors, so type parameters are implici
tly in scope. | |
111 | |
112 The former section on factories and constructors in interfaces (now removed): Si
mplify rules for interface factory clauses. Use the keyword \DEFAULT{} instead o
f \FACTORY{}. | |
113 | |
114 \ref{generics}: Mention that typedefs can have type parameters. | |
115 | |
116 \ref{typeTest}: Added checked mode test that type arguments match generic type. | |
117 | |
118 \ref{dynamicTypeSystem}: Added definition of malformed types, and requirement on
their handling in checked mode. | |
119 | |
120 \subsubsection{Changes Since Version 0.06} | |
121 | |
122 \ref{variables}: library variable initializers must be constant. | |
123 | |
124 \ref{classes}: Added \ABSTRACT{} modifier to grammar. | |
125 | |
126 \ref{classes}, \ref{staticMethods}, \ref{staticVariables}, \ref{unqualifiedInvoc
ation},\ref{identifierReference}: Superclass static members are not in scope in
subclasses, and do not conflict with subclass members. | |
127 | |
128 \ref{operators}: \code{[]=} must return \VOID{}. Operator \CALL{} added to supp
ort function emulation. Removed operator \code{$>>>$}. Made explicit restriction
on methods named \CALL{} or \NEGATE{}. | |
129 | |
130 \ref{constants}: Added \code{!$e$} as constant expression. Clarified what happen
s if evaluation of a constant fails. | |
131 | |
132 \ref{maps}: Map keys need not be constants. However, they are always string lite
rals. | |
133 | |
134 \ref{this}: State restrictions on use of \THIS{}. | |
135 | |
136 \ref{instanceCreation}, \ref{new}: Rules for bounds checking of constructor argu
ments when calling default constructors for interfaces refined. | |
137 | |
138 \ref{ordinaryInvocation}: Revised semantics to account for function emulation. | |
139 | |
140 \ref{staticInvocation}: Revised semantics to account for function emulation. | |
141 | |
142 \ref{superInvocation}: Factory constructors cannot contain super invocations. Re
vised semantics to account for function emulation. | |
143 | |
144 \ref{assignment}: Specified assignment involving \code{[]=} operator. | |
145 | |
146 \ref{compoundAssignment}: Removed operator \code{$>>>$}. | |
147 | |
148 \ref{shift}: Removed operator \code{$>>>$}. | |
149 | |
150 \ref{postfixExpressions}: Postfix \code{-{}-} operator specified. Behavior of p
ostfix operations on subscripted expressions specified. | |
151 | |
152 \ref{identifierReference}: Added built-in identifier \CALL{}. Banned use of bui
lt-in identifiers as types made other uses warnings. | |
153 | |
154 \ref{typeTest}: Moved specification of test that type arguments match generic ty
pe to \ref{dynamicTypeSystem}. | |
155 | |
156 \ref{switch}: Corrected evaluation of case clauses so that case expression is th
e receiver of ==. Revised specification to correctly deal with blank statement
s in case clauses. | |
157 | |
158 \ref{assert}: Fixed bug in \ASSERT{} specification that could lead to puzzlers. | |
159 | |
160 \ref{dynamicTypeSystem}: Consolidated definition of malformed types. | |
161 | |
162 \ref{functionTypes}: Revised semantics to account for function emulation. | |
163 | |
164 | |
165 \subsubsection{Changes Since Version 0.07} | |
166 | |
167 \ref{variables}: Static variables are lazily initialized, but need not be consta
nts. Orthogonal notion of constant variable introduced. | |
168 | |
169 \ref{operators}: Added \EQUALS{} operator as part of revised \code{==} treatment
. | |
170 | |
171 \ref{generativeConstructors}: Initializing formals have the same type as the fie
ld they correspond to. | |
172 | |
173 \ref{staticVariables}: Static variable getter rules revised to deal with lazy in
itialization. | |
174 | |
175 \ref{expressions}: Modified syntax to support cascaded method invocations. | |
176 | |
177 \ref{constants}: Removed support for + operator on Strings. Extended string co
nstants to support certain cases of string interpolation. Revised constants to d
eal with constant variables. | |
178 | |
179 \ref{strings}: Corrected definition of \code{HEX\_DIGIT\_SEQUENCE}. Support impl
icit concatenation of adjacent single line strings. | |
180 | |
181 \ref{bindingActualsToFormals}: Centralized and corrected type rules for function
invocation. | |
182 | |
183 \ref{methodInvocation}: Moved rules for checking function/method invocations to
\ref{bindingActualsToFormals}. Added definition of cascaded method invocations. | |
184 | |
185 \ref{getterInvocation}, \ref{assignment}: Updated \code{noSuchMethod()} call for
getters and setters to conform to planned API. | |
186 | |
187 \ref{conditional}: Modified syntax to support cascaded method invocations. | |
188 | |
189 \ref{equality}: Revised semantics for \code{==}. | |
190 | |
191 \ref{identifierReference}: Removed \IMPORT{}, \LIBRARY{} and \SOURCE{} from list
of built-in identifiers and added \EQUALS{}. Revised rules for evaluating ident
ifiers to deal with lazy static variable initialization. | |
192 | |
193 \ref{continue}: Fixed bug that allowed \CONTINUE{} labeled on non-loops. | |
194 | |
195 \ref{librariesAndScripts}: Revised syntax so no space is permitted between \code
{\#} and directives. Introduced \code{show:} combinator. Describe \code{prefix:}
as a combinator. Added initial discussion of namespaces. Preclude string interp
olation in arguments to directives. | |
196 | |
197 \subsubsection{Changes Since Version 0.08} | |
198 | |
199 \ref{instanceMethods}, \ref{abstractInstanceMembers}: Abstract methods may speci
fy default values. | |
200 | |
201 \ref{interfaces}, The former section on interface methods (now removed): Interfa
ce methods may specify default values. | |
202 | |
203 \ref{constants}: The \code{\~{}/ } operator can apply to doubles. | |
204 | |
205 \ref{instanceCreation}: Refined rules regarding abstract class instantiation, al
lowing factories to be used. | |
206 | |
207 \ref{switch}: \SWITCH{} statement specification revised. | |
208 | |
209 \ref{throw}: \THROW{} may not throw \NULL{}. | |
210 | |
211 \ref{imports}: Imports introduce a scope separate from the library scope. Multip
le libraries may share prefix. | |
212 | |
213 \ref{typedef}: Recursive typedefs disallowed. | |
214 | |
215 \subsubsection{Changes Since Version 0.09} | |
216 | |
217 \ref{scoping}: Consolidated discussion of namespaces and scopes. Started to tigh
ten up definitions of scopes. | |
218 | |
219 \ref{classes}: Overriding of fields allowed. | |
220 | |
221 \ref{operators}: \CALL{} is no longer an operator. | |
222 | |
223 The former section on variables in interfaces (now removed): Added specification
of variable declarations in interfaces. | |
224 | |
225 \ref{constants}: Static methods and top-level functions are compile-time constan
ts. | |
226 | |
227 \ref{strings}: Multiline strings can be implicitly concatenated and contain inte
rpolated expressions. | |
228 | |
229 \ref{typeCast}: Type cast expression added. | |
230 | |
231 \ref{expressionStatements}: Map literals cannot be expression statements. | |
232 | |
233 \ref{try}, \ref{throw}: Clarified type of stack trace. | |
234 | |
235 \ref{exports}, \ref{imports}: Added re-export facility. | |
236 | |
237 | |
238 \subsubsection{Changes Since Version 0.10} | |
239 | |
240 \ref{overview}: Discuss reified runtime types. | |
241 | |
242 \ref{scoping}: Removed shadowing warnings. Allow overloading of \code{-}. | |
243 | |
244 \ref{variables}: Centralized discussion of implicit getters and setters. | |
245 | |
246 \ref{externalFunctions}: External functions added. | |
247 | |
248 \ref{classes}: Abstract classes must now be declared explicitly. | |
249 | |
250 \ref{operators}: Eliminate \NEGATE{} in favor of overloaded unary minus. Elimina
te \EQUALS{} in favor of operator \code{==}. | |
251 | |
252 \ref{setters}: Setter syntax no longer includes = sign after the name. | |
253 | |
254 \ref{abstractInstanceMembers}: Clarify that getters and setters may be abstrac
t. Eliminate \ABSTRACT{} modifier for abstract members. Added static warning if
abstract class has abstract member. | |
255 | |
256 \ref{instanceVariables}: Instance variables can be initialized to non-constants.
Moved discussion of implicit getters and setters to \ref{variables}. | |
257 | |
258 \ref{generativeConstructors}: Clarify that finals can only be set once. | |
259 | |
260 \ref{redirectingFactoryConstructors}: Added redirecting factories. | |
261 | |
262 \ref{staticVariables}: Moved discussion of implicit getters and setters to \ref{
variables}. | |
263 | |
264 \ref{interfaces}: Eliminated interface declarations. | |
265 | |
266 \ref{metadata}: Added metadata. | |
267 | |
268 \ref{constants}: Refined definition constant identity/caching. | |
269 | |
270 \ref{throw}: Stack traces moved to \ref{try}. | |
271 | |
272 \ref{new}: Creating an instance via \NEW{} using an undefined class or construct
or is a dynamic error and a static warning, not a compile-time error. Evaluatio
n rules to allow instance variables with non-constant initializers. Instantiati
ng an abstract class via a generative constructor is now a dynamic error. | |
273 | |
274 \ref{equality}: Replaced \code{===} with built-in function \code{identical()}. E
quality does not special case identity. | |
275 | |
276 \ref{identifierReference}: Type names have meaning as expressions. \ASSERT{} is
not a built-in identifier anymore, but \EXPORT{}, \IMPORT{}, \LIBRARY{} and \PAR
T{} are. Removed warning on use of built-in identifiers as variable/function nam
es. | |
277 | |
278 \ref{typeCast}: type cast accepts \NULL{}. | |
279 | |
280 \ref{argumentDefinitionTest}: Added operation to determine if optional argument
was actually passed. | |
281 | |
282 \ref{localFunctionDeclaration}: Added section on local functions. | |
283 | |
284 \ref{switch}: Allow switch on compile-time constants of any one type. | |
285 | |
286 \ref{try}: Revised syntax for \CATCH{} clauses. Specification of stack traces mo
ved from \ref{throw}. | |
287 | |
288 \ref{return}: Made explicit that checked mode tests returns. | |
289 | |
290 \ref{assert}: \ASSERT{} is now a reserved word. | |
291 | |
292 \ref{librariesAndScripts}: Revised library syntax and semantics. | |
293 | |
294 \ref{typeDynamic}: Renamed {\bf Dynamic} to \DYNAMIC{}. | |
295 | |
296 \ref{reservedWords}: \ASSERT{} is a reserved word. | |
297 | |
298 | |
299 \subsubsection{Changes Since Version 0.11} | |
300 | |
301 \ref{notation}: Moved discussion of tokenization to section \ref{reference}. | |
302 | |
303 \ref{numbers}: Removed unary plus. | |
304 | |
305 \ref{librariesAndScripts}: Refined definition of show and hide to handle getters
and setters in pairs. | |
306 | |
307 \ref{functionTypes}: All function types are subtypes of \code{Function}. | |
308 | |
309 \ref{reference}: Added discussion of tokenization. | |
310 | |
311 \ref{reservedWords}: Defined meaning of reserved word. | |
312 | |
313 \ref{comments}: Added initial discussion of dartdoc comments. | |
314 | |
315 \subsubsection{Changes Since Version 0.12} | |
316 | |
317 \ref{classes}: Removed \ABSTRACT{} modifier from grammar of members. Added gramm
ar for \WITH{} clause. | |
318 | |
319 \ref{superclasses}: Added discussion of new \WITH{} clause for mixins. | |
320 | |
321 \ref{mixins}: Added specification of mixins. | |
322 | |
323 \ref{constants}: Revised description of \code{identical()} so that it always ret
urns \TRUE{} on numbers with the same class and value. | |
324 | |
325 \ref{null}: Invocations on \NULL{} throw \code{NoSuchMethodError} only. | |
326 | |
327 \ref{throw}: \THROW{} of \NULL{} raises \code{NullThrownError}. | |
328 | |
329 \ref{instanceCreation} Using undefined types as type arguments to a constructor
is a dynamic failure. | |
330 | |
331 \ref{librariesAndScripts}: Added discussion of compilation units. Allow name cl
ause to be optional for libraries, allow export clauses in scripts. Support full
y qualified name for libraries. Allow different imports to share same prefix. Ad
ded mixin application as a top level declaration. | |
332 | |
333 \ref{typedef}: Typedefs for mixin applications added. | |
334 | |
335 \ref{interfaceTypes}: Add effects of mixin clause on subtyping. | |
336 | |
337 \ref{leastUpperBounds}: Corrected definition of LUBs. | |
338 | |
339 \ref{reservedWords}: Added keyword \WITH{}. | |
340 | |
341 | |
342 \subsubsection{Changes Since Version 0.20} | |
343 | |
344 \ref{getters}: Getters cannot return \VOID{}. | |
345 | |
346 \ref{superinterfaces}: Added requirement that superclass cannot appear in \IMPLE
MENTS{} clause. | |
347 | |
348 \ref{interfaceInheritanceAndOverriding}: Clarified status of getter/setter vs. m
ethod conflicts in multiple interface inheritance. | |
349 | |
350 \ref{throw}: Separated \THROW{} into \code{\THROW{} e} and \code{\RETHROW{}}. | |
351 | |
352 \ref{new}: Arguments to constructor are evaluated before allocating new object. | |
353 | |
354 \ref{unqualifiedInvocation}: Calling an undeclared method in a static context is
a dynamic error (and a static warning) not a compile-time one. | |
355 | |
356 \ref{ordinaryInvocation}, \ref{superInvocation}, \ref{getterInvocation}, \ref{as
signment}: Refined description of \code{InvocationMirror} instance passed to \co
de{noSuchMethod()}. | |
357 | |
358 \ref{lexicalRules}: Abandoned requirement for Unicode Normalization Form C. | |
359 | |
360 \subsubsection{Changes Since Version 0.30} | |
361 | |
362 \ref{superclasses}, \ref{superinterfaces}: Clarified that super types with wrong
number of type arguments cause a compilation error. | |
363 | |
364 \subsubsection{Changes Since Version 0.31} | |
365 | |
366 \ref{abstractInstanceMembers}: Abstract methods act as pure declarations. | |
367 | |
368 \ref{mixins}: Mixin application has forwarding constructors for all superclass c
onstructors. | |
369 | |
370 \ref{instanceCreation}, \ref{new}: Revised so that wrong generic arity is a runt
ime error with static warning. | |
371 | |
372 \ref{typeTest}, \ref{typeCast}: Eliminated special treatment of malformed types
. | |
373 | |
374 \ref{rethrow}: Rethrow is a statement, not an expression. | |
375 | |
376 \ref{librariesAndScripts}: Semicolon required after top-level external declarati
ons. | |
377 | |
378 \ref{imports}: Removed requirement that library names be unique within an isolat
e. | |
379 | |
380 \ref{dynamicTypeSystem}: Revised definition of malformed types. Revised behavior
of checked and production modes wrt to malformed and malbounded types. Refined
assignability rules wrt new function type subtyping. | |
381 | |
382 \ref{interfaceTypes}: Corrected oversight wrt type variables and \cd{Object}. | |
383 | |
384 \ref{functionTypes}: Liberalized function subtyping rules. Special assignability
rules. | |
385 | |
386 \ref{parameterizedTypes}: Out with misconstructed types, in with malbounded ones
. | |
387 | |
388 \subsubsection{Changes Since Version 0.40} | |
389 | |
390 \ref{expressions}: Argument definition test construct dropped. | |
391 | |
392 \ref{maps}: Map literals can be keyed by arbitrary expressions. | |
393 | |
394 \ref{librariesAndScripts}: Implicitly named libraries are named `'. Script tags
are allowed in all libraries. It is a warning to import or export two libraries
with the same name. | |
395 | |
396 \subsubsection{Changes Since Version 0.41} | |
397 | |
398 \ref{variables}: Uninitialized final is now just a static warning. | |
399 | |
400 \ref{typeOfAFunction}: Added details about the run time type of functions. | |
401 | |
402 \ref{instanceVariables}: Disallowed const inst vars. | |
403 | |
404 \ref{redirectingConstructors}: Uninitialized final is now just a static warning. | |
405 | |
406 \ref{objectIdentity}, \ref{constants}: Clarified rules for double identity. | |
407 | |
408 \ref{maps}: Adjusted rules for constant map literals. | |
409 | |
410 \ref{propertyExtraction}: If the same method is extracted repeatedly from the sa
me object, the results are equal. Furthermore, the type of the property extract
ion is based on the method being closurized. Also described handling of propert
y extractions on \SUPER{} explicitly. | |
411 | |
412 \ref{getterInvocation}: Explicitly described getter invocations on \SUPER{}. | |
413 | |
414 \subsubsection{Changes Since Version 0.50} | |
415 | |
416 % there was no public 0.50! | |
417 | |
418 \ref{variables}: Final variables introduce setters that trap on execution. Not i
nitializing a final is a warning, not an error. Initializing a final variable d
eclared with an initializer is a warning, not an error. | |
419 | |
420 \ref{requiredFormals}: Initializing formals can specify function types. These m
ay not specify defaults. | |
421 | |
422 \ref{instanceMethods}: Corrected override rules to fit with earlier relaxation o
f function subtype rules. Furthermore, bad overrides provoke warnings not errors
. Also, methods and corresponding setters yield warnings. | |
423 | |
424 \ref{generativeConstructors}: Initializing a final variable declared with an in
itializer is a warning, not an error. | |
425 | |
426 \ref{staticMethods}: Corresponding setters yield warnings. | |
427 | |
428 \ref{inheritanceAndOverriding}: Refined definitions of inheritance and overridin
g to correctly account for library privacy. | |
429 | |
430 \ref{superinterfaces}: Suppress type warnings for unimplemented members of super
interfaces if the class declares \code{noSuchMethod()}. | |
431 | |
432 \ref{interfaceInheritanceAndOverriding}: Refined definitions of inheritance and
overriding to correctly account for library privacy. | |
433 | |
434 \ref{constants}: Literal symbols are constants. | |
435 | |
436 \ref{numbers}, \ref{booleans}, \ref{strings}: Specified the runtime type of numb
ers, booleans and strings. | |
437 | |
438 \ref{strings}: Implicit concatenation works among all kinds of strings. | |
439 | |
440 \ref{symbols}: Added literal symbols. | |
441 | |
442 \ref{if}, \ref{for}, \ref{while}, \ref{do}: Single statements in control constru
cts implicitly introduce a block. | |
443 | |
444 \ref{imports}: Introduced special treatment for imports conflicts with \code{dar
t:core}. Ambiguous names are treated as malformed types or \code{NoSuchMethodErr
or}s. | |
445 | |
446 \ref{typedef}: Tightened restrictions on recursive typedefs. | |
447 | |
448 %\ref{typeDynamic}: Clarified that \DYNAMIC{} is not an expression. | |
449 | |
450 \subsubsection{Changes Since Version 0.51} | |
451 | |
452 \ref{classes}: Mixin applications are a kind of class definition. | |
453 | |
454 \ref{generativeConstructors}: Clarify that executing repeated initialization of
a final variable by an initializer or initializing formal is a run-time error. | |
455 | |
456 \ref{mixins}: Mixin applications are defined using \CLASS{} rather than \TYPED
EF{}. | |
457 | |
458 \ref{objectIdentity}: Refined definition of \code{identical()}. | |
459 | |
460 \ref{propertyExtraction}: Abstract methods are ignored for purposes of property
extraction. | |
461 | |
462 \ref{bindingActualsToFormals}: Mismatched arguments lead to \cd{NoSuchMethodErro
r}. | |
463 | |
464 \ref{ordinaryInvocation}, \ref{superInvocation}: Correctly account for calls to
\cd{noSuchMethod} due to mismatched arguments. | |
465 | |
466 \ref{imports}, \ref{exports}: Provenance of declarations allowed to disambiguat
e imports and exports. | |
467 | |
468 \ref{typedef}: Mixin applications are no longer defined via a \TYPEDEF{}. | |
469 | |
470 \ref{functionTypes}: All functions must implement \CALL{}. | |
471 | |
472 \ref{comments}: Doc comments details are unspecified. | |
473 | |
474 \subsubsection{Changes Since Version 0.6} | |
475 | |
476 \ref{variables}: Type promotion support added. | |
477 | |
478 \ref{formalParameters}: refined scope rules. | |
479 | |
480 \ref{classes}: Banned name clashes between type variables and members etc. | |
481 | |
482 \ref{factories}: Banned default values in redirecting factories. | |
483 | |
484 \ref{constants}: Added constant conditional expressions. | |
485 | |
486 \ref{strings}: Allow adjacent single and multiline strings to concatenate. Allow
escaped newlines in multiline strings. | |
487 | |
488 \ref{const}: Allow parameterized types in const instance creation. | |
489 | |
490 \ref{conditional}: Type promotion support added. | |
491 | |
492 \ref{logicalBooleanExpressions}: Type promotion support added. | |
493 | |
494 \ref{logicalBooleanExpressions} - \ref{bitwiseExpressions}, \ref{operatorPrecede
nce}: Increased precedence of bitwise operations to be higher than equality and
relational expressions. | |
495 | |
496 \ref{identifierReference}: Clarified static type rules. Type promotion support a
dded. | |
497 | |
498 \ref{typeTest}: Type promotion support added. | |
499 | |
500 \ref{if}: Type promotion support added. | |
501 | |
502 \ref{try}: \ON{} with no \CATCH{} implies \DYNAMIC{}, not \cd{Object}. | |
503 | |
504 \ref{return}: Added warning if \RETURN{} without expression mixed with \RETURN{}
with an expression. | |
505 | |
506 \ref{exports}: Ensure that exports treat \code{dart:} libs specially, like impor
ts do. | |
507 | |
508 \ref{typePromotion}: Added notion of type promotion. | |
509 | |
510 \ref{typedef}: Banned all recursion in typedefs. | |
511 | |
512 \subsubsection{Changes Since Version 0.7} | |
513 | |
514 | |
515 \ref{variables}: Final variables no longer introduce setters. | |
516 | |
517 \ref{superinterfaces}: Described \cd{@proxy} annotation's effects on typecheckin
g. | |
518 | |
519 \ref{metadata}: Banned use of types as metadata. | |
520 | |
521 \ref{new}: Instantiating subclasses of malbounded types is a dynamic error. | |
522 | |
523 \ref{typeTest}, \ref{typeCast}, \ref{try}: Use of malformed type in casts, type
tests and catch clauses is a dynamic error. | |
524 | |
525 \ref{scripts}: Corrected rules for running scripts. | |
526 | |
527 \ref{dynamicTypeSystem}: In checked mode, subtype tests against malbounded types
are dynamic errors. | |
528 | |
529 \ref{leastUpperBounds}: Extended LUBs to all types. | |
530 | |
531 | |
532 | |
533 \section{Notation} | 35 \section{Notation} |
534 \label{notation} | 36 \label{notation} |
535 | 37 |
536 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: | 38 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: |
537 \begin{itemize} | 39 \begin{itemize} |
538 \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.} | 40 \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.} |
539 \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. } | 41 \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. } |
540 \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?} | 42 \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?} |
541 \end{itemize} | 43 \end{itemize} |
542 | 44 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 } | 131 } |
630 | 132 |
631 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. | 133 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. |
632 | 134 |
633 \commentary{However they are not first class. To get multiple copies of a libra
ry running simultaneously, one needs to spawn an isolate. | 135 \commentary{However they are not first class. To get multiple copies of a libra
ry running simultaneously, one needs to spawn an isolate. |
634 } | 136 } |
635 | 137 |
636 \subsection{Scoping} | 138 \subsection{Scoping} |
637 \label{scoping} | 139 \label{scoping} |
638 | 140 |
639 A {\em namespace} is a mapping of identifiers to declarations. Let $NS$ be a na
mespace. We say that a name $n$ {\em is in }$NS$ if $n$ is a key of $NS$. We say
a declaration $d$ {\em is in }$NS$ if a key of $NS$ maps to $d$. | 141 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$. |
640 | 142 |
641 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. | 143 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. |
642 | 144 |
643 \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. | 145 \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. |
644 } | 146 } |
645 | 147 |
646 It is a compile-time error if there is more than one entity with the same name d
eclared in the same scope. | 148 It is a compile-time error if there is more than one entity with the same name d
eclared in the same scope. |
647 | 149 |
648 \commentary{ | 150 \commentary{ |
649 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-. | 151 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-. |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 \VAR{} v = \NEW{} C(); // compile-time error | 386 \VAR{} v = \NEW{} C(); // compile-time error |
885 C aC; // compile-time error | 387 C aC; // compile-time error |
886 \VAR{} C = 10; | 388 \VAR{} C = 10; |
887 \} | 389 \} |
888 | 390 |
889 \commentary { | 391 \commentary { |
890 Inside \cd{perverse()}, \cd{C} denotes a local variable. The type \cd{C} is hid
den by the variable of the same name. The attempt to instantiate \cd{C} causes a
compile-time error because it references a local variable prior to its declarat
ion. Similarly, for the declaration of \cd{aC} (even though it is only a type an
notation). | 392 Inside \cd{perverse()}, \cd{C} denotes a local variable. The type \cd{C} is hid
den by the variable of the same name. The attempt to instantiate \cd{C} causes a
compile-time error because it references a local variable prior to its declarat
ion. Similarly, for the declaration of \cd{aC} (even though it is only a type an
notation). |
891 } | 393 } |
892 | 394 |
893 \rationale{ | 395 \rationale{ |
894 As a rule, type annotations are ignored in production mode. However, we do not w
ant to allow programs to compile legally in one mode and not another, and in thi
s extremely odd situation, that consideration takes precedence. | 396 As a rule, type annotations are ignored in production mode. However, we do |
| 397 not want to allow programs to compile legally in one mode and not another, and
in this extremely odd situation, that consideration takes precedence. |
895 } | 398 } |
896 | 399 |
897 \end{dartCode} | 400 \end{dartCode} |
898 | 401 |
899 % 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. | 402 % 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. |
900 | 403 |
901 The following rules apply to all static and instance variables. | 404 The following rules apply to all static and instance variables. |
902 | 405 |
903 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 | 406 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 |
904 | 407 |
(...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2022 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. | 1525 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. |
2023 } | 1526 } |
2024 | 1527 |
2025 It is a static warning if a non-abstract class inherits an abstract method. | 1528 It is a static warning if a non-abstract class inherits an abstract method. |
2026 | 1529 |
2027 \commentary { | 1530 \commentary { |
2028 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. | 1531 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. |
2029 | 1532 |
2030 \begin{enumerate} | 1533 \begin{enumerate} |
2031 | 1534 |
2032 \item There is only one namespace for getters, setters, methods and constructors
(\ref{scoping}). A field $f$ introduces a getter $f$ and a setter $f=$ (\ref{in
stanceVariables}, \ref{staticVariables}). When we speak of members here, we mean
accessible fields, getters, setters and methods (\ref{classes}). | 1535 \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}). |
2033 \item You cannot have two members with the same name in the same class - be the
y declared or inherited (\ref{scoping}, \ref{classes}). | 1536 \item You cannot have two members with the same name in the same class - be the
y declared or inherited (\ref{scoping}, \ref{classes}). |
2034 \item Static members are never inherited. | 1537 \item Static members are never inherited. |
2035 \item It is a warning if you have an static member named $m$ in your class or a
ny superclass (even though it is not inherited) and an instance member of the s
ame name (\ref{instanceMethods}, \ref{getters}, \ref{setters}). | 1538 \item It is a warning if you have an static member named $m$ in your class or a
ny superclass (even though it is not inherited) and an instance member of the s
ame name (\ref{instanceMethods}, \ref{getters}, \ref{setters}). |
2036 \item It is a warning if you have a static setter $v=$, and an instance member $
v$ (\ref{setters}). | 1539 \item It is a warning if you have a static setter $v=$, and an instance member $
v$ (\ref{setters}). |
2037 \item It is a warning if you have a static getter $v$ and an instance setter $v=
$ (\ref{getters}). | 1540 \item It is a warning if you have a static getter $v$ and an instance setter $v=
$ (\ref{getters}). |
2038 \item If you define an instance member named $m$, and your superclass has an in
stance member of the same name, they override each other. This may or may not be
legal. | 1541 \item If you define an instance member named $m$, and your superclass has an in
stance member of the same name, they override each other. This may or may not be
legal. |
2039 \item \label{typeSigAssignable} | 1542 \item \label{typeSigAssignable} |
2040 If two members override each other, it is a static warning if their type signatu
res are not assignable to each other (\ref{instanceMethods}, \ref{getters}, \ref
{setters}) (and since these are function types, this means the same as "subtype
s of each other"). | 1543 If two members override each other, it is a static warning if their type signatu
res are not assignable to each other (\ref{instanceMethods}, \ref{getters}, \ref
{setters}) (and since these are function types, this means the same as "subtype
s of each other"). |
2041 \item \label{requiredParams} | 1544 \item \label{requiredParams} |
2042 If two members override each other, it is a static warning if the overriding mem
ber has more required parameters than the overridden one (\ref{instanceMethods}
). | 1545 If two members override each other, it is a static warning if the overriding mem
ber has more required parameters than the overridden one (\ref{instanceMethods}
). |
(...skipping 10 matching lines...) Expand all Loading... |
2053 \item It is a static warning a concrete class has an abstract member (declared o
r inherited). | 1556 \item It is a static warning a concrete class has an abstract member (declared o
r inherited). |
2054 \item It is a static warning and a dynamic error to call a non-factory construct
or of an abstract class (\ref{new}). | 1557 \item It is a static warning and a dynamic error to call a non-factory construct
or of an abstract class (\ref{new}). |
2055 \item If a class defines an instance member named $m$, and any of its superinter
faces have a member named $m$, the interface of the class overrides $m$. | 1558 \item If a class defines an instance member named $m$, and any of its superinter
faces have a member named $m$, the interface of the class overrides $m$. |
2056 \item An interface inherits all members of its superinterfaces that are not ov
erridden and not members of multiple superinterfaces. | 1559 \item An interface inherits all members of its superinterfaces that are not ov
erridden and not members of multiple superinterfaces. |
2057 \item If multiple superinterfaces of an interface define a member with the same
name $m$, then at most one member is inherited. That member (if it exists) is t
he one whose type is a subtype of all the others. If there is no such member, th
en: | 1560 \item If multiple superinterfaces of an interface define a member with the same
name $m$, then at most one member is inherited. That member (if it exists) is t
he one whose type is a subtype of all the others. If there is no such member, th
en: |
2058 \begin{itemize} | 1561 \begin{itemize} |
2059 \item A static warning is given. | 1562 \item A static warning is given. |
2060 \item If possible the interface gets a member named $m$ that has the minimum
number of required parameters among all the members in the superinterfaces, the
maximal number of positionals, and the superset of named parameters. The typ
es of these are all \DYNAMIC{}. If this is impossible then no member $m$ appears
in the interface. | 1563 \item If possible the interface gets a member named $m$ that has the minimum
number of required parameters among all the members in the superinterfaces, the
maximal number of positionals, and the superset of named parameters. The typ
es of these are all \DYNAMIC{}. If this is impossible then no member $m$ appears
in the interface. |
2061 \end{itemize} (\ref{interfaceInheritanceAndOverriding}) | 1564 \end{itemize} (\ref{interfaceInheritanceAndOverriding}) |
2062 \item Rule \ref{typeSigAssignable} applies to interfaces as well as classes (\
ref{interfaceInheritanceAndOverriding}). | 1565 \item Rule \ref{typeSigAssignable} applies to interfaces as well as classes (\
ref{interfaceInheritanceAndOverriding}). |
2063 \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}). | 1566 \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}) or is annotated with \cd{@proxy}. |
2064 \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})
. | 1567 \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})
. |
2065 \end{enumerate} | 1568 \end{enumerate} |
2066 } | 1569 } |
2067 | 1570 |
2068 | 1571 |
2069 %Can we have abstract getters and setters? | 1572 %Can we have abstract getters and setters? |
2070 | 1573 |
2071 \subsection{Superinterfaces} | 1574 \subsection{Superinterfaces} |
2072 \label{superinterfaces} | 1575 \label{superinterfaces} |
2073 % what about rules about classes that fail to implement their interfaces? | 1576 % what about rules about classes that fail to implement their interfaces? |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2281 \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. | 1784 \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. |
2282 | 1785 |
2283 | 1786 |
2284 \subsection{Mixin Composition} | 1787 \subsection{Mixin Composition} |
2285 \label{mixinComposition} | 1788 \label{mixinComposition} |
2286 | 1789 |
2287 \rationale{ | 1790 \rationale{ |
2288 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. | 1791 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. |
2289 } | 1792 } |
2290 | 1793 |
2291 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 $M_1<T_1 \ldots T_{k_{M_1}}> * M_2<U_1 \ldots U_{k_{
M_2}}>$ to $S<V_1 \ldots V_{k_S}>$ is equivalent to | 1794 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 |
2292 | 1795 |
2293 \code{\ABSTRACT{} \CLASS{} $Id_1<T_1 \ldots T_{k_{M_1}}, U_1 \ldots U_{k_{M_2}
}, V_1 \ldots V_{k_S}> = Id_2<U_1 \ldots U_{k_{M_2}}, V_1 \ldots V_{k_S}>$ \W
ITH{} $M_1 <T_1 \ldots T_{k_{M_1}}>$;} | 1796 $M_1<T_1 \ldots T_{k_{M_1}}> * M_2<U_1 \ldots U_{k_{M_2}}>$ |
| 1797 |
| 1798 to $S<V_1 \ldots V_{k_S}>$ is equivalent to |
| 1799 |
| 1800 \begin{dartCode} |
| 1801 \ABSTRACT{} \CLASS{} $Id_1<T_1 \ldots T_{k_{M_1}}, U_1 \ldots U_{k_{M_2}}, V_1
\ldots V_{k_S}> = $ |
| 1802 $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}}>$; |
| 1803 \end{dartCode} |
2294 | 1804 |
2295 where $Id_2$ denotes | 1805 where $Id_2$ denotes |
2296 | 1806 |
2297 \code{\ABSTRACT{} \CLASS{} $Id_2<U_1 \ldots U_{k_{M_2}}, V_1 \ldots V_{k_S}> =
S<V_1 \ldots V_{k_S}>$ \WITH{} $M_2<U_1 \ldots U_{k_{M_2}}>$; } | 1807 \begin{dartCode} |
| 1808 \ABSTRACT{} \CLASS{} $Id_2<U_1 \ldots U_{k_{M_2}}, V_1 \ldots V_{k_S}> =$ |
| 1809 $S<V_1 \ldots V_{k_S}>$ \WITH{} $M_2<U_1 \ldots U_{k_{
M_2}}>$; |
| 1810 \end{dartCode} |
2298 | 1811 |
2299 and $Id_1$ and $Id_2$ are unique identifiers that do not exist anywhere in the p
rogram. | 1812 and $Id_1$ and $Id_2$ are unique identifiers that do not exist anywhere in the p
rogram. |
2300 | 1813 |
2301 \rationale{ | 1814 \rationale{ |
2302 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. | 1815 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. |
2303 } | 1816 } |
2304 | 1817 |
2305 Mixin composition is associative. | 1818 Mixin composition is associative. |
2306 | 1819 |
2307 | 1820 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2568 m1() \{ | 2081 m1() \{ |
2569 \VAR{} z = \FALSE{}; | 2082 \VAR{} z = \FALSE{}; |
2570 \IF{} (z) \{\RETURN{} x; \} | 2083 \IF{} (z) \{\RETURN{} x; \} |
2571 \ELSE{} \{ \RETURN{} 2;\} | 2084 \ELSE{} \{ \RETURN{} 2;\} |
2572 \} | 2085 \} |
2573 | 2086 |
2574 m2() \{ | 2087 m2() \{ |
2575 \IF{} (\TRUE{}) \{\RETURN{} y; \} | 2088 \IF{} (\TRUE{}) \{\RETURN{} y; \} |
2576 \ELSE{} \{ \RETURN{} 3;\} | 2089 \ELSE{} \{ \RETURN{} 3;\} |
2577 \} | 2090 \} |
2578 | |
2579 \} | 2091 \} |
2580 | |
2581 \end{dartCode} | 2092 \end{dartCode} |
2582 | 2093 |
2583 \commentary{An implementation is free to immediately issue a compilation error f
or \code{x}, but it is not required to do so. It could defer errors if it does
not immediately compile the declarations that reference \code{x}. For example,
it could delay giving a compilation error about the method \code{m1} until the f
irst invocation of \code{m1}. However, it could not choose to execute \code{m1},
see that the branch that refers to \code{x} is not taken and return 2 successf
ully. | 2094 \commentary{An implementation is free to immediately issue a compilation error f
or \code{x}, but it is not required to do so. It could defer errors if it does
not immediately compile the declarations that reference \code{x}. For example,
it could delay giving a compilation error about the method \code{m1} until the f
irst invocation of \code{m1}. However, it could not choose to execute \code{m1},
see that the branch that refers to \code{x} is not taken and return 2 successf
ully. |
2584 | 2095 |
2585 The situation with respect to an invocation \code{m2} is different. Because \cod
e{y} is not a compile-time constant (even though its value is), one need not giv
e a compile-time error upon compiling \code{m2}. An implementation may run the c
ode, which will cause the getter for \code{y} to be invoked. At that point, the
initialization of \code{y} must take place, which requires the initializer to b
e compiled, which will cause a compilation error. | 2096 The situation with respect to an invocation \code{m2} is different. Because \cod
e{y} is not a compile-time constant (even though its value is), one need not giv
e a compile-time error upon compiling \code{m2}. An implementation may run the c
ode, which will cause the getter for \code{y} to be invoked. At that point, the
initialization of \code{y} must take place, which requires the initializer to b
e compiled, which will cause a compilation error. |
2586 } | 2097 } |
2587 | 2098 |
2588 \rationale{ | 2099 \rationale{ |
2589 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: | 2100 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: |
2590 \begin{enumerate} | 2101 \begin{enumerate} |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2841 } | 2352 } |
2842 | 2353 |
2843 Strings support escape sequences for special characters. The escapes are: | 2354 Strings support escape sequences for special characters. The escapes are: |
2844 \begin{itemize} | 2355 \begin{itemize} |
2845 \item $\backslash$n for newline, equivalent to $\backslash$x0A. | 2356 \item $\backslash$n for newline, equivalent to $\backslash$x0A. |
2846 \item $\backslash$r for carriage return, equivalent to $\backslash$x0D. | 2357 \item $\backslash$r for carriage return, equivalent to $\backslash$x0D. |
2847 \item $\backslash$f for form feed, equivalent to $\backslash$x0C. | 2358 \item $\backslash$f for form feed, equivalent to $\backslash$x0C. |
2848 \item $\backslash$b for backspace, equivalent to $\backslash$x08. | 2359 \item $\backslash$b for backspace, equivalent to $\backslash$x08. |
2849 \item $\backslash$t for tab, equivalent to $\backslash$x09. | 2360 \item $\backslash$t for tab, equivalent to $\backslash$x09. |
2850 \item $\backslash$v for vertical tab, equivalent to $\backslash$x0B | 2361 \item $\backslash$v for vertical tab, equivalent to $\backslash$x0B |
2851 \item $\backslash$x $HEX\_DIGIT_1$ $HEX\_DIGIT_2$, equivalent to $\backslash$u\{
$HEX\_DIGIT_1$ $HEX\_DIGIT_2$\}. | 2362 \item $\backslash$x $HEX\_DIGIT_1$ $HEX\_DIGIT_2$, equivalent to |
| 2363 |
| 2364 $\backslash$u\{$HEX\_DIGIT_1$ $HEX\_DIGIT_2$\}. |
2852 \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$\}. | 2365 \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$\}. |
2853 \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. | 2366 \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. |
2854 \item \$ indicating the beginning of an interpolated expression. | 2367 \item \$ indicating the beginning of an interpolated expression. |
2855 \item Otherwise, $\backslash k$ indicates the character $k$ for any $k$ not in $
\{n, r, f, b, t, v, x, u\}$. | 2368 \item Otherwise, $\backslash k$ indicates the character $k$ for any $k$ not in $
\{n, r, f, b, t, v, x, u\}$. |
2856 \end{itemize} | 2369 \end{itemize} |
2857 | 2370 |
2858 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. | 2371 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. |
2859 | 2372 |
2860 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. | 2373 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. |
2861 | 2374 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3021 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\}$. | 2534 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\}$. |
3022 | 2535 |
3023 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$)}. | 2536 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$)}. |
3024 | 2537 |
3025 \commentary{In other words, constant map literals are canonicalized.} | 2538 \commentary{In other words, constant map literals are canonicalized.} |
3026 | 2539 |
3027 A runtime map literal $<K, V>\{k_1:e_1\ldots k_n :e_n\}$ is evaluated as follow
s: | 2540 A runtime map literal $<K, V>\{k_1:e_1\ldots k_n :e_n\}$ is evaluated as follow
s: |
3028 \begin{itemize} | 2541 \begin{itemize} |
3029 \item | 2542 \item |
3030 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$. | 2543 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$. |
3031 \item A fresh instance (\ref{generativeConstructors}) $m$ whose class implement
s the built-in class $Map<K, V>$ is allocated. | 2544 \item A fresh instance (\ref{generativeConstructors}) $m$ whose class implement
s the built-in class |
| 2545 |
| 2546 $Map<K, V>$ is allocated. |
3032 \item | 2547 \item |
3033 The operator \code{[]=} is invoked on $m$ with first argument $u_i$ and second
argument $o_i, i \in 1.. n$. | 2548 The operator \code{[]=} is invoked on $m$ with first argument $u_i$ and second
argument $o_i, i \in 1.. n$. |
3034 \item | 2549 \item |
3035 The result of the evaluation is $m$. | 2550 The result of the evaluation is $m$. |
3036 \end{itemize} | 2551 \end{itemize} |
3037 | 2552 |
3038 | 2553 |
3039 A runtime map literal $\{k_1:e_1\ldots k_n :e_n\}$ is evaluated as $<\DYNAMIC{
}, \DYNAMIC{}>\{k_1:e_1\ldots k_n :e_n\}$. | 2554 A runtime map literal $\{k_1:e_1\ldots k_n :e_n\}$ is evaluated as |
| 2555 |
| 2556 $<\DYNAMIC{}, \DYNAMIC{}>\{k_1:e_1\ldots k_n :e_n\}$. |
3040 | 2557 |
3041 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. | 2558 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. |
3042 | 2559 |
3043 A map literal is ordered: iterating over the keys and/or values of the maps alwa
ys happens in the | 2560 A map literal is ordered: iterating over the keys and/or values of the maps alwa
ys happens in the |
3044 order the keys appeared in the source code. | 2561 order the keys appeared in the source code. |
3045 | 2562 |
3046 \commentary{ | 2563 \commentary{ |
3047 Of course, if a key repeats, the order is defined by first occurrence, but the v
alue is defined by the last. | 2564 Of course, if a key repeats, the order is defined by first occurrence, but the v
alue is defined by the last. |
3048 } | 2565 } |
3049 | 2566 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3098 . | 2615 . |
3099 \end{grammar} | 2616 \end{grammar} |
3100 | 2617 |
3101 The class of a function literal implements the built-in class \code{Function}.
| 2618 The class of a function literal implements the built-in class \code{Function}.
|
3102 %Invoking the getter \code{runtimeType} on a function literal returns the \code{
Type} object that is the value of the expression \code{Function}. | 2619 %Invoking the getter \code{runtimeType} on a function literal returns the \code{
Type} object that is the value of the expression \code{Function}. |
3103 % not necessarily | 2620 % not necessarily |
3104 | 2621 |
3105 | 2622 |
3106 %Q{Can anyone implement it? Then we should define things via call} | 2623 %Q{Can anyone implement it? Then we should define things via call} |
3107 | 2624 |
3108 The static type of 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 $(T_1 \l
dots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarrow T_0$, whe
re $T_0$ is the static type of $e$. In any case where $T_i, 1 \le i \le n+k$, is
not specified, it is considered to have been specified as \DYNAMIC{}. | 2625 The static type of a function literal of the form |
3109 | 2626 |
3110 The static type of 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 $(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$. In any case where $T_i, 1 \le i \le n+k$
, is not specified, it is considered to have been specified as \DYNAMIC{}. | 2627 $(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$ |
3111 | 2628 |
3112 The static type of 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])\{s\}$ is $(T_1 \l
dots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarrow \DYNAMIC
{}$. In any case where $T_i, 1 \le i \le n+k$, is not specified, it is considere
d to have been specified as \DYNAMIC{}. | 2629 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro
w T_0$, where $T_0$ is the static type of $e$. In any case where $T_i, 1 \le i \
le n+k$, is not specified, it is considered to have been specified as \DYNAMIC{
}. |
3113 | 2630 |
3114 The static type of 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\})\{s\}$ is $(T_1
\ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightarrow \DY
NAMIC{}$. In any case where $T_i, 1 \le i \le n+k$, is not specified, it is cons
idered to have been specified as \DYNAMIC{}. | 2631 The static type of a function literal of the form |
| 2632 |
| 2633 $(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$ |
| 2634 |
| 2635 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar
row T_0$, where $T_0$ is the static type of $e$. In any case where $T_i, 1 \le i
\le n+k$, is not specified, it is considered to have been specified as \DYNAMI
C{}. |
| 2636 |
| 2637 The static type of a function literal of the form |
| 2638 |
| 2639 $(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\}$ |
| 2640 |
| 2641 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro
w \DYNAMIC{}$. In any case where $T_i, 1 \le i \le n+k$, is not specified, it i
s considered to have been specified as \DYNAMIC{}. |
| 2642 |
| 2643 The static type of a function literal of the form |
| 2644 |
| 2645 $(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\}$ |
| 2646 |
| 2647 is $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightar
row \DYNAMIC{}$. In any case where $T_i, 1 \le i \le n+k$, is not specified, it
is considered to have been specified as \DYNAMIC{}. |
3115 | 2648 |
3116 %** Now that declared return types are precluded, do we need some better return
type rule for (x){s} and friends? | 2649 %** Now that declared return types are precluded, do we need some better return
type rule for (x){s} and friends? |
3117 | 2650 |
3118 | 2651 |
3119 | 2652 |
3120 \subsection{ This} | 2653 \subsection{ This} |
3121 \label{this} | 2654 \label{this} |
3122 | 2655 |
3123 The reserved word \THIS{} denotes the target of the current instance member invo
cation. | 2656 The reserved word \THIS{} denotes the target of the current instance member invo
cation. |
3124 | 2657 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3219 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{}. | 2752 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{}. |
3220 | 2753 |
3221 \commentary{ | 2754 \commentary{ |
3222 Observe that \THIS{} is not in scope in $e_f$. Hence, the initialization cannot
depend on other properties of the object being instantiated. | 2755 Observe that \THIS{} is not in scope in $e_f$. Hence, the initialization cannot
depend on other properties of the object being instantiated. |
3223 } | 2756 } |
3224 | 2757 |
3225 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$. | 2758 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$. |
3226 | 2759 |
3227 Otherwise, $q$ is a factory constructor (\ref{factories}). Then: | 2760 Otherwise, $q$ is a factory constructor (\ref{factories}). Then: |
3228 | 2761 |
3229 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 $[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}))$}. | 2762 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 |
| 2763 |
| 2764 $[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}))$}. |
3230 | 2765 |
3231 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$. | 2766 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$. |
3232 | 2767 |
3233 It is a static warning if $q$ is a constructor of an abstract class and $q$ is n
ot a factory constructor. | 2768 It is a static warning if $q$ is a constructor of an abstract class and $q$ is n
ot a factory constructor. |
3234 | 2769 |
3235 \commentary{The above gives precise meaning to the idea that instantiating an ab
stract class leads to a warning. | 2770 \commentary{The above gives precise meaning to the idea that instantiating an ab
stract class leads to a warning. |
3236 A similar clause applies to constant object creation in the next section. | 2771 A similar clause applies to constant object creation in the next section. |
3237 } | 2772 } |
3238 | 2773 |
3239 \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. | 2774 \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. |
(...skipping 16 matching lines...) Expand all Loading... |
3256 \label{const} | 2791 \label{const} |
3257 | 2792 |
3258 A {\em constant object expression} invokes a constant constructor (\ref{constant
Constructors}). | 2793 A {\em constant object expression} invokes a constant constructor (\ref{constant
Constructors}). |
3259 | 2794 |
3260 \begin{grammar} | 2795 \begin{grammar} |
3261 {\bf constObjectExpression:} | 2796 {\bf constObjectExpression:} |
3262 \CONST{} type ('{\escapegrammar .}' identifier)? arguments | 2797 \CONST{} type ('{\escapegrammar .}' identifier)? arguments |
3263 . | 2798 . |
3264 \end{grammar} | 2799 \end{grammar} |
3265 | 2800 |
3266 Let $e$ be a constant object expression of the form \CONST{} $T.id(a_1, \ldots
, a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ 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. | 2801 Let $e$ be a constant object expression of the form |
| 2802 |
| 2803 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ |
| 2804 |
| 2805 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. |
3267 | 2806 |
3268 \commentary{In particular, $T$ may not be a type variable.} | 2807 \commentary{In particular, $T$ may not be a type variable.} |
3269 | 2808 |
3270 If $T$ is a parameterized type, it is a compile-time error if $T$ includes a typ
e variable among its type arguments. | 2809 If $T$ is a parameterized type, it is a compile-time error if $T$ includes a typ
e variable among its type arguments. |
3271 | 2810 |
3272 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$. | 2811 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$. |
3273 | 2812 |
3274 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. | 2813 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. |
3275 | 2814 |
3276 %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$. | 2815 %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$. |
3277 %Finally, | 2816 %Finally, |
3278 % If $T$ is a generic with $l$ retype parameters, then for all $ i \in 1 .. l$,
let $V_i = \DYNAMIC{}$. | 2817 % If $T$ is a generic with $l$ retype parameters, then for all $ i \in 1 .. l$,
let $V_i = \DYNAMIC{}$. |
3279 | 2818 |
3280 Evaluation of $e$ proceeds as follows: | 2819 Evaluation of $e$ proceeds as follows: |
3281 | 2820 |
3282 First, 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})$ then let $i$ be the value of the expression \NEW{}
$T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. Otherwis
e, $e$ must be of the form | 2821 First, if $e$ is of the form |
| 2822 |
| 2823 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ |
| 2824 |
| 2825 then let $i$ be the value of the expression |
| 2826 |
| 2827 \NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. |
| 2828 |
| 2829 Otherwise, $e$ must be of the form |
3283 | 2830 |
3284 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, | 2831 \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$, |
3285 | 2832 |
3286 in which case let $i$ be the result of evaluating \NEW{} $T(a_1, \ldots , a_n, x
_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. Then: | 2833 in which case let $i$ be the result of evaluating |
| 2834 |
| 2835 \NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$. |
| 2836 |
| 2837 Then: |
3287 \begin{itemize} | 2838 \begin{itemize} |
3288 \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: | 2839 \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: |
3289 \begin{itemize} | 2840 \begin{itemize} |
3290 \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$. | 2841 \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$. |
3291 \end{itemize} | 2842 \end{itemize} |
3292 \item Otherwise the value of $e$ is $i$. | 2843 \item Otherwise the value of $e$ is $i$. |
3293 \end{itemize} | 2844 \end{itemize} |
3294 | 2845 |
3295 \commentary{ | 2846 \commentary{ |
3296 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. | 2847 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. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3351 As discussed in section \ref{errorsAndWarnings}, the handling of a suspended iso
late is the responsibility of the embedder. | 2902 As discussed in section \ref{errorsAndWarnings}, the handling of a suspended iso
late is the responsibility of the embedder. |
3352 } | 2903 } |
3353 | 2904 |
3354 \subsection{ Property Extraction} | 2905 \subsection{ Property Extraction} |
3355 \label{propertyExtraction} | 2906 \label{propertyExtraction} |
3356 | 2907 |
3357 {\em Property extraction} allows for a member of an object to be concisely extra
cted from the object. | 2908 {\em Property extraction} allows for a member of an object to be concisely extra
cted from the object. |
3358 If $e$ is an expression that evaluates to an object $o$, and if $m$ is the name
of a concrete method member of $e$, then $e.m$ is defined to be equivalent to: | 2909 If $e$ is an expression that evaluates to an object $o$, and if $m$ is the name
of a concrete method member of $e$, then $e.m$ is defined to be equivalent to: |
3359 | 2910 |
3360 \begin{itemize} | 2911 \begin{itemize} |
3361 %\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$. | |
3362 %\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$. | |
3363 %\item | |
3364 | 2912 |
3365 % so the issue is that o is not an expression, but we don't want to bind to e, a
s its evaluation | 2913 \item |
3366 % could have side effects, result in different objects at different times etc. | 2914 \begin{dartCode} |
3367 % so we use u, where u is a fresh final variable bound to o | 2915 $(r_1, \ldots, r_n, \{p_1 : d_1, \ldots , p_k : d_k\})$ \{ |
3368 % | 2916 \RETURN{} $ u.m(r_1, \ldots, r_n, p_1: p_1, \ldots, p_k: p_k);$ |
3369 \item $(r_1, \ldots, r_n, \{p_1 : d_1, \ldots , p_k : d_k\})\{$\RETURN{} $u.m(r
_1, \ldots, r_n, p_1: p_1, \ldots, p_k: p_k);\}$ if $m$ has required parameters
$r_1, \ldots, r_n$, and named parameters $p_1, \ldots, p_k$ with defaults $d_1,
\ldots, d_k$. | 2917 \} |
3370 \item $(r_1, \ldots, r_n, [p_1 = d_1, \ldots , p_k = d_k])\{$\RETURN{} $u.m(r_1,
\ldots, r_n, p_1, \ldots, p_k);\}$ if $m$ has required parameters $r_1, \ldots,
r_n$, and optional positional parameters $p_1, \ldots, p_k$ with defaults $d_1,
\ldots, d_k$. | 2918 \end{dartCode} |
| 2919 |
| 2920 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$. |
| 2921 \item |
| 2922 \begin{dartCode} |
| 2923 $(r_1, \ldots, r_n, [p_1 = d_1, \ldots , p_k = d_k])$\{ |
| 2924 \RETURN{} $u.m(r_1, \ldots, r_n, p_1, \ldots, p_k)$; |
| 2925 \} |
| 2926 \end{dartCode} |
| 2927 |
| 2928 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$. |
3371 \end{itemize} | 2929 \end{itemize} |
3372 | 2930 |
3373 where $u$ is a fresh final variable bound to $o$, except that: | 2931 where $u$ is a fresh final variable bound to $o$, except that: |
3374 \begin{enumerate} | 2932 \begin{enumerate} |
3375 \item iff \code{identical($o_1, o_2$)} then \cd{$o_1.m$ == $o_2.m$}. | 2933 \item iff \code{identical($o_1, o_2$)} then \cd{$o_1.m$ == $o_2.m$}. |
3376 \item The static type of the property extraction is the static type of function
$T.m$, where $T$ is the static type of $e$, if $T.m$ is defined. Otherwise the s
tatic type of $e.m$ is \DYNAMIC{}. | 2934 \item The static type of the property extraction is the static type of function
$T.m$, where $T$ is the static type of $e$, if $T.m$ is defined. Otherwise the s
tatic type of $e.m$ is \DYNAMIC{}. |
3377 \end{enumerate} | 2935 \end{enumerate} |
3378 | 2936 |
3379 \commentary{ | 2937 \commentary{ |
3380 There is no guarantee that \cd{identical($o_1.m, o_2.m$)}. Dart implementations
are not required to canonicalize these or any other closures. | 2938 There is no guarantee that \cd{identical($o_1.m, o_2.m$)}. Dart implementations
are not required to canonicalize these or any other closures. |
(...skipping 15 matching lines...) Expand all Loading... |
3396 \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. | 2954 \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. |
3397 \end{enumerate} | 2955 \end{enumerate} |
3398 } | 2956 } |
3399 | 2957 |
3400 Let $S$ be the superclass of the immediately enclosing class. If $m$ is the name
of a concrete method member of $S$, then the expression $\SUPER{}.m$ is define
d to be equivalent to: | 2958 Let $S$ be the superclass of the immediately enclosing class. If $m$ is the name
of a concrete method member of $S$, then the expression $\SUPER{}.m$ is define
d to be equivalent to: |
3401 | 2959 |
3402 \begin{itemize} | 2960 \begin{itemize} |
3403 %\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$. | 2961 %\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$. |
3404 %\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$. | 2962 %\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$. |
3405 %\item | 2963 %\item |
3406 \item $(r_1, \ldots, r_n, \{p_1 : d_1, \ldots , p_k : d_k\})\{$\RETURN{} $\SUPE
R{}.m(r_1, \ldots, r_n, p_1: p_1, \ldots, p_k: p_k);\}$ if $m$ has required para
meters $r_1, \ldots, r_n$, and named parameters $p_1, \ldots, p_k$ with defaults
$d_1, \ldots, d_k$. | 2964 \item |
3407 \item $(r_1, \ldots, r_n, [p_1 = d_1, \ldots , p_k = d_k])\{$\RETURN{} $\SUPER{}
.m(r_1, \ldots, r_n, p_1, \ldots, p_k);\}$ if $m$ has required parameters $r_1,
\ldots, r_n$, and optional positional parameters $p_1, \ldots, p_k$ with default
s $d_1, \ldots, d_k$. | 2965 \begin{dartCode} |
| 2966 $(r_1, \ldots, r_n, \{p_1 : d_1, \ldots , p_k : d_k\})$\{ |
| 2967 \RETURN{} \SUPER{}$.m(r_1, \ldots, r_n, p_1: p_1, \ldots, p_k: p_k)$; |
| 2968 \} |
| 2969 \end{dartCode} |
| 2970 |
| 2971 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$. |
| 2972 \item |
| 2973 \begin{dartCode} |
| 2974 $(r_1, \ldots, r_n, [p_1 = d_1, \ldots , p_k = d_k])$\{ |
| 2975 \RETURN{} \SUPER{}$.m(r_1, \ldots, r_n, p_1, \ldots, p_k)$; |
| 2976 \} |
| 2977 \end{dartCode} |
| 2978 |
| 2979 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$. |
3408 \end{itemize} | 2980 \end{itemize} |
3409 | 2981 |
3410 Except that: | 2982 Except that: |
3411 \begin{enumerate} | 2983 \begin{enumerate} |
3412 \item iff \code{identical($o_1, o_2$)} then \cd{$o_1.m$ == $o_2.m$}. | 2984 \item iff \code{identical($o_1, o_2$)} then \cd{$o_1.m$ == $o_2.m$}. |
3413 \item | 2985 \item |
3414 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{}
. | 2986 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{}
. |
3415 \end{enumerate} | 2987 \end{enumerate} |
3416 | 2988 |
3417 Otherwise | 2989 Otherwise |
(...skipping 27 matching lines...) Expand all Loading... |
3445 % expressionList ',' spreadArgument; | 3017 % expressionList ',' spreadArgument; |
3446 expressionList (`,' namedArgument)* | 3018 expressionList (`,' namedArgument)* |
3447 % spreadArgument | 3019 % spreadArgument |
3448 . | 3020 . |
3449 | 3021 |
3450 {\bf namedArgument:} | 3022 {\bf namedArgument:} |
3451 label expression % could be top level expression? | 3023 label expression % could be top level expression? |
3452 . | 3024 . |
3453 \end{grammar} | 3025 \end{grammar} |
3454 | 3026 |
3455 Evaluation of an actual argument list of the form $(a_1, \ldots, a_m, q_1: a_{m+
1}, \ldots, q_l: a_{m+l})$ proceeds as follows: | 3027 Evaluation of an actual argument list of the form |
| 3028 |
| 3029 $(a_1, \ldots, a_m, q_1: a_{m+1}, \ldots, q_l: a_{m+l})$ |
| 3030 |
| 3031 proceeds as follows: |
3456 | 3032 |
3457 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}$. | 3033 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}$. |
3458 | 3034 |
3459 \commentary{Simply stated, an argument list consisting of $m$ positional argumen
ts and $l$ named arguments is evaluated from left to right. | 3035 \commentary{Simply stated, an argument list consisting of $m$ positional argumen
ts and $l$ named arguments is evaluated from left to right. |
3460 } | 3036 } |
3461 | 3037 |
3462 | 3038 |
3463 \subsubsection{ Binding Actuals to Formals} | 3039 \subsubsection{ Binding Actuals to Formals} |
3464 \label{bindingActualsToFormals} | 3040 \label{bindingActualsToFormals} |
3465 | 3041 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3622 identifier | 3198 identifier |
3623 . | 3199 . |
3624 \end{grammar} | 3200 \end{grammar} |
3625 | 3201 |
3626 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$)}. | 3202 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$)}. |
3627 | 3203 |
3628 \subsubsection{Static Invocation} | 3204 \subsubsection{Static Invocation} |
3629 \label{staticInvocation} | 3205 \label{staticInvocation} |
3630 | 3206 |
3631 A static method invocation $i$ has the form | 3207 A static method invocation $i$ has the form |
3632 $C.m(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ where $C$
denotes a class in the current scope. | 3208 |
| 3209 $C.m(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ |
| 3210 |
| 3211 where $C$ denotes a class in the current scope. |
3633 | 3212 |
3634 It is a static warning if $C$ does not declare a static method or getter $m$. | 3213 It is a static warning if $C$ does not declare a static method or getter $m$. |
3635 | 3214 |
3636 \rationale{ | 3215 \rationale{ |
3637 Note that the absence of $C.m$ is statically detectable. Nevertheless, we choose
not to define this situation as an error. The goal is to allow coding to proce
ed in the order that suits the developer rather than eagerly insisting on consis
tency. The warnings are given statically at compile-time to help developers catc
h errors. However, developers need not correct these problems immediately in ord
er to make progress. | 3216 Note that the absence of $C.m$ is statically detectable. Nevertheless, we choose
not to define this situation as an error. The goal is to allow coding to proce
ed in the order that suits the developer rather than eagerly insisting on consis
tency. The warnings are given statically at compile-time to help developers catc
h errors. However, developers need not correct these problems immediately in ord
er to make progress. |
3638 } | 3217 } |
3639 | 3218 |
3640 \commentary{ | 3219 \commentary{ |
3641 Note the requirement that $C$ {\em declare} the method. This means that static m
ethods declared in superclasses of $C$ cannot be invoked via $C$. | 3220 Note the requirement that $C$ {\em declare} the method. This means that static m
ethods declared in superclasses of $C$ cannot be invoked via $C$. |
3642 } | 3221 } |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4186 | 3765 |
4187 \end{grammar} | 3766 \end{grammar} |
4188 | 3767 |
4189 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$
. | 3768 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$
. |
4190 | 3769 |
4191 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\}()}. | 3770 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\}()}. |
4192 | 3771 |
4193 \rationale{The above ensures that if $v$ is a field, the getter gets called exac
tly once. Likewise in the cases below. | 3772 \rationale{The above ensures that if $v$ is a field, the getter gets called exac
tly once. Likewise in the cases below. |
4194 } | 3773 } |
4195 | 3774 |
4196 A postfix expression of the form \code{$C.v$ ++} is equivalent to \code{()\{var
r = $C.v$; $C.v$ = r + 1; return r\}()}. | 3775 A postfix expression of the form \code{$C.v$ ++} is equivalent to |
4197 | 3776 |
4198 A postfix expression of the form \code{$e_1.v$++} is equivalent to \code{(x)\{va
r r = x.v; x.v = r + 1; \RETURN{} r\}($e_1$)}. | 3777 \code{()\{var r = $C.v$; $C.v$ = r + 1; return r\}()}. |
4199 | 3778 |
4200 A postfix expression of the form \code{$e_1[e_2]$++}, is equivalent to \code{(a
, i)\{var r = a[i]; a[i] = r + 1; return r\}($e_1$, $e_2$)}. | 3779 A postfix expression of the form \code{$e_1.v$++} is equivalent to |
4201 | 3780 |
4202 A postfix expression of the form \code{$v$-{}-}, where $v$ is an identifier, is
equivalent to \code{()\{var r = $v$; $v$ = r - 1; return r\}()}. | 3781 \code{(x)\{var r = x.v; x.v = r + 1; \RETURN{} r\}($e_1$)}. |
4203 | 3782 |
4204 A postfix expression of the form \code{$C.v$-{}-} is equivalent to \code{()\{var
r = $C.v$; $C.v$ = r - 1; return r\}()}. | 3783 A postfix expression of the form \code{$e_1[e_2]$++}, is equivalent to |
4205 | 3784 |
4206 A postfix expression of the form \code{$e_1.v$-{}-} is equivalent to \code{(x)\{
var r = x.v; x.v = r - 1; \RETURN{} r\}($e_1$)}. | 3785 \code{(a, i)\{var r = a[i]; a[i] = r + 1; return r\}($e_1$, $e_2$)}. |
4207 | 3786 |
4208 A postfix expression of the form \code{$e_1[e_2]$-{}-}, is equivalent to \code{
(a, i)\{var r = a[i]; a[i] = r - 1; return r\}($e_1$, $e_2$)}. | 3787 A postfix expression of the form \code{$v$-{}-}, where $v$ is an identifier, is
equivalent to |
| 3788 |
| 3789 \code{()\{var r = $v$; $v$ = r - 1; return r\}()}. |
| 3790 |
| 3791 A postfix expression of the form \code{$C.v$-{}-} is equivalent to |
| 3792 |
| 3793 \code{()\{var r = $C.v$; $C.v$ = r - 1; return r\}()}. |
| 3794 |
| 3795 A postfix expression of the form \code{$e_1.v$-{}-} is equivalent to |
| 3796 |
| 3797 \code{(x)\{var r = x.v; x.v = r - 1; \RETURN{} r\}($e_1$)}. |
| 3798 |
| 3799 A postfix expression of the form \code{$e_1[e_2]$-{}-}, is equivalent to |
| 3800 |
| 3801 \code{(a, i)\{var r = a[i]; a[i] = r - 1; return r\}($e_1$, $e_2$)}. |
4209 | 3802 |
4210 | 3803 |
4211 \subsection{ Assignable Expressions} | 3804 \subsection{ Assignable Expressions} |
4212 \label{assignableExpressions} | 3805 \label{assignableExpressions} |
4213 | 3806 |
4214 Assignable expressions are expressions that can appear on the left hand side of
an assignment. | 3807 Assignable expressions are expressions that can appear on the left hand side of
an assignment. |
4215 This section describes how to evaluate these expressions when they do not consti
tute the complete left hand side of an assignment. | 3808 This section describes how to evaluate these expressions when they do not consti
tute the complete left hand side of an assignment. |
4216 | 3809 |
4217 \rationale{ | 3810 \rationale{ |
4218 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. | 3811 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. |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4768 | 4361 |
4769 {\bf switchCase:} | 4362 {\bf switchCase:} |
4770 label* (\CASE{} expression `{\escapegrammar :}') statements | 4363 label* (\CASE{} expression `{\escapegrammar :}') statements |
4771 . | 4364 . |
4772 | 4365 |
4773 {\bf defaultCase:} | 4366 {\bf defaultCase:} |
4774 label* \DEFAULT{} `{\escapegrammar :}' statements | 4367 label* \DEFAULT{} `{\escapegrammar :}' statements |
4775 . | 4368 . |
4776 \end{grammar} | 4369 \end{grammar} |
4777 | 4370 |
4778 Given a switch statement of the form \code{\SWITCH{} ($e$) \{ \CASE{} $label_{1
1} \ldots label_{1j_1}$ $e_1: s_1 \ldots$ \CASE{} $label_{n1} \ldots label_{nj_
n}$ $e_n: s_n$ \DEFAULT{}: $s_{n+1}$ \}} or the form \code{\SWITCH{} ($e$) \{ \C
ASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1 \ldots$ \CASE{} $label_{n1} \l
dots label_{nj_n}$ $e_n: s_n$ \}}, it is a compile-time error if the expressions
$e_k$ are not compile-time constants for all $k \in 1..n$. It is a compile-ti
me error if the values of the expressions $e_k$ are not either: | 4371 Given a switch statement of the form |
| 4372 |
| 4373 \begin{dartCode} |
| 4374 \SWITCH{} ($e$) \{ |
| 4375 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ |
| 4376 $\ldots$ |
| 4377 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ |
| 4378 \DEFAULT{}: $s_{n+1}$ |
| 4379 \} |
| 4380 \end{dartCode} |
| 4381 |
| 4382 or the form |
| 4383 |
| 4384 \begin{dartCode} |
| 4385 \SWITCH{} ($e$) \{ |
| 4386 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ |
| 4387 $\ldots$ |
| 4388 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ |
| 4389 \} |
| 4390 \end{dartCode} |
| 4391 |
| 4392 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: |
4779 \begin{itemize} | 4393 \begin{itemize} |
4780 \item instances of the same class $C$, for all $k \in 1..n$, or | 4394 \item instances of the same class $C$, for all $k \in 1..n$, or |
4781 \item instances of a class that implements \cd{int}, for all $k \in 1..n$, or | 4395 \item instances of a class that implements \cd{int}, for all $k \in 1..n$, or |
4782 \item instances of a class that implements \cd{String}, for all $k \in 1..n$. | 4396 \item instances of a class that implements \cd{String}, for all $k \in 1..n$. |
4783 \end{itemize} | 4397 \end{itemize} |
4784 | 4398 |
4785 \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. | 4399 \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. |
4786 } | 4400 } |
4787 | 4401 |
4788 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 or an integer. | 4402 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 or an integer. |
4789 | 4403 |
4790 \rationale{ | 4404 \rationale{ |
4791 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. | 4405 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. |
4792 | 4406 |
4793 } | 4407 } |
4794 | 4408 |
4795 \commentary{ | 4409 \commentary{ |
4796 The \SWITCH{} statement should only be used in very limited situations (e.g., i
nterpreters or scanners). | 4410 The \SWITCH{} statement should only be used in very limited situations (e.g., i
nterpreters or scanners). |
4797 } | 4411 } |
4798 | 4412 |
4799 Execution of a switch statement of the form \code{\SWITCH{} ($e$) \{ \CASE{} $la
bel_{11} \ldots label_{1j_1}$ $e_1: s_1 \ldots$ \CASE{} $label_{n1} \ldots labe
l_{nj_n}$ $e_n: s_n$ \DEFAULT{}: $s_{n+1}$ \}} or the form \code{\SWITCH{} ($e$)
\{ \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1 \ldots$ \CASE{} $label_{
n1} \ldots label_{nj_n}$ $e_n: s_n$ \}} proceeds as follows: | 4413 Execution of a switch statement of the form |
| 4414 |
| 4415 \begin{dartCode} |
| 4416 \SWITCH{} ($e$) \{ |
| 4417 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ |
| 4418 $\ldots$ |
| 4419 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ |
| 4420 \DEFAULT{}: $s_{n+1}$ |
| 4421 \} |
| 4422 \end{dartCode} |
| 4423 |
| 4424 or the form |
| 4425 |
| 4426 \begin{dartCode} |
| 4427 \SWITCH{} ($e$) \{ |
| 4428 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ |
| 4429 $\ldots$ |
| 4430 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ |
| 4431 \} |
| 4432 \end{dartCode} |
| 4433 |
| 4434 proceeds as follows: |
4800 | 4435 |
4801 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$. | 4436 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$. |
4802 | 4437 |
4803 \commentary{Note that if there are no case clauses ($n = 0$), the type of $e$ do
es not matter.} | 4438 \commentary{Note that if there are no case clauses ($n = 0$), the type of $e$ do
es not matter.} |
4804 | 4439 |
4805 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}$. | 4440 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}$. |
4806 | 4441 |
4807 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. | 4442 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. |
4808 | 4443 |
4809 Execution of a \CASE{} clause \CASE{} $e_{k}: s_{k}$ of a switch statement \co
de{\SWITCH{} ($e$) \{ $label_{11} \ldots label_{1j_1}$ \CASE{} $e_1: s_1 \ldots
$ $label_{n1} \ldots label_{nj_n}$ \CASE{} $e_n: s_n$ \DEFAULT{}: $s_{n+1}$ \}}
proceeds as follows: | 4444 Execution of a \CASE{} clause \CASE{} $e_{k}: s_{k}$ of a switch statement |
| 4445 |
| 4446 \begin{dartCode} |
| 4447 \SWITCH{} ($e$) \{ |
| 4448 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ |
| 4449 $\ldots$ |
| 4450 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ |
| 4451 \DEFAULT{}: $s_{n+1}$ |
| 4452 \} |
| 4453 \end{dartCode} |
| 4454 |
| 4455 proceeds as follows: |
4810 | 4456 |
4811 The expression \code{$e_k$ == id} is evaluated to an object $o$ which is then su
bjected to boolean conversion yielding a value $v$. | 4457 The expression \code{$e_k$ == id} is evaluated to an object $o$ which is then su
bjected to boolean conversion yielding a value $v$. |
4812 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}$. | 4458 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}$. |
4813 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. | 4459 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. |
4814 If execution reaches the point after $s_h$ then a runtime error occurs, unless
$h = n+1$. | 4460 If execution reaches the point after $s_h$ then a runtime error occurs, unless
$h = n+1$. |
4815 | 4461 |
4816 Execution of a \CASE{} clause \CASE{} $e_{k}: s_{k}$ of a switch statement \co
de{\SWITCH{} ($e$) \{ $label_{11} \ldots label_{1j_1}$ \CASE{} $e_1: s_1 \ldots
$ $label_{n1} \ldots label_{nj_n}$ \CASE{} $e_n: s_n$ \}} proceeds as follows: | 4462 Execution of a \CASE{} clause \CASE{} $e_{k}: s_{k}$ of a switch statement |
| 4463 |
| 4464 \begin{dartCode} |
| 4465 \SWITCH{} ($e$) \{ |
| 4466 \CASE{} $label_{11} \ldots label_{1j_1}$ $e_1: s_1$ |
| 4467 $\ldots$ |
| 4468 \CASE{} $label_{n1} \ldots label_{nj_n}$ $e_n: s_n$ |
| 4469 \} |
| 4470 \end{dartCode} |
| 4471 |
| 4472 proceeds as follows: |
4817 | 4473 |
4818 The expression \code{$e_k$ == id} is evaluated to an object $o$ which is then su
bjected to boolean conversion yielding a value $v$. | 4474 The expression \code{$e_k$ == id} is evaluated to an object $o$ which is then su
bjected to boolean conversion yielding a value $v$. |
4819 If $v$ is not \TRUE{} the following case, \CASE{} $e_{k+1}: s_{k+1}$ is execut
ed if it exists. | 4475 If $v$ is not \TRUE{} the following case, \CASE{} $e_{k+1}: s_{k+1}$ is execut
ed if it exists. |
4820 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. | 4476 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. |
4821 If execution reaches the point after $s_h$ then a runtime error occurs, unless
$h = n$. | 4477 If execution reaches the point after $s_h$ then a runtime error occurs, unless
$h = n$. |
4822 | 4478 |
4823 | 4479 |
4824 \commentary{ | 4480 \commentary{ |
4825 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
. | 4481 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
. |
4826 } | 4482 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4895 \item | 4551 \item |
4896 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. | 4552 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. |
4897 \item | 4553 \item |
4898 A \FINALLY{} clause, which consists of a block statement. | 4554 A \FINALLY{} clause, which consists of a block statement. |
4899 \end{enumerate} | 4555 \end{enumerate} |
4900 | 4556 |
4901 \rationale{ | 4557 \rationale{ |
4902 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. | 4558 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. |
4903 } | 4559 } |
4904 | 4560 |
4905 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 type, then performing a match causes a run time error. | 4561 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 type, then performing a match causes a run time error. |
4906 | 4562 |
4907 \commentary { | 4563 \commentary { |
4908 It is of course a static warning if $T$ is a malformed type (\ref{staticTypes}). | 4564 It is of course a static warning if $T$ is a malformed type (\ref{staticTypes}). |
4909 } | 4565 } |
4910 | 4566 |
| 4567 An \ON{}-\CATCH{} clause of the form \code{\ON{} $T$ \CATCH{} ($p_1, p_2$) $s$
} introduces a new scope $CS$ in which local variables specified by $p_1$ and $p
_2$ are defined. The statement $s$ is enclosed within $CS$. |
| 4568 |
| 4569 |
4911 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.
| 4570 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.
|
4912 | 4571 |
4913 | 4572 |
4914 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$} | 4573 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$} |
4915 | 4574 |
4916 | 4575 |
4917 %If an explicit type is associated with of $p_2$, it is a static warning if that
type is not \code{Object} or \DYNAMIC{}. | 4576 %If an explicit type is associated with of $p_2$, it is a static warning if that
type is not \code{Object} or \DYNAMIC{}. |
4918 | 4577 |
4919 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 was thrown. | 4578 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 was thrown. |
4920 %\begin{enumerate} | 4579 %\begin{enumerate} |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5033 in a generative constructor. The rules relate only to the specific syntactic for
m \code{\RETURN{} $e$;}. | 4692 in a generative constructor. The rules relate only to the specific syntactic for
m \code{\RETURN{} $e$;}. |
5034 } | 4693 } |
5035 | 4694 |
5036 | 4695 |
5037 \rationale{ | 4696 \rationale{ |
5038 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. | 4697 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. |
5039 | 4698 |
5040 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. | 4699 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. |
5041 } | 4700 } |
5042 | 4701 |
5043 It is a static warning if a function contains both one or more return statements
of the form \code{\RETURN;} and one or more return statements of the form \code
{\RETURN{} $e$;}. | 4702 It is a static warning if a function contains both one or more explicit return s
tatements of the form \code{\RETURN;} and one or more return statements of the f
orm \code{\RETURN{} $e$;}. |
5044 | 4703 |
5045 | 4704 |
5046 \subsection{ Labels} | 4705 \subsection{ Labels} |
5047 \label{labels} | 4706 \label{labels} |
5048 | 4707 |
5049 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$. | 4708 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$. |
5050 | 4709 |
5051 \rationale{The sole role of labels is to provide targets for the break (\ref{bre
ak}) and continue (\ref{continue}) statements.} | 4710 \rationale{The sole role of labels is to provide targets for the break (\ref{bre
ak}) and continue (\ref{continue}) statements.} |
5052 | 4711 |
5053 %\Q{Are labels in a separate namespace? Bug 49774299} | 4712 %\Q{Are labels in a separate namespace? Bug 49774299} |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5279 \code{\HIDE{} $id_1, \ldots, id_k$} | 4938 \code{\HIDE{} $id_1, \ldots, id_k$} |
5280 | 4939 |
5281 then let $NS_i = \HIDE{}([id_1, \ldots, id_k], NS_{i-1}$) | 4940 then let $NS_i = \HIDE{}([id_1, \ldots, id_k], NS_{i-1}$) |
5282 | 4941 |
5283 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. | 4942 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. |
5284 \end{itemize} | 4943 \end{itemize} |
5285 | 4944 |
5286 Next, if $I$ includes a prefix clause of the form \AS{} $p$, let $NS = prefix(p
, NS_n)$ where $prefix(id, n)$, takes an identifier $id$ and produces a namespac
e that has, for each entry mapping key $k$ to declaration $d$ in $n$, an entry
mapping $id.k$ to $d$. Otherwise, let $NS = NS_n$. | 4945 Next, if $I$ includes a prefix clause of the form \AS{} $p$, let $NS = prefix(p
, NS_n)$ where $prefix(id, n)$, takes an identifier $id$ and produces a namespac
e that has, for each entry mapping key $k$ to declaration $d$ in $n$, an entry
mapping $id.k$ to $d$. Otherwise, let $NS = NS_n$. |
5287 It is a compile-time error if the current library declares a top-level member na
med $p$. | 4946 It is a compile-time error if the current library declares a top-level member na
med $p$. |
5288 | 4947 |
| 4948 % 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 |
| 4949 % either. After all, p isn't actually available as a stand alone name. |
| 4950 |
5289 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: | 4951 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: |
5290 \begin{itemize} | 4952 \begin{itemize} |
5291 \item | 4953 \item |
5292 a top-level declaration with the name $k$ exists in $L$, OR | 4954 a top-level declaration with the name $k$ exists in $L$, OR |
5293 \item a prefix clause of the form \AS{} $k$ is used in $L$. | 4955 \item a prefix clause of the form \AS{} $k$ is used in $L$. |
5294 \end{itemize} | 4956 \end{itemize} |
5295 | 4957 |
5296 \rationale{The greatly increases the chance that a member can be added to a libr
ary without breaking its importers.} | 4958 \rationale{The greatly increases the chance that a member can be added to a libr
ary without breaking its importers.} |
5297 | 4959 |
5298 If a name $N$ is referenced by a library $L$ and $N$ would be introduced into th
e top level scope of $L$ by an import from a library whose URI begins with \code
{dart:} and an import from a library whose URI does not begin with \code{dart:}: | 4960 If a name $N$ is referenced by a library $L$ and $N$ would be introduced into th
e top level scope of $L$ by an import from a library whose URI begins with \code
{dart:} and an import from a library whose URI does not begin with \code{dart:}: |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5433 . | 5095 . |
5434 \end{grammar} | 5096 \end{grammar} |
5435 | 5097 |
5436 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. | 5098 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. |
5437 | 5099 |
5438 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. | 5100 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. |
5439 | 5101 |
5440 \subsection{Scripts} | 5102 \subsection{Scripts} |
5441 \label{scripts} | 5103 \label{scripts} |
5442 | 5104 |
5443 A {\em script} is a library whose exported namespace (\ref{exports}) includes a
top-level function \code{main()}. | 5105 A {\em script} is a library whose exported namespace (\ref{exports}) includes a
top-level function \code{main}. |
5444 A script $S$ may be executed as follows: | 5106 A script $S$ may be executed as follows: |
5445 | 5107 |
5446 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 with no a
rguments. It is a run time error if $S$ does not declare or import a top-level f
unction \code{main()}. | 5108 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 with no arg
uments. It is a run time error if $S$ does not declare or import a top-level fun
ction \code{main}. |
5447 | 5109 |
5448 \rationale{ | 5110 \rationale{ |
5449 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. | 5111 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. |
5450 } | 5112 } |
5451 | 5113 |
5452 \commentary { | 5114 \commentary { |
5453 A Dart program will typically be executed by executing a script. | 5115 A Dart program will typically be executed by executing a script. |
5454 } | 5116 } |
5455 | 5117 |
5456 \subsection{URIs} | 5118 \subsection{URIs} |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5980 The least upper bound of \VOID{} and any type $T \ne \DYNAMIC{}$ is \VOID{}. | 5642 The least upper bound of \VOID{} and any type $T \ne \DYNAMIC{}$ is \VOID{}. |
5981 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$. | 5643 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$. |
5982 | 5644 |
5983 The least upper bound relation is symmetric and reflexive. | 5645 The least upper bound relation is symmetric and reflexive. |
5984 | 5646 |
5985 % Function types | 5647 % Function types |
5986 | 5648 |
5987 The least upper bound of a function type and an interface type $T$ is the least
upper bound of \cd{Function} and $T$. | 5649 The least upper bound of a function type and an interface type $T$ is the least
upper bound of \cd{Function} and $T$. |
5988 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: | 5650 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: |
5989 \begin{itemize} | 5651 \begin{itemize} |
5990 \item If $F= (T_1 \ldots T_r, [T_{r+1}, \ldots, T_n]) \longrightarrow T_0$ and $
G= (S_1 \ldots S_r, [S_{r+1}, \ldots, S_k]) \longrightarrow S_0$ where $k \le n$
then the least upper bound of $F$ and $G$ is $(L_1 \ldots L_r, [L_{r+1}, \ldots
, L_k]) \longrightarrow L_0$ where $L_i$ is the least upper bound of $T_i$ and $
S_i, i \in 0..k$. | 5652 \item If |
5991 \item If $F= (T_1 \ldots T_r, [T_{r+1}, \ldots, T_n]) \longrightarrow T_0$ and $
G= (S_1 \ldots S_r, \{ \ldots \}) \longrightarrow S_0$ then the least upper boun
d of $F$ and $G$ is $(L_1 \ldots L_r) \longrightarrow L_0$ where $L_i$ is the le
ast upper bound of $T_i$ and $S_i, i \in 0..r$. | 5653 |
5992 \item If $F= (T_1 \ldots T_r, \{T_{r+1}$ $p_{r+1}, \ldots, T_f$ $p_f\}) \longri
ghtarrow T_0$ and $G= (S_1 \ldots S_r, \{ S_{r+1}$ $q_{r+1}, \ldots, S_g$ $q_g\
}) \longrightarrow S_0$ 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 t
ypes of $x_j$ in $F$ and $G, j \in m..n$. Then | 5654 $F= (T_1 \ldots T_r, [T_{r+1}, \ldots, T_n]) \longrightarrow T_0$, |
5993 the least upper bound of $F$ and $G$ is $(L_1 \ldots L_r, \{ X_m$ $x_m, \ldots,
X_n$ $x_n\}) \longrightarrow L_0$ where $L_i$ is the least upper bound of $T_i$
and $S_i, i \in 0..r$ | 5655 |
| 5656 $G= (S_1 \ldots S_r, [S_{r+1}, \ldots, S_k]) \longrightarrow S_0$ |
| 5657 |
| 5658 where $k \le n$ then the least upper bound of $F$ and $G$ is |
| 5659 |
| 5660 $(L_1 \ldots L_r, [L_{r+1}, \ldots, L_k]) \longrightarrow L_0$ |
| 5661 |
| 5662 where $L_i$ is the least upper bound of $T_i$ and $S_i, i \in 0..k$. |
| 5663 \item If |
| 5664 |
| 5665 $F= (T_1 \ldots T_r, [T_{r+1}, \ldots, T_n]) \longrightarrow T_0$, |
| 5666 |
| 5667 $G= (S_1 \ldots S_r, \{ \ldots \}) \longrightarrow S_0$ |
| 5668 |
| 5669 then the least upper bound of $F$ and $G$ is |
| 5670 |
| 5671 $(L_1 \ldots L_r) \longrightarrow L_0$ |
| 5672 |
| 5673 where $L_i$ |
| 5674 is the least upper bound of $T_i$ and $S_i, i \in 0..r$. |
| 5675 \item If |
| 5676 |
| 5677 $F= (T_1 \ldots T_r, \{T_{r+1}$ $p_{r+1}, \ldots, T_f$ $p_f\}) \longrightarrow
T_0$, |
| 5678 |
| 5679 $G= (S_1 \ldots S_r, \{ S_{r+1}$ $q_{r+1}, \ldots, S_g$ $q_g\}) \longrightarrow
S_0$ |
| 5680 |
| 5681 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 |
| 5682 the least upper bound of $F$ and $G$ is |
| 5683 |
| 5684 $(L_1 \ldots L_r, \{ X_m$ $x_m, \ldots, X_n$ $x_n\}) \longrightarrow L_0$ |
| 5685 |
| 5686 where $L_i$ is the least upper bound of $T_i$ and $S_i, i \in 0..r$ |
5994 \end{itemize} | 5687 \end{itemize} |
5995 | 5688 |
5996 | 5689 |
5997 \section{Reference} | 5690 \section{Reference} |
5998 \label{reference} | 5691 \label{reference} |
5999 | 5692 |
6000 \subsection{Lexical Rules} | 5693 \subsection{Lexical Rules} |
6001 \label{lexicalRules} | 5694 \label{lexicalRules} |
6002 | 5695 |
6003 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. | 5696 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. |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6114 \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. | 5807 \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. |
6115 \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 | 5808 \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 |
6116 \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. | 5809 \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. |
6117 \item The names of type variables are short (preferably single letter). Examples
: T, S, K, V , E. | 5810 \item The names of type variables are short (preferably single letter). Examples
: T, S, K, V , E. |
6118 \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. | 5811 \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. |
6119 \end{itemize} | 5812 \end{itemize} |
6120 } | 5813 } |
6121 | 5814 |
6122 | 5815 |
6123 \end{document} | 5816 \end{document} |
OLD | NEW |