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

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

Issue 904743003: Fix analyzer type checking of "await" expressions. (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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/generated/static_type_analyzer.dart
diff --git a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
index 99a51ce11e396ed8769f890b92003b4000a95eaa..7b461df669cdc6f24e8fba46f306926a26b760f5 100644
--- a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
+++ b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
@@ -175,6 +175,34 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
}
/**
+ * The Dart Language Specification, 16.29 (Await Expressions):
+ *
+ * Let flatten(T) = flatten(S) if T = Future<S>, and T otherwise. The
+ * static type of [the expression "await e"] is flatten(T) where T is the
+ * static type of e.
+ */
+ @override
+ Object visitAwaitExpression(AwaitExpression node) {
+ DartType staticExpressionType = _getStaticType(node.expression);
+ if (staticExpressionType == null) {
+ // TODO(brianwilkerson) Determine whether this can still happen.
+ staticExpressionType = _dynamicType;
+ }
+ DartType staticType = flattenFutures(_typeProvider, staticExpressionType);
+ _recordStaticType(node, staticType);
+ DartType propagatedExpressionType = node.expression.propagatedType;
+ if (propagatedExpressionType != null) {
+ DartType propagatedType =
+ flattenFutures(_typeProvider, propagatedExpressionType);
+ if (propagatedType != null &&
+ propagatedType.isMoreSpecificThan(staticType)) {
+ _recordPropagatedType(node, propagatedType);
+ }
+ }
+ return null;
+ }
+
+ /**
* The Dart Language Specification, 12.20: <blockquote>The static type of a logical boolean
* expression is `bool`.</blockquote>
*
@@ -1772,6 +1800,19 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
}
/**
+ * Implements the function "flatten" defined in the spec: "Let flatten(T) =
+ * flatten(S) if T = Future<S>, and T otherwise."
+ */
+ static DartType flattenFutures(TypeProvider typeProvider, DartType type) {
+ if (type is InterfaceType &&
+ type.element == typeProvider.futureType.element &&
+ type.typeArguments.length > 0) {
+ return flattenFutures(typeProvider, type.typeArguments[0]);
+ }
+ return type;
+ }
+
+ /**
* Create a table mapping HTML tag names to the names of the classes (in 'dart:html') that
* implement those tags.
*
« no previous file with comments | « pkg/analyzer/lib/src/generated/error_verifier.dart ('k') | pkg/analyzer/test/generated/non_error_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698