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

Unified Diff: pkg/compiler/lib/src/ssa/builder.dart

Issue 914143002: Fix checked-mode return for async-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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/dart_types.dart ('k') | tests/language/async_return_types_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/ssa/builder.dart
diff --git a/pkg/compiler/lib/src/ssa/builder.dart b/pkg/compiler/lib/src/ssa/builder.dart
index 13350ca4400098b06c50736383263ede3859390c..4fb64095a492b1fbcaa64e01c6710225388a7873 100644
--- a/pkg/compiler/lib/src/ssa/builder.dart
+++ b/pkg/compiler/lib/src/ssa/builder.dart
@@ -1058,6 +1058,13 @@ class SsaBuilder extends ResolvedVisitor {
// We build the Ssa graph by simulating a stack machine.
List<HInstruction> stack = <HInstruction>[];
+ /// Returns `true` if the current element is an `async` function.
+ bool get isAsync {
floitsch 2015/02/11 15:04:13 This would mean that the "SsaBuilder".isAsync. Ei
sigurdm 2015/02/12 09:36:48 Done.
+ Element element = sourceElement;
+ return (element is FunctionElement &&
+ element.asyncMarker == AsyncMarker.ASYNC);
+ }
+
SsaBuilder(JavaScriptBackend backend,
CodegenWorkItem work,
this.nativeEmitter,
@@ -5179,6 +5186,22 @@ class SsaBuilder extends ResolvedVisitor {
emitReturn(value, node);
}
+ /// Returns `true` if [Future] is a [type].
floitsch 2015/02/11 15:04:13 /// Returns true if the [type] is a valid return t
sigurdm 2015/02/12 09:36:48 Done.
+ bool isValidAsyncReturnType(type) {
floitsch 2015/02/11 15:04:13 Argument type is missing.
sigurdm 2015/02/12 09:36:48 Done.
+ assert (isAsync);
+ // TODO(sigurdm): In an internal library a function could be declared:
+ //
+ // _FutureImpl foo async => 1;
+ //
+ // This should be valid (because the actual value returned from an async
+ // function is a `_FutureImpl`), but currently false is returned in this
+ // case.
+ return type.isDynamic ||
+ type.isObject ||
+ (type is InterfaceType &&
+ type.element == compiler.futureClass);
+ }
+
visitReturn(ast.Return node) {
if (identical(node.beginToken.stringValue, 'native')) {
native.handleSsaNative(this, node.expression);
@@ -5190,7 +5213,19 @@ class SsaBuilder extends ResolvedVisitor {
} else {
visit(node.expression);
value = pop();
- value = potentiallyCheckOrTrustType(value, returnType);
+ if (isAsync) {
+ if (compiler.enableTypeAssertions &&
+ !isValidAsyncReturnType(returnType)) {
+ String message =
+ "Async function returned a Future, "
+ "was declared to return a $returnType.";
+ generateTypeError(node, message);
+ pop();
+ return;
+ }
+ } else {
+ value = potentiallyCheckOrTrustType(value, returnType);
+ }
}
handleInTryStatement();
« no previous file with comments | « pkg/compiler/lib/src/dart_types.dart ('k') | tests/language/async_return_types_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698