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

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

Issue 1324933002: Proposed spec for DEP for assert with messages. Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Update version number Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« 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 \newcommand{\code}[1]{{\sf #1}} 8 \newcommand{\code}[1]{{\sf #1}}
9 \title{Dart Programming Language Specification \\ 9 \title{Dart Programming Language Specification \\
10 (4th edition draft)\\ 10 {\large Version 1.13}}
11 {\large Version 1.11}}
12 11
13 % For information about Location Markers (and in particular the 12 % For information about Location Markers (and in particular the
14 % commands \LMHash and \LMLabel), see the long comment at the 13 % commands \LMHash and \LMLabel), see the long comment at the
15 % end of this file. 14 % end of this file.
16 15
17 \begin{document} 16 \begin{document}
18 \maketitle 17 \maketitle
19 \tableofcontents 18 \tableofcontents
20 19
21 20
(...skipping 3845 matching lines...) Expand 10 before | Expand all | Expand 10 after
3867 \end{code} 3866 \end{code}
3868 3867
3869 \commentary{Notice that the wording carefully avoids re-evaluating the receiver $o$ and the arguments $a_i$. } 3868 \commentary{Notice that the wording carefully avoids re-evaluating the receiver $o$ and the arguments $a_i$. }
3870 3869
3871 \LMHash{} 3870 \LMHash{}
3872 Let $T$ be the static type of $o$. It is a static type warning if $T$ does not have an accessible (\ref{privacy}) instance member named $m$ unless either: 3871 Let $T$ be the static type of $o$. It is a static type warning if $T$ does not have an accessible (\ref{privacy}) instance member named $m$ unless either:
3873 \begin{itemize} 3872 \begin{itemize}
3874 \item 3873 \item
3875 $T$ or a superinterface of $T$ is annotated with an annotation denoting a consta nt identical to the constant \code{@proxy} defined in \code{dart:core}. Or 3874 $T$ or a superinterface of $T$ is annotated with an annotation denoting a consta nt identical to the constant \code{@proxy} defined in \code{dart:core}. Or
3876 \item $T$ is \code{Type}, $e$ is a constant type literal and the class correspo nding to $e$ has a static getter named $m$. 3875 \item $T$ is \code{Type}, $e$ is a constant type literal and the class correspo nding to $e$ has a static getter named $m$.
3877 \item $T$ is \code{Function} and $m$ is \CALL. \rationale {The type \code{Functi on} is treated as if it has a \code{call} method for any possible signature of \ CALL. The expectation is that any concrete subclass of \code{Function} will impl ement \CALL. Note that a warning will be issue if this is not the case. Furtherm ore, any use of \CALL{} on a subclass of \code{Function} that fails to implement \CALL{} will also provoke a a warning, as this exemption is limited to type \co de{Function}, and does not apply to its subtypes. 3876 \item $T$ is \code{Function} and $m$ is \CALL. \rationale {The type \code{Functi on} is treated as if it has a \code{call} method for any possible signature of \ CALL. The expectation is that any concrete subclass of \code{Function} will impl ement \CALL. Note that a warning will be issue if this is not the case. Furtherm ore, any use of \CALL{} on a subclass of \code{Function} that fails to implement \CALL{} will also provoke a warning, as this exemption is limited to type \code {Function}, and does not apply to its subtypes.
3878 } 3877 }
3879 \end{itemize} 3878 \end{itemize}
3880 3879
3881 \LMHash{} 3880 \LMHash{}
3882 If $T.m$ exists, it is a static type warning if the type $F$ of $T.m$ may not b e assigned to a function type. If $T.m$ does not exist, or if $F$ is not a funct ion type, the static type of $i$ is \DYNAMIC{}; otherwise the static type of $i$ is the declared return type of $F$. 3881 If $T.m$ exists, it is a static type warning if the type $F$ of $T.m$ may not b e assigned to a function type. If $T.m$ does not exist, or if $F$ is not a funct ion type, the static type of $i$ is \DYNAMIC{}; otherwise the static type of $i$ is the declared return type of $F$.
3883 3882
3884 \LMHash{} 3883 \LMHash{}
3885 It is a compile-time error to invoke any of the methods of class \cd{Object} on a prefix object (\ref{imports}) or on a constant type literal that is immediate ly followed by the token `.'. 3884 It is a compile-time error to invoke any of the methods of class \cd{Object} on a prefix object (\ref{imports}) or on a constant type literal that is immediate ly followed by the token `.'.
3886 3885
3887 3886
(...skipping 2562 matching lines...) Expand 10 before | Expand all | Expand 10 after
6450 6449
6451 6450
6452 \subsection{ Assert} 6451 \subsection{ Assert}
6453 \LMLabel{assert} 6452 \LMLabel{assert}
6454 6453
6455 \LMHash{} 6454 \LMHash{}
6456 An {\em assert statement} is used to disrupt normal execution if a given boolean condition does not hold. 6455 An {\em assert statement} is used to disrupt normal execution if a given boolean condition does not hold.
6457 6456
6458 \begin{grammar} 6457 \begin{grammar}
6459 {\bf assertStatement:} 6458 {\bf assertStatement:}
6460 assert `(' conditionalExpression `)' `{\escapegrammar ;}' 6459 assert `(' conditionalExpression (`,' expression)? `)' `{\escapegrammar ;}'
6461 . 6460 .
6462 \end{grammar} 6461 \end{grammar}
6463 6462
6464 \LMHash{} 6463 \LMHash{}
6465 The assert statement has no effect in production mode. In checked mode, executio n of an assert statement \code{\ASSERT{}($e$);} proceeds as follows: 6464 The assert statement has no effect in production mode. In checked mode, executio n of an assert statement \code{\ASSERT{}($e$);} or \code{\ASSERT{}($e$, $s$);} p roceeds as follows:
6466 6465
6467 \LMHash{} 6466 \LMHash{}
6468 The conditional expression $e$ is evaluated to an object $o$. If the class of $o $ is a subtype of \code{Function} then let $r$ be the result of invoking $o$ wit h no arguments. Otherwise, let $r$ be $o$. 6467 The conditional expression $e$ is evaluated to an object $o$. If the class of $o $ is a subtype of \code{Function} then let $r$ be the result of invoking $o$ wit h no arguments. Otherwise, let $r$ be $o$.
6469 It is a dynamic type error if $o$ is not of type \code{bool} or of type \code{Fu nction}, or if $r$ is not of type \code{bool}. If $r$ is \FALSE{}, we say that the assertion failed. If $r$ is \TRUE{}, we say that the assertion succeeded. If the assertion succeeded, execution of the assert statement is complete. If the assertion failed, an \code{AssertionError} is thrown. 6468 It is a dynamic type error if $o$ is not of type \code{bool} or of type \code{Fu nction}, or if $r$ is not of type \code{bool}. If $r$ is \FALSE{}, we say that the assertion failed. If $r$ is \TRUE{}, we say that the assertion succeeded. If the assertion succeeded, execution of the assert statement is complete.
6469
6470 \LMHash{}
6471 If the assertion failed, and the assertion is of the form \code{\ASSERT{}($e$);} an \cd{AssertionError} is thrown.
6472
6473 If the assertion failed and the assertion is of the form \code{\ASSERT{}($e$, $s $);} then the expression $s$ is evaluated to a value $o_s$. If evaluation of $s$ fails, an \cd{AssertionError} is thrown. Otherwise, the \cd{toString()} method is invoked on $o_s$ resulting in a string object $m$. If the invocation of \cd{t oString()} throws an exception, an \cd{AssertionError} is thrown. Otherwise,
Lasse Reichstein Nielsen 2015/11/05 16:22:25 Calling o_s.toString is not guaranteed to result i
Brian Wilkerson 2015/11/05 17:04:37 True. We have the same problem for string interpol
Bob Nystrom 2015/11/05 17:50:04 fails, an \cd{AssertionError} is thrown. I don't
gbracha 2015/11/05 19:25:01 Interestingly, the original spec would ensure that
Paul Berry 2015/11/05 19:35:26 Personally, I feel the opposite way. I use assert
floitsch 2015/11/18 21:16:36 Late to the party... I'm not going to make this ea
gbracha 2015/11/24 20:26:04 So we are going around in circles. The original sp
6474 an \cd{AssertionError} $x$ is created with error message $m$.
Lasse Reichstein Nielsen 2015/11/05 16:22:25 Maybe if evaluation of $s$ fails, we should let th
gbracha 2015/11/05 19:25:01 So if we go back to propagating failures in messag
6475
6476 \rationale {
6477 The optional argument $s$ is intended to allow a suitable message to be associat ed with the assertion. An implementation should endeavor to display the message $m$ in a manner that is useful to the developer.
6478 }
6479
6480 \commentary{
6481 The definition above implies that $s$ is not evaluated if the assertion succeed ed.
6482 }
6470 6483
6471 %\Q{Might be cleaner to define it as \code{if (!$e$) \{\THROW{} \NEW{} Assertion Error();\}} (in checked mode only). 6484 %\Q{Might be cleaner to define it as \code{if (!$e$) \{\THROW{} \NEW{} Assertion Error();\}} (in checked mode only).
6472 %What about an error message as part of the assert?} 6485 %What about an error message as part of the assert?}
6473 6486
6474 \LMHash{} 6487 \LMHash{}
6475 It is a static type warning if the type of $e$ may not be assigned to either \ code{bool} or $() \rightarrow$ \code{bool}. 6488 It is a static type warning if the type of $e$ may not be assigned to either \ code{bool} or $() \rightarrow$ \code{bool}.
6476 6489
6477 \rationale{Why is this a statement, not a built in function call? Because it is handled magically so it has no effect and no overhead in production mode. Also, in the absence of final methods. one could not prevent it being overridden (thou gh there is no real harm in that). It cannot be viewed as a function call that is being optimized away because the argument might have side effects. 6490 \rationale{Why is this a statement, not a built in function call? Because it is handled magically so it has no effect and no overhead in production mode. Also, in the absence of final methods. one could not prevent it being overridden (thou gh there is no real harm in that). It cannot be viewed as a function call that is being optimized away because the argument might have side effects. And lastly , the optional message would have to be evaluated in all cases if \ASSERT{} were a function.
6478 } 6491 }
6479 6492
6480 %If a lexically visible declaration named \code{assert} is in scope, an assert s tatement 6493 %If a lexically visible declaration named \code{assert} is in scope, an assert s tatement
6481 %\code{\ASSERT{} (e); } 6494 %\code{\ASSERT{} (e); }
6482 %is interpreted as an expression statement \code{(assert(e));} . 6495 %is interpreted as an expression statement \code{(assert(e));} .
6483 6496
6484 %\rationale{ 6497 %\rationale{
6485 %Since \ASSERT{} is a built-in identifier, one might define a function or method with this name. 6498 %Since \ASSERT{} is a built-in identifier, one might define a function or method with this name.
6486 %It is impossible to distinguish as \ASSERT{} statement from a method invocation in such a situation. 6499 %It is impossible to distinguish as \ASSERT{} statement from a method invocation in such a situation.
6487 %One could choose to always interpret such code as an \ASSERT{} statement. Or we could choose to give priority to any lexically visible user defined function. The former can cause rather puzzling situations, e.g.,} 6500 %One could choose to always interpret such code as an \ASSERT{} statement. Or we could choose to give priority to any lexically visible user defined function. The former can cause rather puzzling situations, e.g.,}
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
7314 A function type $(T_1, \ldots T_n, \{T_{x_1}$ $x_1, \ldots, T_{x_k}$ $x_k\}) \ri ghtarrow T$ is a subtype of the function type $(S_1, \ldots, S_n, \{S_{y_1}$ $y_ 1, \ldots, S_{y_m}$ $y_m\}) \rightarrow S$, if all of the following conditions a re met: 7327 A function type $(T_1, \ldots T_n, \{T_{x_1}$ $x_1, \ldots, T_{x_k}$ $x_k\}) \ri ghtarrow T$ is a subtype of the function type $(S_1, \ldots, S_n, \{S_{y_1}$ $y_ 1, \ldots, S_{y_m}$ $y_m\}) \rightarrow S$, if all of the following conditions a re met:
7315 \begin{enumerate} 7328 \begin{enumerate}
7316 \item Either 7329 \item Either
7317 \begin{itemize} 7330 \begin{itemize}
7318 \item $S$ is \VOID{}, Or 7331 \item $S$ is \VOID{}, Or
7319 \item $T \Longleftrightarrow S$. 7332 \item $T \Longleftrightarrow S$.
7320 \end{itemize} 7333 \end{itemize}
7321 \item $\forall i \in 1 .. n, T_i \Longleftrightarrow S_i$. 7334 \item $\forall i \in 1 .. n, T_i \Longleftrightarrow S_i$.
7322 \item $k \ge m$ and $y_i \in \{x_1, \ldots, x_k\}, i \in 1 .. m$. 7335 \item $k \ge m$ and $y_i \in \{x_1, \ldots, x_k\}, i \in 1 .. m$.
7323 %\{x_1, \ldots, x_k\}$ is a superset of $\{y_1, \ldots, y_m\}$. 7336 %\{x_1, \ldots, x_k\}$ is a superset of $\{y_1, \ldots, y_m\}$.
7324 \item For all $y_i \in \{y_1, \ldots, y_m\}, y_i = x_j \Rightarrow T_j \Longlef trightarrow S_i$ 7337 \item For all $y_i \in \{y_1, \ldots, y_m\}, y_i = x_j \Rightarrow T_{x_j} \Lon gleftrightarrow S_{y_i}$
7325 \end{enumerate} 7338 \end{enumerate}
7326 7339
7327 %In addition, a function type $(T_1, \ldots, Tn, [T_{n+1} x_{n+1}, \ldots, T_{n+ k} x_{n+k}]) \rightarrow T$ is a subtype of the function type $(T_1, \ldots, T_n , T_{n+1} , [T_{n+2} x_{n+2}, \ldots, T_{n+k} x_{n+k}]) \rightarrow T$. 7340 %In addition, a function type $(T_1, \ldots, Tn, [T_{n+1} x_{n+1}, \ldots, T_{n+ k} x_{n+k}]) \rightarrow T$ is a subtype of the function type $(T_1, \ldots, T_n , T_{n+1} , [T_{n+2} x_{n+2}, \ldots, T_{n+k} x_{n+k}]) \rightarrow T$.
7328 7341
7329 %\rationale{This second rule is attractive to web developers, who are used to th is sort of flexibility from Javascript. However, it may be costly to implement e fficiently.} \Q{Should we do this or not?} 7342 %\rationale{This second rule is attractive to web developers, who are used to th is sort of flexibility from Javascript. However, it may be costly to implement e fficiently.} \Q{Should we do this or not?}
7330 7343
7331 %We write $(T_1, \ldots, T_n) \rightarrow T$ as a shorthand for the type $(T_1, \ldots, T_n, []) \rightarrow T$. 7344 %We write $(T_1, \ldots, T_n) \rightarrow T$ as a shorthand for the type $(T_1, \ldots, T_n, []) \rightarrow T$.
7332 7345
7333 %The rules above need to be sanity checked, but the intent is that we view funct ions with rest parameters as having type $(T_1, ..., T_n, [\_{Tn+1}[] \_]) \righ tarrow T$, where \_ is some magical identifier. Then the rules above may cover e verything. 7346 %The rules above need to be sanity checked, but the intent is that we view funct ions with rest parameters as having type $(T_1, ..., T_n, [\_{Tn+1}[] \_]) \righ tarrow T$, where \_ is some magical identifier. Then the rules above may cover e verything.
7334 % This is wrong - from the outside, the type takes an unbounded sequence of type s, not a list. This can be modeled as $(T_1, \ldots, T_n, [T_{n+1}, \_ \ldots, T _{n+k} \_]) \rightarrow T$ for some finite $k$. 7347 % This is wrong - from the outside, the type takes an unbounded sequence of type s, not a list. This can be modeled as $(T_1, \ldots, T_n, [T_{n+1}, \_ \ldots, T _{n+k} \_]) \rightarrow T$ for some finite $k$.
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
7867 7880
7868 The invariant that each normative paragraph is associated with a line 7881 The invariant that each normative paragraph is associated with a line
7869 containing the text \LMHash{} should be maintained. Extra occurrences 7882 containing the text \LMHash{} should be maintained. Extra occurrences
7870 of \LMHash{} can be added if needed, e.g., in order to make 7883 of \LMHash{} can be added if needed, e.g., in order to make
7871 individual \item{}s in itemized lists addressable. Each \LM.. command 7884 individual \item{}s in itemized lists addressable. Each \LM.. command
7872 must occur on a separate line. \LMHash{} must occur immediately 7885 must occur on a separate line. \LMHash{} must occur immediately
7873 before the associated paragraph, and \LMLabel must occur immediately 7886 before the associated paragraph, and \LMLabel must occur immediately
7874 after the associated \section{}, \subsection{} etc. 7887 after the associated \section{}, \subsection{} etc.
7875 7888
7876 ---------------------------------------------------------------------- 7889 ----------------------------------------------------------------------
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