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

Unified 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: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: docs/language/dartLangSpec.tex
diff --git a/docs/language/dartLangSpec.tex b/docs/language/dartLangSpec.tex
index 3850f200dfcfc00dea26f2a7b80fdf71a2c7f3a8..fd64edac6dc943df9b2cdf19e806e424ca7f5dc3 100644
--- a/docs/language/dartLangSpec.tex
+++ b/docs/language/dartLangSpec.tex
@@ -6457,24 +6457,34 @@ An {\em assert statement} is used to disrupt normal execution if a given boolean
\begin{grammar}
{\bf assertStatement:}
- assert `(' conditionalExpression `)' `{\escapegrammar ;}'
+ assert `(' conditionalExpression (`,' stringLiteral)? `)' `{\escapegrammar ;}'
Paul Berry 2015/09/01 19:59:49 Did you mean to say "expression" instead of "strin
Lasse Reichstein Nielsen 2015/09/02 07:36:49 You can always convert an object to a string (or t
.
\end{grammar}
\LMHash{}
-The assert statement has no effect in production mode. In checked mode, execution of an assert statement \code{\ASSERT{}($e$);} proceeds as follows:
+The assert statement has no effect in production mode. In checked mode, execution of an assert statement \code{\ASSERT{}($e$);} or \code{\ASSERT{}($e$, $s$);} proceeds as follows:
\LMHash{}
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$ with no arguments. Otherwise, let $r$ be $o$.
Lasse Reichstein Nielsen 2015/09/02 07:36:49 This seems to assume that both the evaluation of e
-It is a dynamic type error if $o$ is not of type \code{bool} or of type \code{Function}, 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.
+It is a dynamic type error if $o$ is not of type \code{bool} or of type \code{Function}, 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, and the assertion is of the form \code{\ASSERT{}($e$);} then the expression \cd{\THROW{} \NEW{} AssertionError()} is evaluated.
Lasse Reichstein Nielsen 2015/09/02 07:36:49 Don't use simple syntactic rewrites like this, it
sra1 2015/09/02 18:08:03 Well stated. This was exactly my point in the emai
gbracha 2015/09/02 19:58:22 I refer you to section 5 of the spec, which states
Lasse Reichstein Nielsen 2015/09/03 05:22:07 Ack.
+ 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.
sra1 2015/09/01 22:46:47 It is best to have a different constructor per pur
Lasse Reichstein Nielsen 2015/09/02 07:36:49 The ArgumentError.value is just there to allow Arg
sra1 2015/09/02 18:08:03 I would like to be able to distinguish between
Lasse Reichstein Nielsen 2015/09/03 05:22:07 I can see the reason for that. It will require eit
Lasse Reichstein Nielsen 2015/09/22 08:41:58 That has changed. I now have a problem with it, so
+
+\rationale {
+The optional argument $s$ is intended to allow a suitable message to be associated with the assertion. An implementation should endeavour to display the message in a manner that is useful to the developer.
+}
+\commentary{
+The definition above implies that if $s$ does not evaluate to a \cd{String}, a dynamic error is thrown, because the argument to the constructor of \cd{AssertionError} is typed as \cd{String} and we are running in checked mode. It also implies 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.
+}
%\Q{Might be cleaner to define it as \code{if (!$e$) \{\THROW{} \NEW{} AssertionError();\}} (in checked mode only).
%What about an error message as part of the assert?}
\LMHash{}
- 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 $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}.
Lasse Reichstein Nielsen 2015/09/02 07:36:49 I wouldn't make that requirement. I have no proble
gbracha 2015/09/02 19:58:22 Yes, people have debated that. There is a trade o
Lasse Reichstein Nielsen 2015/09/03 05:22:07 I'm not asking for any coercion. I'd prefer to sto
-\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 (though 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.
+\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 (though 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.
}
%If a lexically visible declaration named \code{assert} is in scope, an assert statement
« 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