Chromium Code Reviews| 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(); |