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

Unified Diff: pkg/analyzer/lib/src/generated/error_verifier.dart

Issue 898513002: Fix async/await type checking in analyzer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Reformat and sort methods 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
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 4b83983c15b977570ad69cae502f926ca4c14ac3..0ea52160c5b5ec2baa950aaa8edb5facab13e5ab 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -1793,7 +1793,8 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
}
// RETURN_WITHOUT_VALUE
if (returnExpression == null) {
- if (VoidTypeImpl.instance.isAssignableTo(expectedReturnType)) {
+ if (_computeReturnTypeForMethod(
+ null).isAssignableTo(expectedReturnType)) {
return false;
}
_hasReturnWithoutValue = true;
@@ -5171,7 +5172,7 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
if (_enclosingFunction == null) {
return false;
}
- DartType staticReturnType = getStaticType(returnExpression);
+ DartType staticReturnType = _computeReturnTypeForMethod(returnExpression);
if (expectedReturnType.isVoid) {
if (staticReturnType.isVoid ||
staticReturnType.isDynamic ||
@@ -5184,22 +5185,6 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
[staticReturnType, expectedReturnType, _enclosingFunction.displayName]);
return true;
}
- if (_enclosingFunction.isAsynchronous && !_enclosingFunction.isGenerator) {
- // TODO(brianwilkerson) Figure out how to get the type "Future" so that we
- // can build the type we need to test against.
-// InterfaceType impliedType = "Future<" + flatten(staticReturnType) + ">"
-// if (impliedType.isAssignableTo(expectedReturnType)) {
-// return false;
-// }
-// errorReporter.reportTypeErrorForNode(
-// StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
-// returnExpression,
-// impliedType,
-// expectedReturnType.getDisplayName(),
-// enclosingFunction.getDisplayName());
-// return true;
- return false;
- }
if (staticReturnType.isAssignableTo(expectedReturnType)) {
return false;
}
@@ -5789,6 +5774,25 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
return hasProblem;
}
+ DartType _computeReturnTypeForMethod(Expression returnExpression) {
+ // TODO(paulberry): do the right thing for generators.
+ if (returnExpression == null) {
+ if (_enclosingFunction.isAsynchronous) {
+ return _typeProvider.futureType.substitute4(
+ <DartType>[_typeProvider.nullType]);
+ } else {
+ return VoidTypeImpl.instance;
+ }
+ }
+ DartType staticReturnType = getStaticType(returnExpression);
+ if (staticReturnType != null &&
+ _enclosingFunction.isAsynchronous &&
+ staticReturnType.element != _typeProvider.futureType.element) {
+ return _typeProvider.futureType.substitute4(<DartType>[staticReturnType]);
+ }
+ return staticReturnType;
+ }
+
/**
* Return the error code that should be used when the given class references itself directly.
*

Powered by Google App Engine
This is Rietveld 408576698