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

Unified Diff: sdk/lib/_internal/compiler/implementation/typechecker.dart

Issue 675113002: Support async/await in the dart2js frontend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments Created 6 years, 1 month 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: sdk/lib/_internal/compiler/implementation/typechecker.dart
diff --git a/sdk/lib/_internal/compiler/implementation/typechecker.dart b/sdk/lib/_internal/compiler/implementation/typechecker.dart
index 7cef548d1372a830edae7f73de93caa0b08e48b9..b1fb8cd434fc7613472b666e0482a5b58f8e88e3 100644
--- a/sdk/lib/_internal/compiler/implementation/typechecker.dart
+++ b/sdk/lib/_internal/compiler/implementation/typechecker.dart
@@ -250,6 +250,7 @@ class TypeCheckerVisitor extends Visitor<DartType> {
Node lastSeenNode;
DartType expectedReturnType;
+ AsyncMarker currentAsyncMarker = AsyncMarker.SYNC;
final ClassElement currentClass;
@@ -604,10 +605,13 @@ class TypeCheckerVisitor extends Visitor<DartType> {
returnType = functionType.returnType;
type = functionType;
}
- DartType previous = expectedReturnType;
+ DartType previousReturnType = expectedReturnType;
expectedReturnType = returnType;
+ AsyncMarker previousAsyncMarker = currentAsyncMarker;
+ currentAsyncMarker = element.asyncMarker;
analyze(node.body);
- expectedReturnType = previous;
+ expectedReturnType = previousReturnType;
+ currentAsyncMarker = previousAsyncMarker;
return type;
}
@@ -1589,6 +1593,36 @@ class TypeCheckerVisitor extends Visitor<DartType> {
return const DynamicType();
}
+ DartType visitAwait(Await node) {
+ DartType expressionType = analyze(node.expression);
+ DartType resultType = expressionType;
+ if (expressionType is InterfaceType) {
+ InterfaceType futureType =
+ expressionType.asInstanceOf(compiler.futureClass);
+ if (futureType != null) {
+ resultType = futureType.typeArguments.first;
+ }
+ }
+ return resultType;
+ }
+
+ DartType visitYield(Yield node) {
+ DartType resultType = analyze(node.expression);
+ if (!node.hasStar) {
+ if (currentAsyncMarker.isAsync) {
+ resultType =
+ compiler.streamClass.thisType.createInstantiation(
+ <DartType>[resultType]);
+ } else {
+ resultType =
+ compiler.iterableClass.thisType.createInstantiation(
+ <DartType>[resultType]);
+ }
+ }
+ checkAssignable(node, resultType, expectedReturnType);
+ return const StatementType();
+ }
+
DartType visitTypeAnnotation(TypeAnnotation node) {
return elements.getType(node);
}

Powered by Google App Engine
This is Rietveld 408576698