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

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

Issue 1402813005: move strong mode hints behind flag (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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/src/task/dart_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) 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/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 if (error.errorCode.errorSeverity == ErrorSeverity.ERROR) _failure = true; 320 if (error.errorCode.errorSeverity == ErrorSeverity.ERROR) _failure = true;
321 _reporter.onError(error); 321 _reporter.onError(error);
322 } 322 }
323 } 323 }
324 324
325 /// Checks the body of functions and properties. 325 /// Checks the body of functions and properties.
326 class CodeChecker extends RecursiveAstVisitor { 326 class CodeChecker extends RecursiveAstVisitor {
327 final TypeRules rules; 327 final TypeRules rules;
328 final AnalysisErrorListener reporter; 328 final AnalysisErrorListener reporter;
329 final _OverrideChecker _overrideChecker; 329 final _OverrideChecker _overrideChecker;
330 final bool _hints;
331
330 bool _failure = false; 332 bool _failure = false;
331 bool get failure => _failure || _overrideChecker._failure; 333 bool get failure => _failure || _overrideChecker._failure;
332 334
333 void reset() { 335 void reset() {
334 _failure = false; 336 _failure = false;
335 _overrideChecker._failure = false; 337 _overrideChecker._failure = false;
336 } 338 }
337 339
338 CodeChecker(TypeRules rules, AnalysisErrorListener reporter) 340 CodeChecker(TypeRules rules, AnalysisErrorListener reporter,
341 {bool hints: false})
339 : rules = rules, 342 : rules = rules,
340 reporter = reporter, 343 reporter = reporter,
344 _hints = hints,
341 _overrideChecker = new _OverrideChecker(rules, reporter); 345 _overrideChecker = new _OverrideChecker(rules, reporter);
342 346
343 @override 347 @override
344 void visitComment(Comment node) { 348 void visitComment(Comment node) {
345 // skip, no need to do typechecking inside comments (they may contain 349 // skip, no need to do typechecking inside comments (they may contain
346 // comment references which would require resolution). 350 // comment references which would require resolution).
347 } 351 }
348 352
349 @override 353 @override
350 void visitClassDeclaration(ClassDeclaration node) { 354 void visitClassDeclaration(ClassDeclaration node) {
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 921
918 DartType _getStaticType(Expression expr) { 922 DartType _getStaticType(Expression expr) {
919 var type = expr.staticType; 923 var type = expr.staticType;
920 if (type == null) { 924 if (type == null) {
921 reporter.onError(new MissingTypeError(expr).toAnalysisError()); 925 reporter.onError(new MissingTypeError(expr).toAnalysisError());
922 } 926 }
923 return type ?? rules.provider.dynamicType; 927 return type ?? rules.provider.dynamicType;
924 } 928 }
925 929
926 void _recordDynamicInvoke(AstNode node, AstNode target) { 930 void _recordDynamicInvoke(AstNode node, AstNode target) {
927 reporter.onError(new DynamicInvoke(rules, node).toAnalysisError()); 931 if (_hints) {
932 reporter.onError(new DynamicInvoke(rules, node).toAnalysisError());
933 }
928 // TODO(jmesserly): we may eventually want to record if the whole operation 934 // TODO(jmesserly): we may eventually want to record if the whole operation
929 // (node) was dynamic, rather than the target, but this is an easier fit 935 // (node) was dynamic, rather than the target, but this is an easier fit
930 // with what we used to do. 936 // with what we used to do.
931 DynamicInvoke.set(target, true); 937 DynamicInvoke.set(target, true);
932 } 938 }
933 939
934 void _recordMessage(StaticInfo info) { 940 void _recordMessage(StaticInfo info) {
935 if (info == null) return; 941 if (info == null) return;
936 var error = info.toAnalysisError(); 942 var error = info.toAnalysisError();
937 if (error.errorCode.errorSeverity == ErrorSeverity.ERROR) _failure = true; 943
938 reporter.onError(error); 944 var severity = error.errorCode.errorSeverity;
945 if (severity == ErrorSeverity.ERROR) _failure = true;
946 if (severity != ErrorSeverity.INFO || _hints) {
947 reporter.onError(error);
948 }
939 949
940 if (info is CoercionInfo) { 950 if (info is CoercionInfo) {
941 // TODO(jmesserly): if we're run again on the same AST, we'll produce the 951 // TODO(jmesserly): if we're run again on the same AST, we'll produce the
942 // same annotations. This should be harmless. This might go away once 952 // same annotations. This should be harmless. This might go away once
943 // CodeChecker is integrated better with analyzer, as it will know that 953 // CodeChecker is integrated better with analyzer, as it will know that
944 // checking has already been performed. 954 // checking has already been performed.
945 // assert(CoercionInfo.get(info.node) == null); 955 // assert(CoercionInfo.get(info.node) == null);
946 CoercionInfo.set(info.node, info); 956 CoercionInfo.set(info.node, info);
947 } 957 }
948 } 958 }
(...skipping 25 matching lines...) Expand all
974 } 984 }
975 } catch (e) { 985 } catch (e) {
976 // TODO(sigmund): remove this try-catch block (see issue #48). 986 // TODO(sigmund): remove this try-catch block (see issue #48).
977 } 987 }
978 if (baseMethod == null || baseMethod.isStatic) return null; 988 if (baseMethod == null || baseMethod.isStatic) return null;
979 return baseMethod.type; 989 return baseMethod.type;
980 } 990 }
981 ; 991 ;
982 return f; 992 return f;
983 } 993 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698