Sigurd
2015-09-23 13:50:56 +02:00
parent 8163c4a141
commit 1c3dd67408
4 changed files with 27 additions and 1 deletions
+1 -1
View File
@@ -1655,7 +1655,7 @@ class TypeCheckerVisitor extends Visitor<DartType> {
checkAssignable(expression, expressionType, expectedReturnType);
}
}
} else if (currentAsyncMarker == AsyncMarker.ASYNC) {
} else if (currentAsyncMarker != AsyncMarker.SYNC) {
// `return;` is allowed.
} else if (!types.isAssignable(expectedReturnType, const VoidType())) {
// Let f be the function immediately enclosing a return statement of the
@@ -410,6 +410,11 @@ const Map<String, String> DEFAULT_ASYNC_LIBRARY = const <String, String>{
const Map<String, String> ASYNC_AWAIT_LIBRARY = const <String, String>{
'_wrapJsFunctionForAsync': '_wrapJsFunctionForAsync(f) {}',
'_asyncHelper': '_asyncHelper(o, f, c) {}',
'_SyncStarIterable': 'class _SyncStarIterable {}',
'_IterationMarker': 'class _IterationMarker {}',
'_AsyncStarStreamController': 'class _AsyncStarStreamController {}',
'_asyncStarHelper': '_asyncStarHelper(x, y, z) {}',
'_streamOfController': '_streamOfController(x) {}',
};
const String DEFAULT_MIRRORS_SOURCE = r'''
@@ -2385,6 +2385,8 @@ testAsyncReturn(MockCompiler compiler) {
check("int foo() async => 0;", NOT_ASSIGNABLE),
check("int foo() async => new Future<int>.value();",
NOT_ASSIGNABLE),
check("Iterable<int> foo() sync* { return; }"),
check("Stream<int> foo() async* { return; }"),
]);
}
@@ -40,6 +40,23 @@ foo7() async {
return new Future<int>.value(3);
}
Iterable<int> foo8() sync* {
yield 1;
// Can only have valueless return in sync* functions.
return
8 /// return_value_sync_star: compile-time error
;
}
Stream<int> foo9() async* {
yield 1;
// Can only have valueless return in async* functions.
return
8 /// return_value_sync_star: compile-time error
;
}
test() async {
Expect.equals(3, await foo1());
Expect.equals(3, await foo2());
@@ -48,6 +65,8 @@ test() async {
Expect.equals(3, await foo5());
Expect.equals(3, await await foo6());
Expect.equals(3, await await foo7());
Expect.listEquals([1], foo8().toList());
Expect.listEquals([1], await foo9().toList());
}
main() {