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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.src.generated.resolver; 5 library analyzer.src.generated.resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 3737 matching lines...) Expand 10 before | Expand all | Expand 10 after
3748 @override 3748 @override
3749 bool visitSwitchDefault(SwitchDefault node) => 3749 bool visitSwitchDefault(SwitchDefault node) =>
3750 _visitStatements(node.statements); 3750 _visitStatements(node.statements);
3751 3751
3752 @override 3752 @override
3753 bool visitSwitchStatement(SwitchStatement node) { 3753 bool visitSwitchStatement(SwitchStatement node) {
3754 bool outerBreakValue = _enclosingBlockContainsBreak; 3754 bool outerBreakValue = _enclosingBlockContainsBreak;
3755 _enclosingBlockContainsBreak = false; 3755 _enclosingBlockContainsBreak = false;
3756 try { 3756 try {
3757 bool hasDefault = false; 3757 bool hasDefault = false;
3758 bool hasNonExitingCase = false;
3758 List<SwitchMember> members = node.members; 3759 List<SwitchMember> members = node.members;
3759 for (int i = 0; i < members.length; i++) { 3760 for (int i = 0; i < members.length; i++) {
3760 SwitchMember switchMember = members[i]; 3761 SwitchMember switchMember = members[i];
3761 if (switchMember is SwitchDefault) { 3762 if (switchMember is SwitchDefault) {
3762 hasDefault = true; 3763 hasDefault = true;
3763 // If this is the last member and there are no statements, return 3764 // If this is the last member and there are no statements, then it
3764 // false 3765 // does not exit.
3765 if (switchMember.statements.isEmpty && i + 1 == members.length) { 3766 if (switchMember.statements.isEmpty && i + 1 == members.length) {
3766 return false; 3767 hasNonExitingCase = true;
3768 continue;
3767 } 3769 }
3768 } 3770 }
3769 // For switch members with no statements, don't visit the children, 3771 // For switch members with no statements, don't visit the children.
3770 // otherwise, return false if no return is found in the children 3772 // Otherwise, if there children statements don't exit, mark this as a
3771 // statements. 3773 // non-exiting case.
3772 if (!switchMember.statements.isEmpty && !switchMember.accept(this)) { 3774 if (!switchMember.statements.isEmpty && !switchMember.accept(this)) {
3773 return false; 3775 hasNonExitingCase = true;
3774 } 3776 }
3775 } 3777 }
3778 if (hasNonExitingCase) {
3779 return false;
3780 }
3776 // As all cases exit, return whether that list includes `default`. 3781 // As all cases exit, return whether that list includes `default`.
3777 return hasDefault; 3782 return hasDefault;
3778 } finally { 3783 } finally {
3779 _enclosingBlockContainsBreak = outerBreakValue; 3784 _enclosingBlockContainsBreak = outerBreakValue;
3780 } 3785 }
3781 } 3786 }
3782 3787
3783 @override 3788 @override
3784 bool visitThisExpression(ThisExpression node) => false; 3789 bool visitThisExpression(ThisExpression node) => false;
3785 3790
(...skipping 7156 matching lines...) Expand 10 before | Expand all | Expand 10 after
10942 return null; 10947 return null;
10943 } 10948 }
10944 if (identical(node.staticElement, variable)) { 10949 if (identical(node.staticElement, variable)) {
10945 if (node.inSetterContext()) { 10950 if (node.inSetterContext()) {
10946 result = true; 10951 result = true;
10947 } 10952 }
10948 } 10953 }
10949 return null; 10954 return null;
10950 } 10955 }
10951 } 10956 }
OLDNEW
« 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