From 1c3dd67408df7273d7b71915569ab8a7ef2a67aa Mon Sep 17 00:00:00 2001 From: Sigurd Date: Wed, 23 Sep 2015 13:50:56 +0200 Subject: [PATCH] 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 . --- pkg/compiler/lib/src/typechecker.dart | 2 +- tests/compiler/dart2js/mock_libraries.dart | 5 +++++ tests/compiler/dart2js/type_checker_test.dart | 2 ++ tests/language/async_return_types_test.dart | 19 +++++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/pkg/compiler/lib/src/typechecker.dart b/pkg/compiler/lib/src/typechecker.dart index 323c19db73b..6ca167a27f0 100644 --- a/pkg/compiler/lib/src/typechecker.dart +++ b/pkg/compiler/lib/src/typechecker.dart @@ -1655,7 +1655,7 @@ class TypeCheckerVisitor extends Visitor { 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 diff --git a/tests/compiler/dart2js/mock_libraries.dart b/tests/compiler/dart2js/mock_libraries.dart index 9a87e5fd42f..957cb561942 100644 --- a/tests/compiler/dart2js/mock_libraries.dart +++ b/tests/compiler/dart2js/mock_libraries.dart @@ -410,6 +410,11 @@ const Map DEFAULT_ASYNC_LIBRARY = const { const Map ASYNC_AWAIT_LIBRARY = const { '_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''' diff --git a/tests/compiler/dart2js/type_checker_test.dart b/tests/compiler/dart2js/type_checker_test.dart index 0e6a54ea5b5..fc7b6012739 100644 --- a/tests/compiler/dart2js/type_checker_test.dart +++ b/tests/compiler/dart2js/type_checker_test.dart @@ -2385,6 +2385,8 @@ testAsyncReturn(MockCompiler compiler) { check("int foo() async => 0;", NOT_ASSIGNABLE), check("int foo() async => new Future.value();", NOT_ASSIGNABLE), + check("Iterable foo() sync* { return; }"), + check("Stream foo() async* { return; }"), ]); } diff --git a/tests/language/async_return_types_test.dart b/tests/language/async_return_types_test.dart index 83eb9a8d992..1134e25b003 100644 --- a/tests/language/async_return_types_test.dart +++ b/tests/language/async_return_types_test.dart @@ -40,6 +40,23 @@ foo7() async { return new Future.value(3); } + +Iterable foo8() sync* { + yield 1; + // Can only have valueless return in sync* functions. + return + 8 /// return_value_sync_star: compile-time error + ; +} + +Stream 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() {