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

Unified Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 2064203002: Do not error on dead, mandated statements at end of switch cases (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Two tests Created 4 years, 6 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 | pkg/analyzer/test/generated/hint_code_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/resolver.dart
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index f3c4a89daab993c8d14fbde132c748e2af5a4eca..3407e59dd7ed35153eeb441a3f1754e167740746 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -1913,13 +1913,13 @@ class DeadCodeVerifier extends RecursiveAstVisitor<Object> {
@override
Object visitSwitchCase(SwitchCase node) {
- _checkForDeadStatementsInNodeList(node.statements);
+ _checkForDeadStatementsInNodeList(node.statements, allowMandated: true);
return super.visitSwitchCase(node);
}
@override
Object visitSwitchDefault(SwitchDefault node) {
- _checkForDeadStatementsInNodeList(node.statements);
+ _checkForDeadStatementsInNodeList(node.statements, allowMandated: true);
return super.visitSwitchDefault(node);
}
@@ -2045,8 +2045,12 @@ class DeadCodeVerifier extends RecursiveAstVisitor<Object> {
* [SwitchMember], this loops through the list searching for dead statements.
*
* @param statements some ordered list of statements in a [Block] or [SwitchMember]
+ * @param allowMandated allow dead statements mandated by the language spec.
+ * This allows for a final break, continue, return, or throw statement
+ * at the end of a switch case, that are mandated by the language spec.
*/
- void _checkForDeadStatementsInNodeList(NodeList<Statement> statements) {
+ void _checkForDeadStatementsInNodeList(
+ NodeList<Statement> statements, {bool allowMandated: false}) {
bool statementExits(Statement statement) {
if (statement is BreakStatement) {
return statement.label == null;
@@ -2063,6 +2067,13 @@ class DeadCodeVerifier extends RecursiveAstVisitor<Object> {
if (statementExits(currentStatement) && i != size - 1) {
Statement nextStatement = statements[i + 1];
Statement lastStatement = statements[size - 1];
+ // If mandated statements are allowed, and only the last statement is
+ // dead, and it's a BreakStatement, then assume it is a statement
+ // mandated by the language spec, there to avoid a
+ // CASE_BLOCK_NOT_TERMINATED error.
+ if (allowMandated && i == size - 2 && nextStatement is BreakStatement) {
+ return;
+ }
int offset = nextStatement.offset;
int length = lastStatement.end - offset;
_errorReporter.reportErrorForOffset(HintCode.DEAD_CODE, offset, length);
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/hint_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698