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

Unified Diff: tests/compiler/dart2js/type_checker_test.dart

Issue 962603002: Typecheck return with respect to async. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Allow return; in generators. 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
Index: tests/compiler/dart2js/type_checker_test.dart
diff --git a/tests/compiler/dart2js/type_checker_test.dart b/tests/compiler/dart2js/type_checker_test.dart
index adf75131ee0df80e659b329dbaf8427dd801ea1d..e82dd8bc3f2c06286b512311450578706b4fc50c 100644
--- a/tests/compiler/dart2js/type_checker_test.dart
+++ b/tests/compiler/dart2js/type_checker_test.dart
@@ -55,7 +55,8 @@ main() {
testTypePromotionHints,
testFunctionCall,
testCascade,
- testAwait];
+ testAwait,
+ testAsyncReturn];
asyncTest(() => Future.forEach(tests, (test) => setup(test)));
}
@@ -2032,6 +2033,33 @@ testAwait(MockCompiler compiler) {
NOT_ASSIGNABLE);
}
+testAsyncReturn(MockCompiler compiler) {
+ Future check(String code, [expectedWarnings]) {
+ return analyzeTopLevel(code, expectedWarnings);
+ }
+ return Future.wait([
+ check("Future<int> foo() async { return; }", MessageKind.RETURN_NOTHING),
+ check("Future<int> foo() async { return null; }"),
+ check("Future<int> foo() async { return 0; }"),
+ check("Future<int> foo() async { return ''; }", NOT_ASSIGNABLE),
+ check("Future<int> foo() async { return new Future.value(); }"),
+ check("Future<int> foo() async { return new Future<int>.value(); }"),
+ check("Future<int> foo() async { return new Future<String>.value(); }",
+ NOT_ASSIGNABLE),
+ check("""
+ Future<int> foo() async { return new Future<Future<int>>.value(); }
+ """),
+ check("void foo() async { return; }"),
+ check("void foo() async { return 0; }", MessageKind.RETURN_VALUE_IN_VOID),
+ check("void foo() async { return new Future.value(); }",
+ MessageKind.RETURN_VALUE_IN_VOID),
+ check("int foo() async { return; }", MessageKind.RETURN_NOTHING),
+ check("int foo() async { return 0; }", NOT_ASSIGNABLE),
+ check("int foo() async { return new Future<int>.value(); }",
+ NOT_ASSIGNABLE),
+ ]);
+}
+
const CLASS_WITH_METHODS = '''
typedef int String2Int(String s);
@@ -2131,7 +2159,7 @@ analyzeTopLevel(String text, [expectedWarnings]) {
MockCompiler compiler = new MockCompiler.internal();
compiler.diagnosticHandler = createHandler(compiler, text);
- return compiler.init().then((_) {
+ return compiler.init("import 'dart:async';").then((_) {
LibraryElement library = compiler.mainApp;
Link<Element> topLevelElements =
« pkg/compiler/lib/src/typechecker.dart ('K') | « tests/compiler/dart2js/mock_libraries.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698