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

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

Issue 2998173002: Specify what "is equivalent to" means. (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 \documentclass{article} 1 \documentclass{article}
2 \usepackage{epsfig} 2 \usepackage{epsfig}
3 \usepackage{color} 3 \usepackage{color}
4 \usepackage{dart} 4 \usepackage{dart}
5 \usepackage{bnf} 5 \usepackage{bnf}
6 \usepackage{hyperref} 6 \usepackage{hyperref}
7 \usepackage{lmodern} 7 \usepackage{lmodern}
8 \usepackage[T1]{fontenc} 8 \usepackage[T1]{fontenc}
9 \newcommand{\code}[1]{{\sf #1}} 9 \newcommand{\code}[1]{{\sf #1}}
10 \title{Dart Programming Language Specification \\ 10 \title{Dart Programming Language Specification \\
11 {5th edition draft}\\ 11 {5th edition draft}\\
12 {\large Version 2.0.0-dev}} 12 {\large Version 2.0.0-dev}}
13 13
14 % For information about Location Markers (and in particular the 14 % For information about Location Markers (and in particular the
15 % commands \LMHash and \LMLabel), see the long comment at the 15 % commands \LMHash and \LMLabel), see the long comment at the
16 % end of this file. 16 % end of this file.
17 17
18 % CHANGES 18 % CHANGES
19 % ======= 19 % =======
20 % Significant changes to the specification. 20 % Significant changes to the specification.
21 % 21 %
22 % 2.0 22 % 2.0
23 % - Don't allow functions as assert test values. 23 % - Don't allow functions as assert test values.
24 % - Start running "async" functions synchronously. 24 % - Start running "async" functions synchronously.
25 % - Specify what "is equivalent to" means.
25 % 26 %
26 % 1.15 27 % 1.15
27 % - Change how language specification describes control flow. 28 % - Change how language specification describes control flow.
28 % - Object initialization now specifies initialization order correctly. 29 % - Object initialization now specifies initialization order correctly.
29 % - Specifies that leaving an await-for loop must wait for the subscription 30 % - Specifies that leaving an await-for loop must wait for the subscription
30 % to be canceled. 31 % to be canceled.
31 % - An await-for loop only pauses the subscription if it does something async. 32 % - An await-for loop only pauses the subscription if it does something async.
32 % - Assert statements allows a "message" operand and a trailing comma. 33 % - Assert statements allows a "message" operand and a trailing comma.
33 % - The Null type is now considered a subtype of all types in most cases. 34 % - The Null type is now considered a subtype of all types in most cases.
34 % - Specify what NEWLINE means in multiline strings. 35 % - Specify what NEWLINE means in multiline strings.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 The notation $[x_1, \ldots, x_n/y_1, \ldots, y_n]E$ denotes a copy of $E$ in whi ch all occurrences of $y_i, 1 \le i \le n$ have been replaced with $x_i$. 178 The notation $[x_1, \ldots, x_n/y_1, \ldots, y_n]E$ denotes a copy of $E$ in whi ch all occurrences of $y_i, 1 \le i \le n$ have been replaced with $x_i$.
178 179
179 \LMHash{} 180 \LMHash{}
180 We sometimes abuse list or map literal syntax, writing $[o_1, \ldots, o_n]$ (re spectively $\{k_1: o_1, \ldots, k_n: o_n\}$) where the $o_i$ and $k_i$ may be ob jects rather than expressions. The intent is to denote a list (respectively map) object whose elements are the $o_i$ (respectively, whose keys are the $k_i$ and values are the $o_i$). 181 We sometimes abuse list or map literal syntax, writing $[o_1, \ldots, o_n]$ (re spectively $\{k_1: o_1, \ldots, k_n: o_n\}$) where the $o_i$ and $k_i$ may be ob jects rather than expressions. The intent is to denote a list (respectively map) object whose elements are the $o_i$ (respectively, whose keys are the $k_i$ and values are the $o_i$).
181 182
182 \LMHash{} 183 \LMHash{}
183 The specifications of operators often involve statements such as $x$ $op$ $y$ is equivalent to the method invocation $x.op(y)$. Such specifications should be un derstood as a shorthand for: 184 The specifications of operators often involve statements such as $x$ $op$ $y$ is equivalent to the method invocation $x.op(y)$. Such specifications should be un derstood as a shorthand for:
184 \begin{itemize} 185 \begin{itemize}
185 \item 186 \item
186 $x$ $op$ $y$ is equivalent to the method invocation $x.op^\prime(y)$, assuming the class of $x$ actually declared a non-operator method named $op^\prime$ defin ing the same function as the operator $op$. 187 $x$ $op$ $y$ is equivalent to the method invocation $x.op^\prime(y)$, assuming the class of $x$ actually declared a non-operator method named $op^\prime$ defin ing the same function as the operator $op$.
187 \end{itemize} 188 \end{itemize}
188 189
189 \rationale{This circumlocution is required because x.op(y), where op is an oper ator, is not legal syntax. However, it is painfully verbose, and we prefer to st ate this rule once here, and use a concise and clear notation across the specifi cation. 190 \rationale{This circumlocution is required because x.op(y), where op is an oper ator, is not legal syntax. However, it is painfully verbose, and we prefer to st ate this rule once here, and use a concise and clear notation across the specifi cation.
190 } 191 }
191 192
192 \LMHash{} 193 \LMHash{}
193 When the specification refers to the order given in the program, it means the or der of the program source code text, scanning left-to-right and top-to-bottom. 194 When the specification refers to the order given in the program, it means the or der of the program source code text, scanning left-to-right and top-to-bottom.
194 195
195 \LMHash{} 196 \LMHash{}
196 When the specification refers to a {\em fresh variable}, it means a variable wit h a name that doesn't occur anywhere in the current program. 197 When the specification refers to a {\em fresh variable}, it means a variable wit h a name that doesn't occur anywhere in the current program.
197 When the specification introduces a fresh variable bound to a value, the fresh v ariable is implicitly bound in a surrounding scope. 198 When the specification introduces a fresh variable bound to a value, the fresh v ariable is implicitly bound in a surrounding scope.
198 199
199 \LMHash{} 200 \LMHash{}
200 References to otherwise unspecified names of program entities (such as classes o r functions) are interpreted as the names of members of the Dart core library. 201 References to otherwise unspecified names of program entities (such as classes o r functions) are interpreted as the names of members of the Dart core library.
201 202
202 \commentary{ 203 \commentary{
203 Examples would be the classes \code{Object} and \code{Type} representing the roo t of the class hierarchy and the reification of runtime types respectively. 204 Examples would be the classes \code{Object} and \code{Type} representing the roo t of the class hierarchy and the reification of runtime types respectively.
204 } 205 }
205 206
207 \LMHash{}
208 When the specification says that one piece of syntax "is equivalent to" another syntax, it means that it is equivalent in all ways, and the former syntax should generate the same static warnings and have the same runtime behavior as the lat ter.
eernst 2017/08/21 10:15:20 `"is equivalent to"` --> `{\em is equivalent to}`,
Lasse Reichstein Nielsen 2017/08/22 05:32:13 Done.
209 \commentary {
210 If the syntax contains errors, implementations should obviously ensure that erro r messages only refer to the original syntax.
eernst 2017/08/21 10:15:20 Maybe `Error messages, if any, should always refer
Lasse Reichstein Nielsen 2017/08/22 05:32:09 Done.
211 }
212 If execution or evaluation of a construct is said to be equivalent with executio n or evaluation of another construct, then only the runtime behavior is equivale nt, and only the static warnings or errors mentioned for the original syntax app lies.
eernst 2017/08/21 10:15:21 Might as well use `equivalent to` everywhere (`wit
Lasse Reichstein Nielsen 2017/08/22 05:32:10 Done.
206 \section{Overview} 213 \section{Overview}
207 \LMLabel{overview} 214 \LMLabel{overview}
208 215
209 \LMHash{} 216 \LMHash{}
210 Dart is a class-based, single-inheritance, pure object-oriented programming lang uage. Dart is optionally typed (\ref{types}) and supports reified generics. The run-time type of every object is represented as an instance of class \code{Type} which can be obtained by calling the getter \code{runtimeType} declared in cl ass \code{Object}, the root of the Dart class hierarchy. 217 Dart is a class-based, single-inheritance, pure object-oriented programming lang uage. Dart is optionally typed (\ref{types}) and supports reified generics. The run-time type of every object is represented as an instance of class \code{Type} which can be obtained by calling the getter \code{runtimeType} declared in cl ass \code{Object}, the root of the Dart class hierarchy.
211 218
212 \LMHash{} 219 \LMHash{}
213 Dart programs may be statically checked. The static checker will report some vio lations of the type rules, but such violations do not abort compilation or precl ude execution. 220 Dart programs may be statically checked. The static checker will report some vio lations of the type rules, but such violations do not abort compilation or precl ude execution.
214 221
215 \LMHash{} 222 \LMHash{}
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 \begin{grammar} 828 \begin{grammar}
822 {\bf defaultFormalParameter:} 829 {\bf defaultFormalParameter:}
823 normalFormalParameter (`=' expression)? 830 normalFormalParameter (`=' expression)?
824 . 831 .
825 832
826 {\bf defaultNamedParameter:}normalFormalParameter (`=' expression)?; 833 {\bf defaultNamedParameter:}normalFormalParameter (`=' expression)?;
827 normalFormalParameter ( `{\escapegrammar :}' expression)? 834 normalFormalParameter ( `{\escapegrammar :}' expression)?
828 . 835 .
829 \end{grammar} 836 \end{grammar}
830 837
831 A {\bf defaultNamedParameter} on the form: 838 A {\bf defaultNamedParameter} of the form:
eernst 2017/08/21 10:15:21 I actually looked at this one at some point. Googl
Lasse Reichstein Nielsen 2017/08/22 05:32:11 Agree, and I have probably added all five of them.
832 \begin{code} 839 \begin{code}
833 normalFormalParameter : expression 840 normalFormalParameter : expression
834 \end{code} 841 \end{code}
835 is equivalent to one on the form: 842 is equivalent to one of the form:
eernst 2017/08/21 10:15:20 Ditto.
836 \begin{code} 843 \begin{code}
837 normalFormalParameter = expression 844 normalFormalParameter = expression
838 \end{code} 845 \end{code}
839 The colon-syntax is included only for backwards compatibility. 846 The colon-syntax is included only for backwards compatibility.
840 It is deprecated and will be removed in a later version of the language specific ation. 847 It is deprecated and will be removed in a later version of the language specific ation.
841 848
842 \LMHash{} 849 \LMHash{}
843 It is a compile-time error if the default value of an optional parameter is not a compile-time constant (\ref{constants}). If no default is explicitly specified for an optional parameter an implicit default of \NULL{} is provided. 850 It is a compile-time error if the default value of an optional parameter is not a compile-time constant (\ref{constants}). If no default is explicitly specified for an optional parameter an implicit default of \NULL{} is provided.
844 851
845 \LMHash{} 852 \LMHash{}
(...skipping 3109 matching lines...) Expand 10 before | Expand all | Expand 10 after
3955 3962
3956 If $e_f$ is a property extraction expression (\ref{propertyExtraction}), then $i $ isn't a function expression invocation and is instead recognized as an ordinar y method invocation (\ref{ordinaryInvocation}). 3963 If $e_f$ is a property extraction expression (\ref{propertyExtraction}), then $i $ isn't a function expression invocation and is instead recognized as an ordinar y method invocation (\ref{ordinaryInvocation}).
3957 3964
3958 \commentary{ 3965 \commentary{
3959 \code{$a.b(x)$} is parsed as a method invocation of method \code{$b()$} on objec t \code{$a$}, not as an invocation of getter \code{$b$} on \code{$a$} followed b y a function call \code{$(a.b)(x)$}. If a method or getter \code{$b$} exists, t he two will be equivalent. However, if \code{$b$} is not defined on \code{$a$}, the resulting invocation of \code{noSuchMethod()} would differ. The \code{Invoc ation} passed to \code{noSuchMethod()} would describe a call to a method \code{$ b$} with argument \code{$x$} in the former case, and a call to a getter \code{$b $} (with no arguments) in the latter. 3966 \code{$a.b(x)$} is parsed as a method invocation of method \code{$b()$} on objec t \code{$a$}, not as an invocation of getter \code{$b$} on \code{$a$} followed b y a function call \code{$(a.b)(x)$}. If a method or getter \code{$b$} exists, t he two will be equivalent. However, if \code{$b$} is not defined on \code{$a$}, the resulting invocation of \code{noSuchMethod()} would differ. The \code{Invoc ation} passed to \code{noSuchMethod()} would describe a call to a method \code{$ b$} with argument \code{$x$} in the former case, and a call to a getter \code{$b $} (with no arguments) in the latter.
3960 } 3967 }
3961 3968
3962 \LMHash{} 3969 \LMHash{}
3963 Otherwise: 3970 Otherwise:
3964 3971
3965 A function expression invocation $e_f(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldot s , x_{n+k}: a_{n+k})$ is equivalent to $e_f.call(a_1, \ldots , a_n, x_{n+1}: a_ {n+1}, \ldots , x_{n+k}: a_{n+k})$. 3972 Execution of a function expression invocation $e_f(a_1, \ldots , a_n, x_{n+1}: a _{n+1}, \ldots , x_{n+k}: a_{n+k})$ is equivalent to execution of $e_f.call(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$.
3966 3973
3967 \commentary{ 3974 \commentary{
3968 The implication of this definition, and the other definitions involving the meth od \code{call()}, is that user defined types can be used as function values prov ided they define a \CALL{} method. The method \CALL{} is special in this regard. The signature of the \CALL{} method determines the signature used when using th e object via the built-in invocation syntax. 3975 The implication of this definition, and the other definitions involving the meth od \code{call()}, is that user defined types can be used as function values prov ided they define a \CALL{} method. The method \CALL{} is special in this regard. The signature of the \CALL{} method determines the signature used when using th e object via the built-in invocation syntax.
3969 } 3976 }
3970 3977
3971 \LMHash{} 3978 \LMHash{}
3972 It is a static warning if the static type $F$ of $e_f$ may not be assigned to a function type. If $F$ is not a function type, the static type of $i$ is \DYNAMI C{}. Otherwise 3979 It is a static warning if the static type $F$ of $e_f$ may not be assigned to a function type. If $F$ is not a function type, the static type of $i$ is \DYNAMI C{}. Otherwise
3973 the static type of $i$ is the declared return type of $F$. 3980 the static type of $i$ is the declared return type of $F$.
3974 %\item Let $T_i$ be the static type of $a_i, i \in 1 .. n+k$. It is a static war ning if $F$ is not a supertype of $(T_1, \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldot s, T_{n+k}$ $x_{n+k}]) \to \bot$. 3981 %\item Let $T_i$ be the static type of $a_i, i \in 1 .. n+k$. It is a static war ning if $F$ is not a supertype of $(T_1, \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldot s, T_{n+k}$ $x_{n+k}]) \to \bot$.
3975 %\end{itemize} 3982 %\end{itemize}
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after
4889 \LMHash{} 4896 \LMHash{}
4890 An {\em equality expression} is either a relational expression (\ref{relationalE xpressions}), or an invocation of an equality operator on either \SUPER{} or an expression $e_1$, with argument $e_2$. 4897 An {\em equality expression} is either a relational expression (\ref{relationalE xpressions}), or an invocation of an equality operator on either \SUPER{} or an expression $e_1$, with argument $e_2$.
4891 4898
4892 4899
4893 \LMHash{} 4900 \LMHash{}
4894 Evaluation of an equality expression $ee$ of the form \code{$e_1$ == $e_2$} proc eeds as follows: 4901 Evaluation of an equality expression $ee$ of the form \code{$e_1$ == $e_2$} proc eeds as follows:
4895 \begin{itemize} 4902 \begin{itemize}
4896 \item The expression $e_1$ is evaluated to an object $o_1$. 4903 \item The expression $e_1$ is evaluated to an object $o_1$.
4897 \item The expression $e_2$ is evaluated to an object $o_2$. 4904 \item The expression $e_2$ is evaluated to an object $o_2$.
4898 \item If either $o_1$ or $o_2$ is \NULL{}, then $ee$ evaluates to \TRUE{} if bot h $o_1$ and $o_2$ are \NULL{} and to \FALSE{} otherwise. Otherwise, 4905 \item If either $o_1$ or $o_2$ is \NULL{}, then $ee$ evaluates to \TRUE{} if bot h $o_1$ and $o_2$ are \NULL{} and to \FALSE{} otherwise. Otherwise,
4899 \item $ee$ is equivalent to the method invocation \code{$o_1$.==($o_2$)}. 4906 \item evaluation of $ee$ is equivalent to the method invocation \code{$o_1$.==($ o_2$)}.
4900 \end{itemize} 4907 \end{itemize}
4901 4908
4902 4909
4903 \LMHash{} 4910 \LMHash{}
4904 Evaluation of an equality expression $ee$ of the form \code{\SUPER{} == $e$} pro ceeds as follows: 4911 Evaluation of an equality expression $ee$ of the form \code{\SUPER{} == $e$} pro ceeds as follows:
4905 \begin{itemize} 4912 \begin{itemize}
4906 \item The expression $e$ is evaluated to an object $o$. 4913 \item The expression $e$ is evaluated to an object $o$.
4907 \item If either \THIS{} or $o$ is \NULL{}, then $ee$ evaluates to evaluates to \ TRUE{} if both \THIS{} and $o$ are \NULL{} and to \FALSE{} otherwise. Otherwise, 4914 \item If either \THIS{} or $o$ is \NULL{}, then $ee$ evaluates to evaluates to \ TRUE{} if both \THIS{} and $o$ are \NULL{} and to \FALSE{} otherwise. Otherwise,
4908 \item $ee$ is equivalent to the method invocation \code{\SUPER{}.==($o$)}. 4915 \item evaluation of $ee$ is equivalent to the method invocation \code{\SUPER{}.= =($o$)}.
4909 \end{itemize} 4916 \end{itemize}
4910 4917
4911 \commentary{As a result of the above definition, user defined \code{==} methods can assume that their argument is non-null, and avoid the standard boiler-plate prelude: 4918 \commentary{As a result of the above definition, user defined \code{==} methods can assume that their argument is non-null, and avoid the standard boiler-plate prelude:
4912 4919
4913 \code{if (identical(\NULL{}, arg)) return \FALSE{};} 4920 \code{if (identical(\NULL{}, arg)) return \FALSE{};}
4914 4921
4915 Another implication is that there is never a need to use \code{identical()} to t est against \NULL{}, nor should anyone ever worry about whether to write \NULL{} == $e$ or $e$ == \NULL{}. 4922 Another implication is that there is never a need to use \code{identical()} to t est against \NULL{}, nor should anyone ever worry about whether to write \NULL{} == $e$ or $e$ == \NULL{}.
4916 } 4923 }
4917 4924
4918 \LMHash{} 4925 \LMHash{}
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
4974 {\bf bitwiseOperator:}`\&'; 4981 {\bf bitwiseOperator:}`\&';
4975 `\^{}'; 4982 `\^{}';
4976 `$|$' 4983 `$|$'
4977 . 4984 .
4978 \end{grammar} 4985 \end{grammar}
4979 4986
4980 \LMHash{} 4987 \LMHash{}
4981 A {\em bitwise expression} is either a shift expression (\ref{shift}), or an inv ocation of a bitwise operator on either \SUPER{} or an expression $e_1$, with ar gument $e_2$. 4988 A {\em bitwise expression} is either a shift expression (\ref{shift}), or an inv ocation of a bitwise operator on either \SUPER{} or an expression $e_1$, with ar gument $e_2$.
4982 4989
4983 \LMHash{} 4990 \LMHash{}
4984 A bitwise expression of the form $e_1$ $op$ $e_2$ is equivalent to the method invocation $e_1.op(e_2)$. 4991 A bitwise expression of the form $e_1$ $op$ $e_2$ is equivalent to the method i nvocation $e_1.op(e_2)$.
eernst 2017/08/21 10:15:20 Can't really see any changes, but we might as well
Lasse Reichstein Nielsen 2017/08/22 05:32:11 I removed a leading space, but yes, fixing double-
4985 A bitwise expression of the form \code{\SUPER{} $op$ $e_2$} is equivalent to th e method invocation \code{\SUPER{}.op($e_2$)}. 4992 A bitwise expression of the form \code{\SUPER{} $op$ $e_2$} is equivalent to th e method invocation \code{\SUPER{}.op($e_2$)}.
eernst 2017/08/21 10:15:20 Font typo: should be `$op$`. Double space.
Lasse Reichstein Nielsen 2017/08/22 05:32:11 Done.
4986 4993
4987 \commentary{ 4994 \commentary{
4988 It should be obvious that the static type rules for these expressions are define d by the equivalence above - ergo, by the type rules for method invocation and t he signatures of the operators on the type $e_1$. The same holds in similar situ ations throughout this specification. 4995 It should be obvious that the static type rules for these expressions are define d by the equivalence above - ergo, by the type rules for method invocation and t he signatures of the operators on the type $e_1$. The same holds in similar situ ations throughout this specification.
4989 } 4996 }
4990 4997
4991 4998
4992 \subsection{ Shift} 4999 \subsection{ Shift}
4993 \LMLabel{shift} 5000 \LMLabel{shift}
4994 5001
4995 \LMHash{} 5002 \LMHash{}
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
5103 {\bf tildeOperator:} `\~{}' 5110 {\bf tildeOperator:} `\~{}'
5104 . 5111 .
5105 5112
5106 5113
5107 \end{grammar} 5114 \end{grammar}
5108 5115
5109 \LMHash{} 5116 \LMHash{}
5110 A {\em unary expression} is either a postfix expression (\ref{postfixExpression s}), an await expression (\ref{awaitExpressions}) or an invocation of a prefix o perator on an expression or an invocation of a unary operator on either \SUPER{} or an expression $e$. 5117 A {\em unary expression} is either a postfix expression (\ref{postfixExpression s}), an await expression (\ref{awaitExpressions}) or an invocation of a prefix o perator on an expression or an invocation of a unary operator on either \SUPER{} or an expression $e$.
5111 5118
5112 \LMHash{} 5119 \LMHash{}
5113 The expression $!e$ is equivalent to the expression $e?$ $ \FALSE{} :\TRUE{}$. 5120 The expression $!e$ is equivalent to the expression \code{$e$ ? \FALSE{} : \TRUE {}}.
5114 5121
5115 \LMHash{} 5122 \LMHash{}
5116 Evaluation of an expression of the form \code{++$e$} is equivalent to \code{$e$ += 1}. Evaluation of an expression of the form \code{-{}-$e$} is equivalent to \code{$e$ -= 1}. 5123 Evaluation of an expression of the form \code{++$e$} is equivalent to \code{$e$ += 1}. Evaluation of an expression of the form \code{-{}-$e$} is equivalent to \code{$e$ -= 1}.
5117 5124
5118 %The expression $-e$ is equivalent to the method invocation \code{$e$.-()}. The expression \code{-\SUPER{}} is equivalent to the method invocation \code{\SUPE R{}.-()}. 5125 %The expression $-e$ is equivalent to the method invocation \code{$e$.-()}. The expression \code{-\SUPER{}} is equivalent to the method invocation \code{\SUPE R{}.-()}.
5119 5126
5120 \LMHash{} 5127 \LMHash{}
5121 An expression of the form \code{$op$ $e$} is equivalent to the method invocation \code{$e.op()$}. An expression of the form \code{$op$ \SUPER{}} is equivalent t o the method invocation (\ref{superInvocation}) \code{\SUPER{}.$op()$}. 5128 An expression of the form \code{$op$ $e$} is equivalent to the method invocation \code{$e.op()$}. An expression of the form \code{$op$ \SUPER{}} is equivalent t o the method invocation (\ref{superInvocation}) \code{\SUPER{}.$op()$}.
5122 5129
5123 \subsection{ Await Expressions} 5130 \subsection{ Await Expressions}
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
5308 Evaluate \code{$a$[$i$]} to an object $r$ 5315 Evaluate \code{$a$[$i$]} to an object $r$
5309 and let $y$ be a fresh variable bound to $r$. 5316 and let $y$ be a fresh variable bound to $r$.
5310 Evaluate \code{$a$[$i$] = $y$ - 1}. 5317 Evaluate \code{$a$[$i$] = $y$ - 1}.
5311 Then $e$ evaluates to $r$. 5318 Then $e$ evaluates to $r$.
5312 5319
5313 \LMHash{} 5320 \LMHash{}
5314 The static type of such an expression is the static type of \code{$e_1$[$e_2$]}. 5321 The static type of such an expression is the static type of \code{$e_1$[$e_2$]}.
5315 5322
5316 \LMHash{} 5323 \LMHash{}
5317 Evaluation of a postfix expression $e$ of the form \code{$e_1$?.$v$++} 5324 Evaluation of a postfix expression $e$ of the form \code{$e_1$?.$v$++}
5318 where $e_1$ is not a type literal, proceeds as follows: 5325 where $e_1$ is not a type literal, proceeds as follows:
eernst 2017/08/21 10:15:20 Delete `where $e_1$ is not a type literal, `: The
Lasse Reichstein Nielsen 2017/08/22 05:32:13 Done.
5319 5326
5320 \LMHash{} 5327 \LMHash{}
5321 If $e_1$ is a type literal, $e$ is equivalent to \code{$e_1$.$v$++}. 5328 If $e_1$ is a type literal, evaluation of $e$ is equivalent to
5329 evaluation of \code{$e_1$.$v$++}.
5322 5330
5323 \LMHash{} 5331 \LMHash{}
5324 Otherwise evaluate $e_1$ to an object $u$. 5332 Otherwise evaluate $e_1$ to an object $u$.
5325 if $u$ is the null value, $e$ evaluates to the null value. 5333 if $u$ is the null value, $e$ evaluates to the null value.
5326 Otherwise let $x$ be a fresh variable bound to $u$. 5334 Otherwise let $x$ be a fresh variable bound to $u$.
5327 Evaluate \code{$x$.$v$++} to an object $o$. 5335 Evaluate \code{$x$.$v$++} to an object $o$.
5328 Then $e$ evaluates to $o$. 5336 Then $e$ evaluates to $o$.
5329 5337
5330 \LMHash{} 5338 \LMHash{}
5331 The static type of such an expression is the static type of \code{$e_1$.$v$}. 5339 The static type of such an expression is the static type of \code{$e_1$.$v$}.
5332 5340
5333 \LMHash{} 5341 \LMHash{}
5334 Evaluation of a postfix expression $e$ of the form \code{$e_1$?.$v$-{}-} 5342 Evaluation of a postfix expression $e$ of the form \code{$e_1$?.$v$-{}-}
5335 where $e_1$ is not a type literal, proceeds as follows: 5343 where $e_1$ is not a type literal, proceeds as follows:
eernst 2017/08/21 10:15:20 Ditto: delete `where $e_1$ is not a type literal,
Lasse Reichstein Nielsen 2017/08/22 05:32:09 Done.
5336 5344
5337 If $e_1$ is a type literal, $e$ is equivalent to \code{$e_1$.$v$-{}-}. 5345 If $e_1$ is a type literal, evaluation of $e$ is equivalent to
5346 evaluation of \code{$e_1$.$v$-{}-}.
5338 5347
5339 Otherwise evaluate $e_1$ to an object $u$. 5348 Otherwise evaluate $e_1$ to an object $u$.
5340 If $u$ is the null value, $e$ evaluates to the null value. 5349 If $u$ is the null value, $e$ evaluates to the null value.
5341 Otherwise let $x$ be a fresh variable bound to $u$. 5350 Otherwise let $x$ be a fresh variable bound to $u$.
5342 Evaluate \code{$x$.$v$-{}-} to an object $o$. 5351 Evaluate \code{$x$.$v$-{}-} to an object $o$.
5343 Then $e$ evaluates to $o$. 5352 Then $e$ evaluates to $o$.
5344 5353
5345 5354
5346 \LMHash{} 5355 \LMHash{}
5347 The static type of such an expression is the static type of \code{$e_1$.$v$}. 5356 The static type of such an expression is the static type of \code{$e_1$.$v$}.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
5396 \LMHash{} 5405 \LMHash{}
5397 An assignable expression of the form $e.id$ or $e?.id$ is evaluated as a propert y extraction (\ref{propertyExtraction}). 5406 An assignable expression of the form $e.id$ or $e?.id$ is evaluated as a propert y extraction (\ref{propertyExtraction}).
5398 5407
5399 \LMHash{} 5408 \LMHash{}
5400 An assignable expression of the form \code{$e_1$[$e_2$]} is evaluated as a metho d invocation of the operator method \code{[]} on $e_1$ with argument $e_2$. 5409 An assignable expression of the form \code{$e_1$[$e_2$]} is evaluated as a metho d invocation of the operator method \code{[]} on $e_1$ with argument $e_2$.
5401 5410
5402 \LMHash{} 5411 \LMHash{}
5403 An assignable expression of the form \code{\SUPER{}.id} is evaluated as a prope rty extraction. 5412 An assignable expression of the form \code{\SUPER{}.id} is evaluated as a prope rty extraction.
5404 5413
5405 \LMHash{} 5414 \LMHash{}
5406 An assignable expression of the form \code{\SUPER{}[$e_2$]} is equivalent to the method invocation \code{\SUPER{}.[]($e_2$)}. 5415 Evaluation of an assignable expression of the form \code{\SUPER{}[$e_2$]} is equ ivalent to evaluation of the method invocation \code{\SUPER{}.[]($e_2$)}.
5407 5416
5408 \subsection{ Identifier Reference} 5417 \subsection{ Identifier Reference}
5409 \LMLabel{identifierReference} 5418 \LMLabel{identifierReference}
5410 5419
5411 \LMHash{} 5420 \LMHash{}
5412 An {\em identifier expression} consists of a single identifier; it provides acce ss to an object via an unqualified name. 5421 An {\em identifier expression} consists of a single identifier; it provides acce ss to an object via an unqualified name.
5413 5422
5414 \begin{grammar} 5423 \begin{grammar}
5415 {\bf identifier:} 5424 {\bf identifier:}
5416 IDENTIFIER 5425 IDENTIFIER
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
5497 %\item If $d$ is a library variable then: 5506 %\item If $d$ is a library variable then:
5498 % \begin{itemize} 5507 % \begin{itemize}
5499 % \item If $d$ is of one of the forms \code{\VAR{} $v$ = $e_i$;} , \code{$T$ $v $ = $e_i$;} , \code{\FINAL{} $v$ = $e_i$;} or \code{\FINAL{} $T$ $v$ = $e_i$;} and no value has yet been stored into $v$ then the initializer expression $e_i$ is evaluated. If, during the evaluation of $e_i$, the getter for $v$ is referenc ed, a \code{CyclicInitializationError} is thrown. If the evaluation succeeded yi elding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$ is stored into $v$. The value of $e$ is $r$. 5508 % \item If $d$ is of one of the forms \code{\VAR{} $v$ = $e_i$;} , \code{$T$ $v $ = $e_i$;} , \code{\FINAL{} $v$ = $e_i$;} or \code{\FINAL{} $T$ $v$ = $e_i$;} and no value has yet been stored into $v$ then the initializer expression $e_i$ is evaluated. If, during the evaluation of $e_i$, the getter for $v$ is referenc ed, a \code{CyclicInitializationError} is thrown. If the evaluation succeeded yi elding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$ is stored into $v$. The value of $e$ is $r$.
5500 \item If $d$ is a constant variable of one of the forms \code{\CONST{} $v$ = $e$;} or \code{\CONST{} $T$ $v$ = $e$;} then the value $id$ is the value of the compile-time constant $e$. 5509 \item If $d$ is a constant variable of one of the forms \code{\CONST{} $v$ = $e$;} or \code{\CONST{} $T$ $v$ = $e$;} then the value $id$ is the value of the compile-time constant $e$.
5501 % Otherwise 5510 % Otherwise
5502 % \item $e$ evaluates to the current binding of $id$. 5511 % \item $e$ evaluates to the current binding of $id$.
5503 % \end{itemize} 5512 % \end{itemize}
5504 \item If $d$ is a local variable or formal parameter then $e$ evaluates to the c urrent binding of $id$. 5513 \item If $d$ is a local variable or formal parameter then $e$ evaluates to the c urrent binding of $id$.
5505 %\item If $d$ is a library variable, local variable, or formal parameter, then $ e$ evaluates to the current binding of $id$. \commentary{This case also applies if d is a library or local function declaration, as these are equivalent to func tion-valued variable declarations.} 5514 %\item If $d$ is a library variable, local variable, or formal parameter, then $ e$ evaluates to the current binding of $id$. \commentary{This case also applies if d is a library or local function declaration, as these are equivalent to func tion-valued variable declarations.}
5506 \item If $d$ is a static method, top-level function or local function then $e$ e valuates to the function defined by $d$. 5515 \item If $d$ is a static method, top-level function or local function then $e$ e valuates to the function defined by $d$.
5507 \item If $d$ is the declaration of a static variable, static getter or static se tter declared in class $C$, then $e$ is equivalent to the property extraction (\ ref{propertyExtraction}) $C.id$. 5516 \item If $d$ is the declaration of a static variable, static getter or static se tter declared in class $C$, then evaluation of $e$ is equivalent to evaluation o f the property extraction (\ref{propertyExtraction}) $C.id$.
eernst 2017/08/21 10:15:21 Doesn't this eliminate the ability of the static a
Lasse Reichstein Nielsen 2017/08/22 05:32:12 I'm not actually sure. I worried about the same th
5508 \item If $d$ is the declaration of a library variable, top-level getter or top-l evel setter, then $e$ is equivalent to the top level getter invocation (\ref{top LevelGetterInvocation}) $id$. 5517 \item If $d$ is the declaration of a library variable, top-level getter or top-l evel setter, then evaluation of $e$ is equivalent to evaluation of the top level getter invocation (\ref{topLevelGetterInvocation}) $id$.
5509 \item Otherwise, if $e$ occurs inside a top level or static function (be it func tion, method, getter, or setter) or variable initializer, evaluation of $e$ cau ses a \code{NoSuchMethod} to be thrown. 5518 \item Otherwise, if $e$ occurs inside a top level or static function (be it func tion, method, getter, or setter) or variable initializer, evaluation of $e$ cau ses a \code{NoSuchMethod} to be thrown.
5510 \item Otherwise, $e$ is equivalent to the property extraction (\ref{propertyExtr action}) \THIS{}.$id$. 5519 \item Otherwise, evaluation of $e$ is equivalent to evaluation of the property e xtraction (\ref{propertyExtraction}) \THIS{}.$id$.
eernst 2017/08/21 10:15:20 Again, static analysis should also be able to see
Lasse Reichstein Nielsen 2017/08/22 05:32:10 Acknowledged.
5511 % This implies that referring to an undefined static getter by simple name is an error, whereas doing so by qualified name is only a warning. Same with assignme nts. Revise? 5520 % This implies that referring to an undefined static getter by simple name is an error, whereas doing so by qualified name is only a warning. Same with assignme nts. Revise?
5512 \end{itemize} 5521 \end{itemize}
5513 5522
5514 \LMHash{} 5523 \LMHash{}
5515 The static type of $e$ is determined as follows: 5524 The static type of $e$ is determined as follows:
5516 5525
5517 \begin{itemize} 5526 \begin{itemize}
5518 \item If $d$ is a class, type alias or type parameter the static type of $e$ is \code{Type}. 5527 \item If $d$ is a class, type alias or type parameter the static type of $e$ is \code{Type}.
5519 \item If $d$ is a local variable or formal parameter the static type of $e$ is t he type of the variable $id$, unless $id$ is known to have some type $T$, in whi ch case the static type of $e$ is $T$, provided that $T$ is more specific than a ny other type $S$ such that $v$ is known to have type $S$. 5528 \item If $d$ is a local variable or formal parameter the static type of $e$ is t he type of the variable $id$, unless $id$ is known to have some type $T$, in whi ch case the static type of $e$ is $T$, provided that $T$ is more specific than a ny other type $S$ such that $v$ is known to have type $S$.
5520 \item If $d$ is a static method, top-level function or local function the static type of $e$ is the function type defined by $d$. 5529 \item If $d$ is a static method, top-level function or local function the static type of $e$ is the function type defined by $d$.
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
5726 \begin{grammar} 5735 \begin{grammar}
5727 {\bf localVariableDeclaration:} 5736 {\bf localVariableDeclaration:}
5728 initializedVariableDeclaration `{\escapegrammar ;}' 5737 initializedVariableDeclaration `{\escapegrammar ;}'
5729 . 5738 .
5730 \end{grammar} 5739 \end{grammar}
5731 5740
5732 \LMHash{} 5741 \LMHash{}
5733 Executing a variable declaration statement of one of the forms \VAR{} $v = e;$ , $T$ $v = e; $, \CONST{} $v = e;$, \CONST{} $T$ $v = e;$, \FINAL{} $v = e;$ o r \FINAL{} $T$ $v = e;$ proceeds as follows: 5742 Executing a variable declaration statement of one of the forms \VAR{} $v = e;$ , $T$ $v = e; $, \CONST{} $v = e;$, \CONST{} $T$ $v = e;$, \FINAL{} $v = e;$ o r \FINAL{} $T$ $v = e;$ proceeds as follows:
5734 5743
5735 \LMHash{} 5744 \LMHash{}
5736 The expression $e$ is evaluated to an object $o$. Then, the variable $v$ is set to $o$. 5745 The expression $e$ is evaluated to an object $o$. Then, the variable $v$ is set to $o$.
5737 5746
5738 \LMHash{} 5747 \LMHash{}
5739 A variable declaration statement of the form \VAR{} $v;$ is equivalent to \VAR{ } $v = \NULL{};$. A variable declaration statement of the form $T$ $v;$ is equiv alent to $T$ $v = \NULL{};$. 5748 A variable declaration statement of the form \code{\VAR{} $v$;} is equivalent to \code{\VAR{} $v$ = \NULL{};}. A variable declaration statement of the form \cod e{$T$ $v$;} is equivalent to \code{$T$ $v$ = \NULL{};}.
5740 5749
5741 \commentary{ 5750 \commentary{
5742 This holds regardless of the type $T$. For example, \code{int i;} does not cause \code{i} to be initialized to zero. Instead, \code{i} is initialized to \NULL{} , just as if we had written \VAR{} \code{i;} or \code{Object i;} or \code{Collec tion<String> i;}. 5751 This holds regardless of the type $T$. For example, \code{int i;} does not cause \code{i} to be initialized to zero. Instead, \code{i} is initialized to \NULL{} , just as if we had written \VAR{} \code{i;} or \code{Object i;} or \code{Collec tion<String> i;}.
5743 } 5752 }
5744 5753
5745 \rationale{ 5754 \rationale{
5746 To do otherwise would undermine the optionally typed nature of Dart, causing typ e annotations to modify program behavior. 5755 To do otherwise would undermine the optionally typed nature of Dart, causing typ e annotations to modify program behavior.
5747 } 5756 }
5748 5757
5749 %A variable declaration statement of one of the forms $T$ $v;$, $T$ $v = e;$, \C ONST{} $T$ $v = e;$, or \FINAL{} $T$ $v = e;$ causes a new getter named $v$ wit h static return type $T$ to be added to the innermost enclosing scope at the poi nt following the variable declaration statement. The result of executing this ge tter is the value stored in $v$. 5758 %A variable declaration statement of one of the forms $T$ $v;$, $T$ $v = e;$, \C ONST{} $T$ $v = e;$, or \FINAL{} $T$ $v = e;$ causes a new getter named $v$ wit h static return type $T$ to be added to the innermost enclosing scope at the poi nt following the variable declaration statement. The result of executing this ge tter is the value stored in $v$.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
5818 \LMLabel{if} 5827 \LMLabel{if}
5819 5828
5820 \LMHash{} 5829 \LMHash{}
5821 The {\em if statement} allows for conditional execution of statements. 5830 The {\em if statement} allows for conditional execution of statements.
5822 5831
5823 \begin{grammar} 5832 \begin{grammar}
5824 {\bf ifStatement:} 5833 {\bf ifStatement:}
5825 \IF{} `(' expression `)' statement ( \ELSE{} statement)? 5834 \IF{} `(' expression `)' statement ( \ELSE{} statement)?
5826 . 5835 .
5827 \end{grammar} 5836 \end{grammar}
5837 An if statement of the form \code{\IF{} ($e$) $s_1$ \ELSE{} $s_2$} where $s_1$ i s not a block statement is equivalent to the statement \code{\IF{} ($e$) \{$s_1$ \} \ELSE{} $s_2$}.
5838 An if statement of the form \code{\IF{} ($e$) $s_1$ \ELSE{} $s_2$} where $s_2$ i s not a block statement is equivalent to the statement \code{\IF{} ($e$) $s_1$ \ ELSE{} \{$s_2$\}}.
5828 5839
5829 Execution of an if statement of the form \code {\IF{} (}$b$\code{)}$s_1$ \code{ \ELSE{} } $s_2$ proceeds as follows: 5840 \rationale {
5830 5841 The reason for this equivalence is to catch errors such as
5831 \LMHash{} 5842 }
5832 First, the expression $b$ is evaluated to an object $o$. Then, $o$ is subjected to boolean conversion (\ref{booleanConversion}), producing an object $r$. If $r $ is \TRUE{}, then the statement $\{s_1\}$ is executed, otherwise statement $\{s _2\}$ is executed. 5843 \begin{dartCode}
5833
5834 \commentary {
5835 Put another way, \code {\IF{} (}$b$\code{)}$s_1$ \code{\ELSE{} } $s_2$ is equiv alent to
5836 \code {\IF{} (}$b$\code{)}$\{s_1\}$ \code{\ELSE{} } $\{s_2\}$
5837 }
5838
5839 \rationale {
5840 The reason for this equivalence is to catch errors such as
5841 }
5842 \begin{dartCode}
5843 \VOID{} main() \{ 5844 \VOID{} main() \{
5844 \IF{} (somePredicate) 5845 \IF{} (somePredicate)
5845 \VAR{} v = 2; 5846 \VAR{} v = 2;
5846 print(v); 5847 print(v);
5847 \} 5848 \}
5848 \end{dartCode} 5849 \end{dartCode}
5849 5850
5850 \rationale { 5851 \rationale {
5851 Under reasonable scope rules such code is problematic. If we assume that \code{ v} is declared in the scope of the method \code{main()}, then when \code{somePre dicate} is false, \code{v} will be uninitialized when accessed. The cleanest ap proach would be to require a block following the test, rather than an arbitrary statement. However, this goes against long standing custom, undermining Dart's g oal of familiarity. Instead, we choose to insert a block, introducing a scope, around the statement following the predicate (and similarly for \ELSE{} and loo ps). This will cause both a warning and a runtime error in the case above. Of c ourse, if there is a declaration of \code{v} in the surrounding scope, programme rs might still be surprised. We expect tools to highlight cases of shadowing to help avoid such situations. 5852 Under reasonable scope rules such code is problematic. If we assume that \code{ v} is declared in the scope of the method \code{main()}, then when \code{somePre dicate} is false, \code{v} will be uninitialized when accessed. The cleanest ap proach would be to require a block following the test, rather than an arbitrary statement. However, this goes against long standing custom, undermining Dart's g oal of familiarity. Instead, we choose to insert a block, introducing a scope, around the statement following the predicate (and similarly for \ELSE{} and loo ps). This will cause both a warning and a runtime error in the case above. Of c ourse, if there is a declaration of \code{v} in the surrounding scope, programme rs might still be surprised. We expect tools to highlight cases of shadowing to help avoid such situations.
5852 } 5853 }
5853 5854
5855
5856 \LMHash{}
5857 Execution of an if statement of the form \code {\IF{} (}$b$\code{)} $s_1$ \code {\ELSE{} } $s_2$ where $s_1$ and $s_2$ are block statements, proceeds as follows :
eernst 2017/08/21 10:15:20 Might as well keep the simpler "all \code" style t
Lasse Reichstein Nielsen 2017/08/22 05:32:10 Agree. This was moved verbatim from earlier, but l
5858
5859 \LMHash{}
5860 First, the expression $b$ is evaluated to an object $o$. Then, $o$ is subjected to boolean conversion (\ref{booleanConversion}), producing an object $r$. If $r$ is \TRUE{}, then the block statement $s_1$ is executed, otherwise the block sta tement $s_2$ is executed.
5861
5854 \LMHash{} 5862 \LMHash{}
5855 It is a static type warning if the type of the expression $b$ may not be assig ned to \code{bool}. 5863 It is a static type warning if the type of the expression $b$ may not be assig ned to \code{bool}.
5856 5864
5857 \LMHash{} 5865 \LMHash{}
5858 If: 5866 If:
5859 \begin{itemize} 5867 \begin{itemize}
5860 \item $b$ shows that a variable $v$ has type $T$. 5868 \item $b$ shows that a variable $v$ has type $T$.
5861 \item $v$ is not potentially mutated in $s_1$ or within a closure. 5869 \item $v$ is not potentially mutated in $s_1$ or within a closure.
5862 \item If the variable $v$ is accessed by a closure in $s_1$ then the variable $v $ is not potentially mutated anywhere in the scope of $v$. 5870 \item If the variable $v$ is accessed by a closure in $s_1$ then the variable $v $ is not potentially mutated anywhere in the scope of $v$.
5863 \end{itemize} 5871 \end{itemize}
5864 then the type of $v$ is known to be $T$ in $s_1$. 5872 then the type of $v$ is known to be $T$ in $s_1$.
5865 5873
5866 \LMHash{} 5874 \LMHash{}
5867 An if statement of the form \code {\IF{} (}$b$\code{)}$s_1$ is equivalent to t he if statement 5875 An if statement of the form \code{\IF{} ($e$) $s$} is equivalent to the if state ment \code{\IF{} ($e$) $s$ \ELSE{} \{\}}.
5868
5869 \code {\IF{} (}$b$\code{)}$s_1$ \code{\ELSE{} \{\}}.
5870
5871 5876
5872 5877
5873 \subsection{For} 5878 \subsection{For}
5874 \LMLabel{for} 5879 \LMLabel{for}
5875 5880
5876 \LMHash{} 5881 \LMHash{}
5877 The {\em for statement} supports iteration. 5882 The {\em for statement} supports iteration.
5878 5883
5879 \begin{grammar} 5884 \begin{grammar}
5880 {\bf forStatement:} 5885 {\bf forStatement:}
(...skipping 2365 matching lines...) Expand 10 before | Expand all | Expand 10 after
8246 8251
8247 The invariant that each normative paragraph is associated with a line 8252 The invariant that each normative paragraph is associated with a line
8248 containing the text \LMHash{} should be maintained. Extra occurrences 8253 containing the text \LMHash{} should be maintained. Extra occurrences
8249 of \LMHash{} can be added if needed, e.g., in order to make 8254 of \LMHash{} can be added if needed, e.g., in order to make
8250 individual \item{}s in itemized lists addressable. Each \LM.. command 8255 individual \item{}s in itemized lists addressable. Each \LM.. command
8251 must occur on a separate line. \LMHash{} must occur immediately 8256 must occur on a separate line. \LMHash{} must occur immediately
8252 before the associated paragraph, and \LMLabel must occur immediately 8257 before the associated paragraph, and \LMLabel must occur immediately
8253 after the associated \section{}, \subsection{} etc. 8258 after the associated \section{}, \subsection{} etc.
8254 8259
8255 ---------------------------------------------------------------------- 8260 ----------------------------------------------------------------------
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698