OLD | NEW |
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 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); | 1099 _checkForYieldOfInvalidType(node.expression, node.star != null); |
1100 } else { | 1100 } else { |
1101 CompileTimeErrorCode errorCode; | 1101 CompileTimeErrorCode errorCode; |
1102 if (node.star != null) { | 1102 if (node.star != null) { |
1103 errorCode = CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR; | 1103 errorCode = CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR; |
1104 } else { | 1104 } else { |
1105 errorCode = CompileTimeErrorCode.YIELD_IN_NON_GENERATOR; | 1105 errorCode = CompileTimeErrorCode.YIELD_IN_NON_GENERATOR; |
1106 } | 1106 } |
1107 _errorReporter.reportErrorForNode(errorCode, node); | 1107 _errorReporter.reportErrorForNode(errorCode, node); |
1108 } | 1108 } |
1109 return super.visitYieldStatement(node); | 1109 return super.visitYieldStatement(node); |
(...skipping 4601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5711 } | 5711 } |
5712 return false; | 5712 return false; |
5713 } | 5713 } |
5714 | 5714 |
5715 /** | 5715 /** |
5716 * Check for a type mis-match between the yielded type and the declared | 5716 * Check for a type mis-match between the yielded type and the declared |
5717 * return type of a generator function. | 5717 * return type of a generator function. |
5718 * | 5718 * |
5719 * This method should only be called in generator functions. | 5719 * This method should only be called in generator functions. |
5720 */ | 5720 */ |
5721 bool _checkForYieldOfInvalidType(Expression yieldExpression) { | 5721 bool _checkForYieldOfInvalidType(Expression yieldExpression, |
| 5722 bool isYieldEach) { |
5722 assert(_inGenerator); | 5723 assert(_inGenerator); |
5723 if (_enclosingFunction == null) { | 5724 if (_enclosingFunction == null) { |
5724 return false; | 5725 return false; |
5725 } | 5726 } |
5726 DartType declaredReturnType = _enclosingFunction.returnType; | 5727 DartType declaredReturnType = _enclosingFunction.returnType; |
5727 DartType staticYieldedType = getStaticType(yieldExpression); | 5728 DartType staticYieldedType = getStaticType(yieldExpression); |
5728 DartType impliedReturnType; | 5729 DartType impliedReturnType; |
5729 if (_enclosingFunction.isAsynchronous) { | 5730 if (isYieldEach) { |
| 5731 impliedReturnType = staticYieldedType; |
| 5732 } else if (_enclosingFunction.isAsynchronous) { |
5730 impliedReturnType = | 5733 impliedReturnType = |
5731 _typeProvider.streamType.substitute4(<DartType>[staticYieldedType]); | 5734 _typeProvider.streamType.substitute4(<DartType>[staticYieldedType]); |
5732 } else { | 5735 } else { |
5733 impliedReturnType = | 5736 impliedReturnType = |
5734 _typeProvider.iterableType.substitute4(<DartType>[staticYieldedType]); | 5737 _typeProvider.iterableType.substitute4(<DartType>[staticYieldedType]); |
5735 } | 5738 } |
5736 if (impliedReturnType.isAssignableTo(declaredReturnType)) { | 5739 if (impliedReturnType.isAssignableTo(declaredReturnType)) { |
5737 return false; | 5740 return false; |
5738 } | 5741 } |
5739 _errorReporter.reportTypeErrorForNode( | 5742 _errorReporter.reportTypeErrorForNode( |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6269 toCheck.add(type.element); | 6272 toCheck.add(type.element); |
6270 // type arguments | 6273 // type arguments |
6271 if (type is InterfaceType) { | 6274 if (type is InterfaceType) { |
6272 InterfaceType interfaceType = type; | 6275 InterfaceType interfaceType = type; |
6273 for (DartType typeArgument in interfaceType.typeArguments) { | 6276 for (DartType typeArgument in interfaceType.typeArguments) { |
6274 _addTypeToCheck(typeArgument); | 6277 _addTypeToCheck(typeArgument); |
6275 } | 6278 } |
6276 } | 6279 } |
6277 } | 6280 } |
6278 } | 6281 } |
OLD | NEW |