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

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: Updated and tested. 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
« no previous file with comments | « tests/compiler/dart2js/mock_libraries.dart ('k') | tests/language/language_dart2js.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..1d717e53ce2520e831afdeabb340b267e8337395 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,50 @@ 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),
+
+ check("Future<int> foo() async => null;"),
+ check("Future<int> foo() async => 0;"),
+ check("Future<int> foo() async => '';", NOT_ASSIGNABLE),
+ check("Future<int> foo() async => new Future.value();"),
+ check("Future<int> foo() async => new Future<int>.value();"),
+ check("Future<int> foo() async => new Future<String>.value();",
+ NOT_ASSIGNABLE),
+ check("""
+ Future<int> foo() async => new Future<Future<int>>.value();
+ """),
+ check("void foo() async => 0;", MessageKind.RETURN_VALUE_IN_VOID),
+ check("void foo() async => new Future.value();",
+ MessageKind.RETURN_VALUE_IN_VOID),
+ check("int foo() async => 0;", NOT_ASSIGNABLE),
+ check("int foo() async => new Future<int>.value();",
+ NOT_ASSIGNABLE),
+ ]);
+}
+
const CLASS_WITH_METHODS = '''
typedef int String2Int(String s);
@@ -2131,7 +2176,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 =
« no previous file with comments | « tests/compiler/dart2js/mock_libraries.dart ('k') | tests/language/language_dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698