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

Side by Side Diff: pkg/analyzer/lib/src/task/strong/checker.dart

Issue 2703253006: Turn off `strong_mode_down_cast_composite` warnings by default in Flutter projects.
Patch Set: Remove newline. Created 3 years, 10 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 | « pkg/analyzer/lib/src/generated/workspace.dart ('k') | no next file » | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be 5 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be
6 // refactored to fit into analyzer. 6 // refactored to fit into analyzer.
7 library analyzer.src.task.strong.checker; 7 library analyzer.src.task.strong.checker;
8 8
9 import 'package:analyzer/analyzer.dart'; 9 import 'package:analyzer/analyzer.dart';
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 140 }
141 141
142 typedef FunctionType _MemberTypeGetter(InterfaceType type); 142 typedef FunctionType _MemberTypeGetter(InterfaceType type);
143 143
144 /// Checks the body of functions and properties. 144 /// Checks the body of functions and properties.
145 class CodeChecker extends RecursiveAstVisitor { 145 class CodeChecker extends RecursiveAstVisitor {
146 final StrongTypeSystemImpl rules; 146 final StrongTypeSystemImpl rules;
147 final TypeProvider typeProvider; 147 final TypeProvider typeProvider;
148 final AnalysisErrorListener reporter; 148 final AnalysisErrorListener reporter;
149 final AnalysisOptionsImpl _options; 149 final AnalysisOptionsImpl _options;
150 final bool _hasFlutterDependency;
150 _OverrideChecker _overrideChecker; 151 _OverrideChecker _overrideChecker;
151 152
152 bool _failure = false; 153 bool _failure = false;
153 bool _hasImplicitCasts; 154 bool _hasImplicitCasts;
154 155
155 CodeChecker(TypeProvider typeProvider, StrongTypeSystemImpl rules, 156 CodeChecker(TypeProvider typeProvider, StrongTypeSystemImpl rules,
156 AnalysisErrorListener reporter, this._options) 157 AnalysisErrorListener reporter, this._options, this._hasFlutterDependency)
157 : typeProvider = typeProvider, 158 : typeProvider = typeProvider,
158 rules = rules, 159 rules = rules,
159 reporter = reporter { 160 reporter = reporter {
160 _overrideChecker = new _OverrideChecker(this); 161 _overrideChecker = new _OverrideChecker(this);
161 } 162 }
162 163
163 bool get failure => _failure; 164 bool get failure => _failure;
164 165
165 void checkArgument(Expression arg, DartType expectedType) { 166 void checkArgument(Expression arg, DartType expectedType) {
166 // Preserve named argument structure, so their immediate parent is the 167 // Preserve named argument structure, so their immediate parent is the
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 // Iterable<T> to List<T>. The intuition here is that raw (generic) 1105 // Iterable<T> to List<T>. The intuition here is that raw (generic)
1105 // casts are problematic, and we should complain about those. 1106 // casts are problematic, and we should complain about those.
1106 var typeArgs = from.typeArguments; 1107 var typeArgs = from.typeArguments;
1107 downCastComposite = 1108 downCastComposite =
1108 typeArgs.isEmpty || typeArgs.any((t) => t.isDynamic); 1109 typeArgs.isEmpty || typeArgs.any((t) => t.isDynamic);
1109 } else { 1110 } else {
1110 downCastComposite = !from.isDynamic; 1111 downCastComposite = !from.isDynamic;
1111 } 1112 }
1112 } 1113 }
1113 1114
1115 // BUG(28588): The down-cast-composite warning will be turned off by
1116 // default, but as a first step we're only doing this for Flutter code
1117 // and we will leave it on for web projects to help with the migration
1118 // to strong mode and the associate runtime type checks. Flutter projects
1119 // can still turn on the warning explicitly through analysis options.
1120 if (_hasFlutterDependency && downCastComposite) {
1121 bool hasExplicitOption = _options.errorProcessors.any(
1122 (processor) => processor.code == StrongModeCode.DOWN_CAST_COMPOSITE);
1123 if (!hasExplicitOption) return;
1124 }
1125
1114 var parent = expr.parent; 1126 var parent = expr.parent;
1115 ErrorCode errorCode; 1127 ErrorCode errorCode;
1116 if (downCastComposite) { 1128 if (downCastComposite) {
1117 errorCode = StrongModeCode.DOWN_CAST_COMPOSITE; 1129 errorCode = StrongModeCode.DOWN_CAST_COMPOSITE;
1118 } else if (from.isDynamic) { 1130 } else if (from.isDynamic) {
1119 errorCode = StrongModeCode.DYNAMIC_CAST; 1131 errorCode = StrongModeCode.DYNAMIC_CAST;
1120 } else if (parent is VariableDeclaration && parent.initializer == expr) { 1132 } else if (parent is VariableDeclaration && parent.initializer == expr) {
1121 errorCode = StrongModeCode.ASSIGNMENT_CAST; 1133 errorCode = StrongModeCode.ASSIGNMENT_CAST;
1122 } else { 1134 } else {
1123 errorCode = opAssign 1135 errorCode = opAssign
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 var visited = new Set<InterfaceType>(); 1505 var visited = new Set<InterfaceType>();
1494 do { 1506 do {
1495 visited.add(current); 1507 visited.add(current);
1496 current.mixins.reversed.forEach( 1508 current.mixins.reversed.forEach(
1497 (m) => _checkIndividualOverridesFromClass(node, m, seen, true)); 1509 (m) => _checkIndividualOverridesFromClass(node, m, seen, true));
1498 _checkIndividualOverridesFromClass(node, current.superclass, seen, true); 1510 _checkIndividualOverridesFromClass(node, current.superclass, seen, true);
1499 current = current.superclass; 1511 current = current.superclass;
1500 } while (!current.isObject && !visited.contains(current)); 1512 } while (!current.isObject && !visited.contains(current));
1501 } 1513 }
1502 } 1514 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/workspace.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698