OLD | NEW |
---|---|
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 (4th edition draft)\\ |
(...skipping 6439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6450 | 6450 |
6451 | 6451 |
6452 \subsection{ Assert} | 6452 \subsection{ Assert} |
6453 \LMLabel{assert} | 6453 \LMLabel{assert} |
6454 | 6454 |
6455 \LMHash{} | 6455 \LMHash{} |
6456 An {\em assert statement} is used to disrupt normal execution if a given boolean condition does not hold. | 6456 An {\em assert statement} is used to disrupt normal execution if a given boolean condition does not hold. |
6457 | 6457 |
6458 \begin{grammar} | 6458 \begin{grammar} |
6459 {\bf assertStatement:} | 6459 {\bf assertStatement:} |
6460 assert `(' conditionalExpression `)' `{\escapegrammar ;}' | 6460 assert `(' conditionalExpression (`,' expression)? `)' `{\escapegrammar ;}' |
6461 . | 6461 . |
6462 \end{grammar} | 6462 \end{grammar} |
6463 | 6463 |
6464 \LMHash{} | 6464 \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: | 6465 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 | 6466 |
6467 \LMHash{} | 6467 \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$. | 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$. |
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. | 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. |
6470 | |
6471 If the assertion failed, and the assertion is of the form \code{\ASSERT{}($e$);} then the expression \cd{\THROW{} \NEW{} AssertionError()} is evaluated. | |
6472 If the assertion failed and the assertion is of the form \code{\ASSERT{}($e$, $ s$);} then the expression \cd{\THROW{} \NEW{} AssertionError(s)} is evaluated. | |
Lasse Reichstein Nielsen
2015/09/18 12:26:28
I'd recommend against specifying the exact constru
| |
6473 | |
6474 \rationale { | |
6475 The optional argument $s$ is intended to allow a suitable message to be associat ed with the assertion. An implementation should endeavour to display the message in a manner that is useful to the developer. | |
6476 } | |
6477 \commentary{ | |
6478 The definition above implies that if $s$ does not evaluate to a \cd{String}, a d ynamic error is thrown, because the argument to the constructor of \cd{Assertion Error} is typed as \cd{String} and we are running in checked mode. It also impli es that $s$ is not evaluated if the assertion succeeded, and that any exception that occurs during evaluation of $s$ is thrown and propagated as usual, in which case the assertion error is lost. | |
sra1
2015/09/17 19:55:22
Where is it specified that the argument to Asserti
Lasse Reichstein Nielsen
2015/10/15 09:14:48
This means that a type error in the assertion mess
Lasse Reichstein Nielsen
2015/10/15 09:14:48
I guess that's implicitly specified by this commen
| |
6479 } | |
6470 | 6480 |
6471 %\Q{Might be cleaner to define it as \code{if (!$e$) \{\THROW{} \NEW{} Assertion Error();\}} (in checked mode only). | 6481 %\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?} | 6482 %What about an error message as part of the assert?} |
6473 | 6483 |
6474 \LMHash{} | 6484 \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}. | 6485 It is a static type warning if the type of $e$ may not be assigned to either \ code{bool} or $() \rightarrow$ \code{bool}. It is a static type warning if the type of $s$ may not be assigned to \cd{String}. |
sra1
2015/09/17 19:55:22
I think it is a mistake to constrain the message t
| |
6476 | 6486 |
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. | 6487 \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 string message would have to be evaluated in all cases if \ASSERT {} were a function. |
6478 } | 6488 } |
6479 | 6489 |
6480 %If a lexically visible declaration named \code{assert} is in scope, an assert s tatement | 6490 %If a lexically visible declaration named \code{assert} is in scope, an assert s tatement |
6481 %\code{\ASSERT{} (e); } | 6491 %\code{\ASSERT{} (e); } |
6482 %is interpreted as an expression statement \code{(assert(e));} . | 6492 %is interpreted as an expression statement \code{(assert(e));} . |
6483 | 6493 |
6484 %\rationale{ | 6494 %\rationale{ |
6485 %Since \ASSERT{} is a built-in identifier, one might define a function or method with this name. | 6495 %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. | 6496 %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.,} | 6497 %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 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7867 | 7877 |
7868 The invariant that each normative paragraph is associated with a line | 7878 The invariant that each normative paragraph is associated with a line |
7869 containing the text \LMHash{} should be maintained. Extra occurrences | 7879 containing the text \LMHash{} should be maintained. Extra occurrences |
7870 of \LMHash{} can be added if needed, e.g., in order to make | 7880 of \LMHash{} can be added if needed, e.g., in order to make |
7871 individual \item{}s in itemized lists addressable. Each \LM.. command | 7881 individual \item{}s in itemized lists addressable. Each \LM.. command |
7872 must occur on a separate line. \LMHash{} must occur immediately | 7882 must occur on a separate line. \LMHash{} must occur immediately |
7873 before the associated paragraph, and \LMLabel must occur immediately | 7883 before the associated paragraph, and \LMLabel must occur immediately |
7874 after the associated \section{}, \subsection{} etc. | 7884 after the associated \section{}, \subsection{} etc. |
7875 | 7885 |
7876 ---------------------------------------------------------------------- | 7886 ---------------------------------------------------------------------- |
OLD | NEW |