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

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

Issue 894063004: Fix return type checking for generator functions. (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 | « no previous file | 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 1775 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 if (returnExpression == null) { 1786 if (returnExpression == null) {
1787 return false; 1787 return false;
1788 } 1788 }
1789 _errorReporter.reportErrorForNode( 1789 _errorReporter.reportErrorForNode(
1790 CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR, 1790 CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR,
1791 returnExpression); 1791 returnExpression);
1792 return true; 1792 return true;
1793 } 1793 }
1794 // RETURN_WITHOUT_VALUE 1794 // RETURN_WITHOUT_VALUE
1795 if (returnExpression == null) { 1795 if (returnExpression == null) {
1796 if (_computeReturnTypeForMethod( 1796 if (_inGenerator ||
1797 null).isAssignableTo(expectedReturnType)) { 1797 _computeReturnTypeForMethod(null).isAssignableTo(expectedReturnType)) {
1798 return false; 1798 return false;
1799 } 1799 }
1800 _hasReturnWithoutValue = true; 1800 _hasReturnWithoutValue = true;
1801 _errorReporter.reportErrorForNode( 1801 _errorReporter.reportErrorForNode(
1802 StaticWarningCode.RETURN_WITHOUT_VALUE, 1802 StaticWarningCode.RETURN_WITHOUT_VALUE,
1803 node); 1803 node);
1804 return true; 1804 return true;
1805 } else if (_inGenerator) { 1805 } else if (_inGenerator) {
1806 // RETURN_IN_GENERATOR 1806 // RETURN_IN_GENERATOR
1807 _errorReporter.reportErrorForNode( 1807 _errorReporter.reportErrorForNode(
(...skipping 3357 matching lines...) Expand 10 before | Expand all | Expand 10 after
5165 * @param returnExpression the returned expression to evaluate 5165 * @param returnExpression the returned expression to evaluate
5166 * @param expectedReturnType the expressed return type by the enclosing method or function 5166 * @param expectedReturnType the expressed return type by the enclosing method or function
5167 * @return `true` if and only if an error code is generated on the passed node 5167 * @return `true` if and only if an error code is generated on the passed node
5168 * See [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]. 5168 * See [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE].
5169 */ 5169 */
5170 bool _checkForReturnOfInvalidType(Expression returnExpression, 5170 bool _checkForReturnOfInvalidType(Expression returnExpression,
5171 DartType expectedReturnType) { 5171 DartType expectedReturnType) {
5172 if (_enclosingFunction == null) { 5172 if (_enclosingFunction == null) {
5173 return false; 5173 return false;
5174 } 5174 }
5175 if (_inGenerator) {
5176 // "return expression;" is disallowed in generators, but this is checked
5177 // elsewhere. Bare "return" is always allowed in generators regardless
5178 // of the return type. So no need to do any further checking.
5179 return false;
5180 }
5175 DartType staticReturnType = _computeReturnTypeForMethod(returnExpression); 5181 DartType staticReturnType = _computeReturnTypeForMethod(returnExpression);
5176 if (expectedReturnType.isVoid) { 5182 if (expectedReturnType.isVoid) {
5177 if (staticReturnType.isVoid || 5183 if (staticReturnType.isVoid ||
5178 staticReturnType.isDynamic || 5184 staticReturnType.isDynamic ||
5179 staticReturnType.isBottom) { 5185 staticReturnType.isBottom) {
5180 return false; 5186 return false;
5181 } 5187 }
5182 _errorReporter.reportTypeErrorForNode( 5188 _errorReporter.reportTypeErrorForNode(
5183 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, 5189 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
5184 returnExpression, 5190 returnExpression,
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
5768 CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS, 5774 CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS,
5769 interfaceNode, 5775 interfaceNode,
5770 [superType.displayName]); 5776 [superType.displayName]);
5771 } 5777 }
5772 } 5778 }
5773 // done 5779 // done
5774 return hasProblem; 5780 return hasProblem;
5775 } 5781 }
5776 5782
5777 DartType _computeReturnTypeForMethod(Expression returnExpression) { 5783 DartType _computeReturnTypeForMethod(Expression returnExpression) {
5778 // TODO(paulberry): do the right thing for generators. 5784 // This method should never be called for generators, since generators are
5785 // never allowed to contain return statements with expressions.
5786 assert(!_inGenerator);
5779 if (returnExpression == null) { 5787 if (returnExpression == null) {
5780 if (_enclosingFunction.isAsynchronous) { 5788 if (_enclosingFunction.isAsynchronous) {
5781 return _typeProvider.futureNullType; 5789 return _typeProvider.futureNullType;
5782 } else { 5790 } else {
5783 return VoidTypeImpl.instance; 5791 return VoidTypeImpl.instance;
5784 } 5792 }
5785 } 5793 }
5786 DartType staticReturnType = getStaticType(returnExpression); 5794 DartType staticReturnType = getStaticType(returnExpression);
5787 if (staticReturnType != null && 5795 if (staticReturnType != null &&
5788 _enclosingFunction.isAsynchronous && 5796 _enclosingFunction.isAsynchronous &&
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
6228 toCheck.add(type.element); 6236 toCheck.add(type.element);
6229 // type arguments 6237 // type arguments
6230 if (type is InterfaceType) { 6238 if (type is InterfaceType) {
6231 InterfaceType interfaceType = type; 6239 InterfaceType interfaceType = type;
6232 for (DartType typeArgument in interfaceType.typeArguments) { 6240 for (DartType typeArgument in interfaceType.typeArguments) {
6233 _addTypeToCheck(typeArgument); 6241 _addTypeToCheck(typeArgument);
6234 } 6242 }
6235 } 6243 }
6236 } 6244 }
6237 } 6245 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698