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

Side by Side Diff: pkg/analyzer/lib/src/generated/error_verifier.dart

Issue 895113002: Add static type checking of "yield" statements to analyzer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/lib/src/generated/error.dart ('k') | pkg/analyzer/lib/src/generated/resolver.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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library engine.resolver.error_verifier; 5 library engine.resolver.error_verifier;
6 6
7 import "dart:math" as math; 7 import "dart:math" as math;
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'ast.dart'; 10 import 'ast.dart';
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 } 1088 }
1089 1089
1090 @override 1090 @override
1091 Object visitWhileStatement(WhileStatement node) { 1091 Object visitWhileStatement(WhileStatement node) {
1092 _checkForNonBoolCondition(node.condition); 1092 _checkForNonBoolCondition(node.condition);
1093 return super.visitWhileStatement(node); 1093 return super.visitWhileStatement(node);
1094 } 1094 }
1095 1095
1096 @override 1096 @override
1097 Object visitYieldStatement(YieldStatement node) { 1097 Object visitYieldStatement(YieldStatement node) {
1098 if (!_inGenerator) { 1098 if (_inGenerator) {
1099 _checkForYieldOfInvalidType(node.expression);
1100 } else {
1099 CompileTimeErrorCode errorCode; 1101 CompileTimeErrorCode errorCode;
1100 if (node.star != null) { 1102 if (node.star != null) {
1101 errorCode = CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR; 1103 errorCode = CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR;
1102 } else { 1104 } else {
1103 errorCode = CompileTimeErrorCode.YIELD_IN_NON_GENERATOR; 1105 errorCode = CompileTimeErrorCode.YIELD_IN_NON_GENERATOR;
1104 } 1106 }
1105 _errorReporter.reportErrorForNode(errorCode, node); 1107 _errorReporter.reportErrorForNode(errorCode, node);
1106 } 1108 }
1107 return super.visitYieldStatement(node); 1109 return super.visitYieldStatement(node);
1108 } 1110 }
(...skipping 4595 matching lines...) Expand 10 before | Expand all | Expand 10 after
5704 parameters[0].kind != ParameterKind.REQUIRED) { 5706 parameters[0].kind != ParameterKind.REQUIRED) {
5705 _errorReporter.reportErrorForNode( 5707 _errorReporter.reportErrorForNode(
5706 CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER, 5708 CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER,
5707 setterName); 5709 setterName);
5708 return true; 5710 return true;
5709 } 5711 }
5710 return false; 5712 return false;
5711 } 5713 }
5712 5714
5713 /** 5715 /**
5716 * Check for a type mis-match between the yielded type and the declared
5717 * return type of a generator function.
5718 *
5719 * This method should only be called in generator functions.
5720 */
5721 bool _checkForYieldOfInvalidType(Expression yieldExpression) {
5722 assert(_inGenerator);
5723 if (_enclosingFunction == null) {
5724 return false;
5725 }
5726 DartType declaredReturnType = _enclosingFunction.returnType;
5727 DartType staticYieldedType = getStaticType(yieldExpression);
5728 DartType impliedReturnType;
5729 if (_enclosingFunction.isAsynchronous) {
5730 impliedReturnType =
5731 _typeProvider.streamType.substitute4(<DartType>[staticYieldedType]);
5732 } else {
5733 impliedReturnType =
5734 _typeProvider.iterableType.substitute4(<DartType>[staticYieldedType]);
5735 }
5736 if (impliedReturnType.isAssignableTo(declaredReturnType)) {
5737 return false;
5738 }
5739 _errorReporter.reportTypeErrorForNode(
5740 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE,
5741 yieldExpression,
5742 [declaredReturnType, impliedReturnType]);
5743 return true;
5744 }
5745
5746 /**
5714 * This verifies that if the given class declaration implements the class Func tion that it has a 5747 * This verifies that if the given class declaration implements the class Func tion that it has a
5715 * concrete implementation of the call method. 5748 * concrete implementation of the call method.
5716 * 5749 *
5717 * @return `true` if and only if an error code is generated on the passed node 5750 * @return `true` if and only if an error code is generated on the passed node
5718 * See [StaticWarningCode.FUNCTION_WITHOUT_CALL]. 5751 * See [StaticWarningCode.FUNCTION_WITHOUT_CALL].
5719 */ 5752 */
5720 bool _checkImplementsFunctionWithoutCall(ClassDeclaration node) { 5753 bool _checkImplementsFunctionWithoutCall(ClassDeclaration node) {
5721 if (node.isAbstract) { 5754 if (node.isAbstract) {
5722 return false; 5755 return false;
5723 } 5756 }
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
6236 toCheck.add(type.element); 6269 toCheck.add(type.element);
6237 // type arguments 6270 // type arguments
6238 if (type is InterfaceType) { 6271 if (type is InterfaceType) {
6239 InterfaceType interfaceType = type; 6272 InterfaceType interfaceType = type;
6240 for (DartType typeArgument in interfaceType.typeArguments) { 6273 for (DartType typeArgument in interfaceType.typeArguments) {
6241 _addTypeToCheck(typeArgument); 6274 _addTypeToCheck(typeArgument);
6242 } 6275 }
6243 } 6276 }
6244 } 6277 }
6245 } 6278 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/error.dart ('k') | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698