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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/error_verifier.dart
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index fdefc3b6cb1ee80fe1c0c5a745472f0aafcfa338..56a5d10ab5040383b098ca0aedec741e011a74bd 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -1793,8 +1793,8 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
}
// RETURN_WITHOUT_VALUE
if (returnExpression == null) {
- if (_computeReturnTypeForMethod(
- null).isAssignableTo(expectedReturnType)) {
+ if (_inGenerator ||
+ _computeReturnTypeForMethod(null).isAssignableTo(expectedReturnType)) {
return false;
}
_hasReturnWithoutValue = true;
@@ -5172,6 +5172,12 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
if (_enclosingFunction == null) {
return false;
}
+ if (_inGenerator) {
+ // "return expression;" is disallowed in generators, but this is checked
+ // elsewhere. Bare "return" is always allowed in generators regardless
+ // of the return type. So no need to do any further checking.
+ return false;
+ }
DartType staticReturnType = _computeReturnTypeForMethod(returnExpression);
if (expectedReturnType.isVoid) {
if (staticReturnType.isVoid ||
@@ -5775,7 +5781,9 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
}
DartType _computeReturnTypeForMethod(Expression returnExpression) {
- // TODO(paulberry): do the right thing for generators.
+ // This method should never be called for generators, since generators are
+ // never allowed to contain return statements with expressions.
+ assert(!_inGenerator);
if (returnExpression == null) {
if (_enclosingFunction.isAsynchronous) {
return _typeProvider.futureNullType;
« 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