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

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

Issue 1462133005: Downwards inference. This adds support to the resolver for downwards (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments 2 Created 5 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
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 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 // checking in SwitchStatement shouldn't be necessary. 460 // checking in SwitchStatement shouldn't be necessary.
461 node.visitChildren(this); 461 node.visitChildren(this);
462 } 462 }
463 463
464 @override 464 @override
465 void visitListLiteral(ListLiteral node) { 465 void visitListLiteral(ListLiteral node) {
466 var type = rules.provider.dynamicType; 466 var type = rules.provider.dynamicType;
467 if (node.typeArguments != null) { 467 if (node.typeArguments != null) {
468 var targs = node.typeArguments.arguments; 468 var targs = node.typeArguments.arguments;
469 if (targs.length > 0) type = targs[0].type; 469 if (targs.length > 0) type = targs[0].type;
470 } else if (node.staticType != null && node.staticType is InterfaceType) {
Brian Wilkerson 2015/12/01 22:31:09 You can remove "node.staticType != null && " (it's
Leaf 2015/12/01 23:39:24 Done.
471 InterfaceType listT = node.staticType;
472 var targs = listT.typeArguments;
473 if (targs != null && targs.length > 0) type = targs[0];
470 } 474 }
471 var elements = node.elements; 475 var elements = node.elements;
472 for (int i = 0; i < elements.length; i++) { 476 for (int i = 0; i < elements.length; i++) {
473 checkArgument(elements[i], type); 477 checkArgument(elements[i], type);
474 } 478 }
475 super.visitListLiteral(node); 479 super.visitListLiteral(node);
476 } 480 }
477 481
478 @override 482 @override
479 void visitMapLiteral(MapLiteral node) { 483 void visitMapLiteral(MapLiteral node) {
480 var ktype = rules.provider.dynamicType; 484 var ktype = rules.provider.dynamicType;
481 var vtype = rules.provider.dynamicType; 485 var vtype = rules.provider.dynamicType;
482 if (node.typeArguments != null) { 486 if (node.typeArguments != null) {
483 var targs = node.typeArguments.arguments; 487 var targs = node.typeArguments.arguments;
484 if (targs.length > 0) ktype = targs[0].type; 488 if (targs.length > 0) ktype = targs[0].type;
485 if (targs.length > 1) vtype = targs[1].type; 489 if (targs.length > 1) vtype = targs[1].type;
490 } else if (node.staticType != null && node.staticType is InterfaceType) {
Brian Wilkerson 2015/12/01 22:31:09 ditto
Leaf 2015/12/01 23:39:24 Done.
491 InterfaceType mapT = node.staticType;
492 var targs = mapT.typeArguments;
493 if (targs != null) {
494 if (targs.length > 0) ktype = targs[0];
495 if (targs.length > 1) vtype = targs[1];
496 }
486 } 497 }
487 var entries = node.entries; 498 var entries = node.entries;
488 for (int i = 0; i < entries.length; i++) { 499 for (int i = 0; i < entries.length; i++) {
489 var entry = entries[i]; 500 var entry = entries[i];
490 checkArgument(entry.key, ktype); 501 checkArgument(entry.key, ktype);
491 checkArgument(entry.value, vtype); 502 checkArgument(entry.value, vtype);
492 } 503 }
493 super.visitMapLiteral(node); 504 super.visitMapLiteral(node);
494 } 505 }
495 506
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 } 951 }
941 // TODO(jmesserly): we may eventually want to record if the whole operation 952 // TODO(jmesserly): we may eventually want to record if the whole operation
942 // (node) was dynamic, rather than the target, but this is an easier fit 953 // (node) was dynamic, rather than the target, but this is an easier fit
943 // with what we used to do. 954 // with what we used to do.
944 DynamicInvoke.set(target, true); 955 DynamicInvoke.set(target, true);
945 } 956 }
946 957
947 void _recordMessage(StaticInfo info) { 958 void _recordMessage(StaticInfo info) {
948 if (info == null) return; 959 if (info == null) return;
949 var error = info.toAnalysisError(); 960 var error = info.toAnalysisError();
950
951 var severity = error.errorCode.errorSeverity; 961 var severity = error.errorCode.errorSeverity;
952 if (severity == ErrorSeverity.ERROR) _failure = true; 962 if (severity == ErrorSeverity.ERROR) _failure = true;
953 if (severity != ErrorSeverity.INFO || _hints) { 963 if (severity != ErrorSeverity.INFO || _hints) {
954 reporter.onError(error); 964 reporter.onError(error);
955 } 965 }
956 966
957 if (info is CoercionInfo) { 967 if (info is CoercionInfo) {
958 // TODO(jmesserly): if we're run again on the same AST, we'll produce the 968 // TODO(jmesserly): if we're run again on the same AST, we'll produce the
959 // same annotations. This should be harmless. This might go away once 969 // same annotations. This should be harmless. This might go away once
960 // CodeChecker is integrated better with analyzer, as it will know that 970 // CodeChecker is integrated better with analyzer, as it will know that
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 } 1037 }
1028 } catch (e) { 1038 } catch (e) {
1029 // TODO(sigmund): remove this try-catch block (see issue #48). 1039 // TODO(sigmund): remove this try-catch block (see issue #48).
1030 } 1040 }
1031 if (baseMethod == null || baseMethod.isStatic) return null; 1041 if (baseMethod == null || baseMethod.isStatic) return null;
1032 return baseMethod.type; 1042 return baseMethod.type;
1033 } 1043 }
1034 ; 1044 ;
1035 return f; 1045 return f;
1036 } 1046 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698