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

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

Issue 2447613003: Allow `rethrow` to end a switch case. Allow braces around switch cases. (Closed)
Patch Set: Created 4 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 {4th edition draft}\\
(...skipping 5952 matching lines...) Expand 10 before | Expand all | Expand 10 after
5963 If $v$ is not \TRUE{} the following case, \CASE{} $e_{k+1}: s_{k+1}$ is execut ed if it exists. 5963 If $v$ is not \TRUE{} the following case, \CASE{} $e_{k+1}: s_{k+1}$ is execut ed if it exists.
5964 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. 5964 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.
5965 If execution reaches the point after $s_h$ then a runtime error occurs, unless $h = n$. 5965 If execution reaches the point after $s_h$ then a runtime error occurs, unless $h = n$.
5966 5966
5967 5967
5968 \commentary{ 5968 \commentary{
5969 In other words, there is no implicit fall-through between non-empty cases. The l ast case in a switch (default or otherwise) can `fall-through' to the end of the statement. 5969 In other words, there is no implicit fall-through between non-empty cases. The l ast case in a switch (default or otherwise) can `fall-through' to the end of the statement.
5970 } 5970 }
5971 5971
5972 \LMHash{} 5972 \LMHash{}
5973 It is a static warning if the type of $e$ may not be assigned to the type of $e_ k$. It is a static warning if the last statement of the statement sequence $s_k$ is not a \BREAK{}, \CONTINUE{}, \RETURN{} or \THROW{} statement. 5973 It is a static warning if the type of $e$ may not be assigned to the type of $e_ k$.
5974 Let $s$ be the last statement of the statement sequence $s_k$.
5975 If $s$ is a non-empty block statement, let $s$ instead be the last statment of t he block statement.
5976 It is a static warning $s$ is not a \BREAK{}, \CONTINUE{}, \REHTROW{} or \RETURN {} statement or an expression statment where the expression is a \THROW{} expres sion.
eernst 2016/10/24 12:38:02 I'm not sure it's sufficiently helpful to mention
Bob Nystrom 2016/10/24 16:48:00 Yeah, I'm not crazy about how blocks are handled h
Lasse Reichstein Nielsen 2016/10/24 18:38:25 I don't want to solve the general problem right no
5974 5977
5975 \rationale{ 5978 \rationale{
5976 The behavior of switch cases intentionally differs from the C tradition. Implic it fall through is a known cause of programming errors and therefore disallowed. Why not simply break the flow implicitly at the end of every case, rather than requiring explicit code to do so? This would indeed be cleaner. It would also be cleaner to insist that each case have a single (possibly compound) statement . We have chosen not to do so in order to facilitate porting of switch statemen ts from other languages. Implicitly breaking the control flow at the end of a c ase would silently alter the meaning of ported code that relied on fall-through, potentially forcing the programmer to deal with subtle bugs. Our design ensures that the difference is immediately brought to the coder's attention. The progr ammer will be notified at compile-time if they forget to end a case with a state ment that terminates the straight-line control flow. We could make this warning a compile-time error, but refrain from doing so because do not wish to force the programmer to deal with this issue immediately while porting code. If develope rs ignore the warning and run their code, a run time error will prevent the prog ram from misbehaving in hard-to-debug ways (at least with respect to this issue) . 5979 The behavior of switch cases intentionally differs from the C tradition. Implic it fall through is a known cause of programming errors and therefore disallowed. Why not simply break the flow implicitly at the end of every case, rather than requiring explicit code to do so? This would indeed be cleaner. It would also be cleaner to insist that each case have a single (possibly compound) statement . We have chosen not to do so in order to facilitate porting of switch statemen ts from other languages. Implicitly breaking the control flow at the end of a c ase would silently alter the meaning of ported code that relied on fall-through, potentially forcing the programmer to deal with subtle bugs. Our design ensures that the difference is immediately brought to the coder's attention. The progr ammer will be notified at compile-time if they forget to end a case with a state ment that terminates the straight-line control flow. We could make this warning a compile-time error, but refrain from doing so because do not wish to force the programmer to deal with this issue immediately while porting code. If develope rs ignore the warning and run their code, a run time error will prevent the prog ram from misbehaving in hard-to-debug ways (at least with respect to this issue) .
5977 5980
5978 The sophistication of the analysis of fall-through is another issue. For now, we have opted for a very straightforward syntactic requirement. There are obviousl y situations where code does not fall through, and yet does not conform to these simple rules, e.g.: 5981 The sophistication of the analysis of fall-through is another issue. For now, we have opted for a very straightforward syntactic requirement. There are obviousl y situations where code does not fall through, and yet does not conform to these simple rules, e.g.:
5979 } 5982 }
5980 5983
5981 \begin{dartCode} 5984 \begin{dartCode}
5982 \SWITCH{} (x) \{ 5985 \SWITCH{} (x) \{
5983 \CASE{} 1: \TRY{} \{ $\ldots$ \RETURN{};\} \FINALLY{} \{ $\ldots$ \RETURN{};\} 5986 \CASE{} 1: \TRY{} \{ $\ldots$ \RETURN{};\} \FINALLY{} \{ $\ldots$ \RETURN{};\}
(...skipping 1928 matching lines...) Expand 10 before | Expand all | Expand 10 after
7912 7915
7913 The invariant that each normative paragraph is associated with a line 7916 The invariant that each normative paragraph is associated with a line
7914 containing the text \LMHash{} should be maintained. Extra occurrences 7917 containing the text \LMHash{} should be maintained. Extra occurrences
7915 of \LMHash{} can be added if needed, e.g., in order to make 7918 of \LMHash{} can be added if needed, e.g., in order to make
7916 individual \item{}s in itemized lists addressable. Each \LM.. command 7919 individual \item{}s in itemized lists addressable. Each \LM.. command
7917 must occur on a separate line. \LMHash{} must occur immediately 7920 must occur on a separate line. \LMHash{} must occur immediately
7918 before the associated paragraph, and \LMLabel must occur immediately 7921 before the associated paragraph, and \LMLabel must occur immediately
7919 after the associated \section{}, \subsection{} etc. 7922 after the associated \section{}, \subsection{} etc.
7920 7923
7921 ---------------------------------------------------------------------- 7924 ----------------------------------------------------------------------
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