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

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

Issue 2067843002: ExitDetector: Don't short-circuit return on non-exiting case statements (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Addressing comments 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/all_the_rest_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 ca02438d7ee4fb47d33baf18f7a934a0e4910bd9..b7f28c5a087268dff533243f3a5950680dfcf9c8 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -3755,24 +3755,29 @@ class ExitDetector extends GeneralizingAstVisitor<bool> {
_enclosingBlockContainsBreak = false;
try {
bool hasDefault = false;
+ bool hasNonExitingCase = false;
List<SwitchMember> members = node.members;
for (int i = 0; i < members.length; i++) {
SwitchMember switchMember = members[i];
if (switchMember is SwitchDefault) {
hasDefault = true;
- // If this is the last member and there are no statements, return
- // false
+ // If this is the last member and there are no statements, then it
+ // does not exit.
if (switchMember.statements.isEmpty && i + 1 == members.length) {
- return false;
+ hasNonExitingCase = true;
+ continue;
}
}
- // For switch members with no statements, don't visit the children,
- // otherwise, return false if no return is found in the children
- // statements.
+ // For switch members with no statements, don't visit the children.
+ // Otherwise, if there children statements don't exit, mark this as a
+ // non-exiting case.
if (!switchMember.statements.isEmpty && !switchMember.accept(this)) {
- return false;
+ hasNonExitingCase = true;
}
}
+ if (hasNonExitingCase) {
+ return false;
+ }
// As all cases exit, return whether that list includes `default`.
return hasDefault;
} finally {
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/all_the_rest_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698