Avoid warning when using return; from sync* and async* functions.
Fixes https://github.com/dart-lang/sdk/issues/24406 R=johnniwinther@google.com Committed: https://github.com/dart-lang/sdk/commit/75f80a204b98ebd65a5da1f2c1db6c6388d67887 Reverted: https://github.com/dart-lang/sdk/commit/8163c4a14199314b6fad626de61d031a35b4d2c1 Review URL: https://codereview.chromium.org//1367433002 .
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user