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

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

Issue 810843002: Fix for issue 21771 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/resolver_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 engine.resolver; 5 library engine.resolver;
6 6
7 import "dart:math" as math; 7 import "dart:math" as math;
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/src/generated/utilities_collection.dart'; 10 import 'package:analyzer/src/generated/utilities_collection.dart';
(...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 // } 1289 // }
1290 1290
1291 /** 1291 /**
1292 * Check for the passed as expression for the [HintCode.UNNECESSARY_CAST] hint code. 1292 * Check for the passed as expression for the [HintCode.UNNECESSARY_CAST] hint code.
1293 * 1293 *
1294 * @param node the as expression to check 1294 * @param node the as expression to check
1295 * @return `true` if and only if a hint code is generated on the passed node 1295 * @return `true` if and only if a hint code is generated on the passed node
1296 * See [HintCode.UNNECESSARY_CAST]. 1296 * See [HintCode.UNNECESSARY_CAST].
1297 */ 1297 */
1298 bool _checkForUnnecessaryCast(AsExpression node) { 1298 bool _checkForUnnecessaryCast(AsExpression node) {
1299 Expression expression = node.expression;
1300 TypeName typeName = node.type;
1301 DartType lhsType = expression.staticType;
1302 DartType rhsType = typeName.type;
1303 // TODO(jwren) After dartbug.com/13732, revisit this, we should be able to 1299 // TODO(jwren) After dartbug.com/13732, revisit this, we should be able to
1304 // remove the !(x instanceof TypeParameterType) checks. 1300 // remove the (x is! TypeParameterType) checks.
1301 AstNode parent = node.parent;
1302 if (parent is ConditionalExpression && (node == parent.thenExpression || nod e == parent.elseExpression)) {
1303 Expression thenExpression = parent.thenExpression;
1304 DartType thenType;
1305 if (thenExpression is AsExpression) {
1306 thenType = thenExpression.expression.staticType;
1307 } else {
1308 thenType = thenExpression.staticType;
1309 }
1310 Expression elseExpression = parent.elseExpression;
1311 DartType elseType;
1312 if (elseExpression is AsExpression) {
1313 elseType = elseExpression.expression.staticType;
1314 } else {
1315 elseType = elseExpression.staticType;
1316 }
1317 if (thenType != null &&
1318 elseType != null &&
1319 !thenType.isDynamic &&
1320 !elseType.isDynamic &&
1321 !thenType.isMoreSpecificThan(elseType) &&
1322 !elseType.isMoreSpecificThan(thenType)) {
1323 return false;
1324 }
1325 }
1326 DartType lhsType = node.expression.staticType;
1327 DartType rhsType = node.type.type;
1305 if (lhsType != null && 1328 if (lhsType != null &&
1306 rhsType != null && 1329 rhsType != null &&
1307 !lhsType.isDynamic && 1330 !lhsType.isDynamic &&
1308 !rhsType.isDynamic && 1331 !rhsType.isDynamic &&
1309 lhsType is! TypeParameterType &&
1310 rhsType is! TypeParameterType &&
1311 lhsType.isMoreSpecificThan(rhsType)) { 1332 lhsType.isMoreSpecificThan(rhsType)) {
1312 _errorReporter.reportErrorForNode(HintCode.UNNECESSARY_CAST, node); 1333 _errorReporter.reportErrorForNode(HintCode.UNNECESSARY_CAST, node);
1313 return true; 1334 return true;
1314 } 1335 }
1315 return false; 1336 return false;
1316 } 1337 }
1317 1338
1318 /** 1339 /**
1319 * Check for situations where the result of a method or function is used, when it returns 'void'. 1340 * Check for situations where the result of a method or function is used, when it returns 'void'.
1320 * 1341 *
(...skipping 15060 matching lines...) Expand 10 before | Expand all | Expand 10 after
16381 * library. 16402 * library.
16382 */ 16403 */
16383 final HashSet<String> members = new HashSet<String>(); 16404 final HashSet<String> members = new HashSet<String>();
16384 16405
16385 /** 16406 /**
16386 * Names of resolved or unresolved class members that are read in the 16407 * Names of resolved or unresolved class members that are read in the
16387 * library. 16408 * library.
16388 */ 16409 */
16389 final HashSet<String> readMembers = new HashSet<String>(); 16410 final HashSet<String> readMembers = new HashSet<String>();
16390 } 16411 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698