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

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

Issue 1338803002: Type check await for. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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 | « pkg/compiler/lib/src/typechecker.dart ('k') | no next file » | 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 61955d443ea1e89edff531993e03abcb9fe1a8fd..0e6a54ea5b583fddaa7ee9249fdda9b81409c231 100644
--- a/tests/compiler/dart2js/type_checker_test.dart
+++ b/tests/compiler/dart2js/type_checker_test.dart
@@ -35,6 +35,7 @@ main() {
testReturn,
testFor,
testSyncForIn,
+ testAsyncForIn,
testWhile,
testTry,
testSwitch,
@@ -284,6 +285,144 @@ class Class {
}""", hints: MessageKind.FORIN_NOT_ASSIGNABLE);
}
+testAsyncForIn(MockCompiler compiler) {
+ String script = """
+abstract class CustomStream<T> implements Stream<T> {}
+abstract class StringStream implements Stream<String> {}
+
+var topLevelDyn;
+String topLevelString;
+int topLevelInt;
+
+class Class {
+ void forIn() async {}
+
+ var instanceDyn;
+ String instanceString;
+ int instanceInt;
+
+ static var staticDyn;
+ static String staticString;
+ static int staticInt;
+}
+""";
+ compiler.parseScript(script);
+ ClassElement foo = compiler.mainApp.find("Class");
+ foo.ensureResolved(compiler);
+ FunctionElement method = foo.lookupLocalMember('forIn');
+
+ analyzeIn(compiler, method, """{
+ var stream;
+ await for (var e in stream) {}
+ }""");
+ analyzeIn(compiler, method, """{
+ var stream;
+ await for (String e in stream) {}
+ }""");
+ analyzeIn(compiler, method, """{
+ var stream;
+ await for (int e in stream) {}
+ }""");
+
+ analyzeIn(compiler, method, """{
+ await for (var e in []) {}
+ }""", hints: MessageKind.NOT_ASSIGNABLE);
+
+ analyzeIn(compiler, method, """{
+ Stream<String> stream;
+ await for (var e in stream) {}
+ }""");
+ analyzeIn(compiler, method, """{
+ Stream<String> stream;
+ await for (String e in stream) {}
+ }""");
+ analyzeIn(compiler, method, """{
+ Stream<String> stream;
+ await for (int e in stream) {}
+ }""", hints: MessageKind.FORIN_NOT_ASSIGNABLE);
+
+ analyzeIn(compiler, method, """{
+ CustomStream<String> stream;
+ await for (var e in stream) {}
+ }""");
+ analyzeIn(compiler, method, """{
+ CustomStream<String> stream;
+ await for (String e in stream) {}
+ }""");
+ analyzeIn(compiler, method, """{
+ CustomStream<String> stream;
+ await for (int e in stream) {}
+ }""", hints: MessageKind.FORIN_NOT_ASSIGNABLE);
+
+ analyzeIn(compiler, method, """{
+ StringStream stream;
+ await for (var e in stream) {}
+ }""");
+ analyzeIn(compiler, method, """{
+ StringStream stream;
+ await for (String e in stream) {}
+ }""");
+ analyzeIn(compiler, method, """{
+ StringStream stream;
+ await for (int e in stream) {}
+ }""", hints: MessageKind.FORIN_NOT_ASSIGNABLE);
+
+ analyzeIn(compiler, method, """{
+ Stream<String> stream;
+ var localDyn;
+ await for (localDyn in stream) {}
+ }""");
+ analyzeIn(compiler, method, """{
+ Stream<String> stream;
+ String localString;
+ await for (localString in stream) {}
+ }""");
+ analyzeIn(compiler, method, """{
+ Stream<String> stream;
+ int localInt;
+ await for (localInt in stream) {}
+ }""", hints: MessageKind.FORIN_NOT_ASSIGNABLE);
+
+ analyzeIn(compiler, method, """{
+ Stream<String> stream;
+ await for (topLevelDyn in stream) {}
+ }""");
+ analyzeIn(compiler, method, """{
+ Stream<String> stream;
+ await for (topLevelString in stream) {}
+ }""");
+ analyzeIn(compiler, method, """{
+ Stream<String> stream;
+ await for (topLevelInt in stream) {}
+ }""", hints: MessageKind.FORIN_NOT_ASSIGNABLE);
+
+ analyzeIn(compiler, method, """{
+ Stream<String> stream;
+ await for (instanceDyn in stream) {}
+ }""");
+ analyzeIn(compiler, method, """{
+ Stream<String> stream;
+ await for (instanceString in stream) {}
+ }""");
+ analyzeIn(compiler, method, """{
+ Stream<String> stream;
+ await for (instanceInt in stream) {}
+ }""", hints: MessageKind.FORIN_NOT_ASSIGNABLE);
+
+ analyzeIn(compiler, method, """{
+ Stream<String> stream;
+ await for (staticDyn in stream) {}
+ }""");
+ analyzeIn(compiler, method, """{
+ Stream<String> stream;
+ await for (staticString in stream) {}
+ }""");
+ analyzeIn(compiler, method, """{
+ Stream<String> stream;
+ await for (staticInt in stream) {}
+ }""", hints: MessageKind.FORIN_NOT_ASSIGNABLE);
+}
+
testWhile(MockCompiler compiler) {
check(String code, {warnings}) {
« no previous file with comments | « pkg/compiler/lib/src/typechecker.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698