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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/resolver_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 c272ed1969f1ca6dad2030c4ab6a70ccb03073ad..10f3a81d3c7902672256eef8ea854f90aee42d46 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -1296,18 +1296,39 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
* See [HintCode.UNNECESSARY_CAST].
*/
bool _checkForUnnecessaryCast(AsExpression node) {
- Expression expression = node.expression;
- TypeName typeName = node.type;
- DartType lhsType = expression.staticType;
- DartType rhsType = typeName.type;
// TODO(jwren) After dartbug.com/13732, revisit this, we should be able to
- // remove the !(x instanceof TypeParameterType) checks.
+ // remove the (x is! TypeParameterType) checks.
+ AstNode parent = node.parent;
+ if (parent is ConditionalExpression && (node == parent.thenExpression || node == parent.elseExpression)) {
+ Expression thenExpression = parent.thenExpression;
+ DartType thenType;
+ if (thenExpression is AsExpression) {
+ thenType = thenExpression.expression.staticType;
+ } else {
+ thenType = thenExpression.staticType;
+ }
+ Expression elseExpression = parent.elseExpression;
+ DartType elseType;
+ if (elseExpression is AsExpression) {
+ elseType = elseExpression.expression.staticType;
+ } else {
+ elseType = elseExpression.staticType;
+ }
+ if (thenType != null &&
+ elseType != null &&
+ !thenType.isDynamic &&
+ !elseType.isDynamic &&
+ !thenType.isMoreSpecificThan(elseType) &&
+ !elseType.isMoreSpecificThan(thenType)) {
+ return false;
+ }
+ }
+ DartType lhsType = node.expression.staticType;
+ DartType rhsType = node.type.type;
if (lhsType != null &&
rhsType != null &&
!lhsType.isDynamic &&
!rhsType.isDynamic &&
- lhsType is! TypeParameterType &&
- rhsType is! TypeParameterType &&
lhsType.isMoreSpecificThan(rhsType)) {
_errorReporter.reportErrorForNode(HintCode.UNNECESSARY_CAST, node);
return true;
« 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