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

Side by Side Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 2091583002: Fix instances where a loop 'always' exits, but also breaks, so it doesn't really exit. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Test 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 3538 matching lines...) Expand 10 before | Expand all | Expand 10 after
3549 } 3549 }
3550 3550
3551 @override 3551 @override
3552 bool visitContinueStatement(ContinueStatement node) => false; 3552 bool visitContinueStatement(ContinueStatement node) => false;
3553 3553
3554 @override 3554 @override
3555 bool visitDoStatement(DoStatement node) { 3555 bool visitDoStatement(DoStatement node) {
3556 bool outerBreakValue = _enclosingBlockContainsBreak; 3556 bool outerBreakValue = _enclosingBlockContainsBreak;
3557 _enclosingBlockContainsBreak = false; 3557 _enclosingBlockContainsBreak = false;
3558 try { 3558 try {
3559 if (_nodeExits(node.body)) { 3559 if (_nodeExits(node.body) && !_enclosingBlockContainsBreak) {
3560 return true; 3560 return true;
3561 } 3561 }
3562 Expression conditionExpression = node.condition; 3562 Expression conditionExpression = node.condition;
3563 if (_nodeExits(conditionExpression)) { 3563 if (_nodeExits(conditionExpression)) {
3564 return true; 3564 return true;
3565 } 3565 }
3566 // TODO(jwren) Do we want to take all constant expressions into account? 3566 // TODO(jwren) Do we want to take all constant expressions into account?
3567 if (conditionExpression is BooleanLiteral) { 3567 if (conditionExpression is BooleanLiteral) {
3568 // If do {} while (true), and the body doesn't break, then return true. 3568 // If do {} while (true), and the body doesn't break, then return true.
3569 if (conditionExpression.value && !_enclosingBlockContainsBreak) { 3569 if (conditionExpression.value && !_enclosingBlockContainsBreak) {
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
3851 3851
3852 @override 3852 @override
3853 bool visitWhileStatement(WhileStatement node) { 3853 bool visitWhileStatement(WhileStatement node) {
3854 bool outerBreakValue = _enclosingBlockContainsBreak; 3854 bool outerBreakValue = _enclosingBlockContainsBreak;
3855 _enclosingBlockContainsBreak = false; 3855 _enclosingBlockContainsBreak = false;
3856 try { 3856 try {
3857 Expression conditionExpression = node.condition; 3857 Expression conditionExpression = node.condition;
3858 if (conditionExpression.accept(this)) { 3858 if (conditionExpression.accept(this)) {
3859 return true; 3859 return true;
3860 } 3860 }
3861 bool blockReturns = node.body.accept(this); 3861 node.body.accept(this);
3862 // TODO(jwren) Do we want to take all constant expressions into account? 3862 // TODO(jwren) Do we want to take all constant expressions into account?
3863 if (conditionExpression is BooleanLiteral) { 3863 if (conditionExpression is BooleanLiteral) {
3864 // If while(true), and the body doesn't return or the body doesn't have 3864 // If while(true), and the body doesn't have a break, then return true.
3865 // a break, then return true. 3865 // The body might be found to exit, but if there are any break
3866 if (conditionExpression.value && 3866 // statements, then it is a faulty finding. In other words:
3867 (blockReturns || !_enclosingBlockContainsBreak)) { 3867 //
3868 // * If the body exits, and does not contain a break statement, then
3869 // it exits.
3870 // * If the body does not exit, and does not contain a break statement,
3871 // then it loops infinitely (also an exit).
3872 //
3873 // As both conditions forbid any break statements to be found, the logic
3874 // just boils down to checking [_enclosingBlockContainsBreak].
3875 if (conditionExpression.value && !_enclosingBlockContainsBreak) {
3868 return true; 3876 return true;
3869 } 3877 }
3870 } 3878 }
3871 return false; 3879 return false;
3872 } finally { 3880 } finally {
3873 _enclosingBlockContainsBreak = outerBreakValue; 3881 _enclosingBlockContainsBreak = outerBreakValue;
3874 } 3882 }
3875 } 3883 }
3876 3884
3877 @override 3885 @override
(...skipping 7080 matching lines...) Expand 10 before | Expand all | Expand 10 after
10958 return null; 10966 return null;
10959 } 10967 }
10960 if (identical(node.staticElement, variable)) { 10968 if (identical(node.staticElement, variable)) {
10961 if (node.inSetterContext()) { 10969 if (node.inSetterContext()) {
10962 result = true; 10970 result = true;
10963 } 10971 }
10964 } 10972 }
10965 return null; 10973 return null;
10966 } 10974 }
10967 } 10975 }
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