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

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

Issue 1758913002: Add instantiate method on ParameterizedType and InterfaceType. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments Created 4 years, 9 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
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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 // Check that the expression is an Iterable. 330 // Check that the expression is an Iterable.
331 var expr = node.iterable; 331 var expr = node.iterable;
332 var iterableType = node.awaitKeyword != null 332 var iterableType = node.awaitKeyword != null
333 ? typeProvider.streamType 333 ? typeProvider.streamType
334 : typeProvider.iterableType; 334 : typeProvider.iterableType;
335 var loopVariable = node.identifier != null 335 var loopVariable = node.identifier != null
336 ? node.identifier 336 ? node.identifier
337 : node.loopVariable?.identifier; 337 : node.loopVariable?.identifier;
338 if (loopVariable != null) { 338 if (loopVariable != null) {
339 var iteratorType = loopVariable.staticType; 339 var iteratorType = loopVariable.staticType;
340 var checkedType = iterableType.substitute4([iteratorType]); 340 var checkedType = iterableType.instantiate([iteratorType]);
341 checkAssignment(expr, checkedType); 341 checkAssignment(expr, checkedType);
342 } 342 }
343 node.visitChildren(this); 343 node.visitChildren(this);
344 } 344 }
345 345
346 @override 346 @override
347 void visitForStatement(ForStatement node) { 347 void visitForStatement(ForStatement node) {
348 if (node.condition != null) { 348 if (node.condition != null) {
349 checkBoolean(node.condition); 349 checkBoolean(node.condition);
350 } 350 }
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 // not match the return or yield type. We should have already gotten an 641 // not match the return or yield type. We should have already gotten an
642 // analyzer error in this case. 642 // analyzer error in this case.
643 return; 643 return;
644 } 644 }
645 InterfaceType futureType = typeProvider.futureType; 645 InterfaceType futureType = typeProvider.futureType;
646 DartType actualType = expression?.staticType; 646 DartType actualType = expression?.staticType;
647 if (body.isAsynchronous && 647 if (body.isAsynchronous &&
648 !body.isGenerator && 648 !body.isGenerator &&
649 actualType is InterfaceType && 649 actualType is InterfaceType &&
650 actualType.element == futureType.element) { 650 actualType.element == futureType.element) {
651 type = futureType.substitute4([type]); 651 type = futureType.instantiate([type]);
652 } 652 }
653 // TODO(vsm): Enforce void or dynamic (to void?) when expression is null. 653 // TODO(vsm): Enforce void or dynamic (to void?) when expression is null.
654 if (expression != null) checkAssignment(expression, type); 654 if (expression != null) checkAssignment(expression, type);
655 } 655 }
656 656
657 void _checkRuntimeTypeCheck(AstNode node, TypeName typeName) { 657 void _checkRuntimeTypeCheck(AstNode node, TypeName typeName) {
658 var type = getType(typeName); 658 var type = getType(typeName);
659 if (!rules.isGroundType(type)) { 659 if (!rules.isGroundType(type)) {
660 _recordMessage(new NonGroundTypeCheckInfo(node, type)); 660 _recordMessage(new NonGroundTypeCheckInfo(node, type));
661 } 661 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 // Iterable<T> -> T 746 // Iterable<T> -> T
747 expectedType = typeProvider.iterableType; 747 expectedType = typeProvider.iterableType;
748 } else { 748 } else {
749 // T -> T 749 // T -> T
750 return type; 750 return type;
751 } 751 }
752 } 752 }
753 if (yieldStar) { 753 if (yieldStar) {
754 if (type.isDynamic) { 754 if (type.isDynamic) {
755 // Ensure it's at least a Stream / Iterable. 755 // Ensure it's at least a Stream / Iterable.
756 return expectedType.substitute4([typeProvider.dynamicType]); 756 return expectedType.instantiate([typeProvider.dynamicType]);
757 } else { 757 } else {
758 // Analyzer will provide a separate error if expected type 758 // Analyzer will provide a separate error if expected type
759 // is not compatible with type. 759 // is not compatible with type.
760 return type; 760 return type;
761 } 761 }
762 } 762 }
763 if (type.isDynamic) { 763 if (type.isDynamic) {
764 return type; 764 return type;
765 } else if (type is InterfaceType && type.element == expectedType.element) { 765 } else if (type is InterfaceType && type.element == expectedType.element) {
766 return type.typeArguments[0]; 766 return type.typeArguments[0];
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 } while (!current.isObject && !visited.contains(current)); 1276 } while (!current.isObject && !visited.contains(current));
1277 } 1277 }
1278 1278
1279 void _recordMessage(StaticInfo info) { 1279 void _recordMessage(StaticInfo info) {
1280 if (info == null) return; 1280 if (info == null) return;
1281 var error = info.toAnalysisError(); 1281 var error = info.toAnalysisError();
1282 if (error.errorCode.errorSeverity == ErrorSeverity.ERROR) _failure = true; 1282 if (error.errorCode.errorSeverity == ErrorSeverity.ERROR) _failure = true;
1283 _reporter.onError(error); 1283 _reporter.onError(error);
1284 } 1284 }
1285 } 1285 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summary_sdk.dart ('k') | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698