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

Unified Diff: pkg/analyzer/test/generated/static_type_warning_code_test.dart

Issue 1771153002: Type check for-in statements. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Update to latest on master. Created 4 years, 9 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: pkg/analyzer/test/generated/static_type_warning_code_test.dart
diff --git a/pkg/analyzer/test/generated/static_type_warning_code_test.dart b/pkg/analyzer/test/generated/static_type_warning_code_test.dart
index 137deb568c5f5ebbfad901c3dba35f6892f86d74..2354fb0bb2332a13a6f1fa625085c1823d307fb6 100644
--- a/pkg/analyzer/test/generated/static_type_warning_code_test.dart
+++ b/pkg/analyzer/test/generated/static_type_warning_code_test.dart
@@ -2039,6 +2039,208 @@ f(p) {
verify([source]);
}
+ void test_forIn_notIterable() {
+ assertErrorsInCode('''
+f() {
+ for (var i in true) {}
+}
+''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_TYPE]);
+ }
+
+ void test_forIn_declaredVariableWrongType() {
+ assertErrorsInCode('''
+f() {
+ for (int i in <String>[]) {}
+}
+''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]);
+ }
+
+ void test_forIn_existingVariableWrongType() {
+ assertErrorsInCode('''
+f() {
+ int i;
+ for (i in <String>[]) {}
+}
+''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]);
+ }
+
+ void test_forIn_declaredVariableRightType() {
+ assertNoErrorsInCode('''
+f() {
+ for (int i in <int>[]) {}
+}
+''');
+ }
+
+ void test_forIn_existingVariableRightType() {
+ assertNoErrorsInCode('''
+f() {
+ int i;
+ for (i in <int>[]) {}
+}
+''');
+ }
+
+ void test_forIn_dynamicVariable() {
+ assertNoErrorsInCode('''
+f() {
+ for (var i in <int>[]) {}
+}
+''');
+ }
+
+ void test_forIn_iterableOfDynamic() {
+ assertNoErrorsInCode('''
+f() {
+ for (int i in []) {}
+}
+''');
+ }
+
+ void test_forIn_dynamicIterable() {
+ assertNoErrorsInCode('''
+f() {
+ dynamic iterable;
+ for (int i in iterable) {}
+}
+''');
+ }
+
+ void test_forIn_upcast() {
+ assertNoErrorsInCode('''
+f() {
+ for (num i in <int>[]) {}
+}
+''');
+ }
+
+ void test_forIn_downcast() {
Brian Wilkerson 2016/03/08 01:12:12 Should any of these tests have different behavior
Bob Nystrom 2016/03/08 19:00:50 Right now, I think you'll just get duplicate error
+ assertNoErrorsInCode('''
+f() {
+ for (int i in <num>[]) {}
+}
+''');
+ }
+
+ void test_forIn_typeBoundBad() {
+ assertErrorsInCode('''
+class Foo<T extends Iterable<int>> {
+ void method(T iterable) {
+ for (String i in iterable) {}
+ }
+}
+''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]);
+ }
+
+ void test_forIn_typeBoundGood() {
+ assertNoErrorsInCode('''
+class Foo<T extends Iterable<int>> {
+ void method(T iterable) {
+ for (var i in iterable) {}
+ }
+}
+''');
+ }
+
+ void test_awaitForIn_notStream() {
+ assertErrorsInCode('''
+f() async {
+ await for (var i in true) {}
+}
+''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_TYPE]);
+ }
+
+ void test_awaitForIn_declaredVariableWrongType() {
+ assertErrorsInCode('''
+import 'dart:async';
+f() async {
+ Stream<String> stream;
+ await for (int i in stream) {}
+}
+''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]);
+ }
+
+ void test_awaitForIn_existingVariableWrongType() {
+ assertErrorsInCode('''
+import 'dart:async';
+f() async {
+ Stream<String> stream;
+ int i;
+ await for (i in stream) {}
+}
+''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]);
+ }
+
+ void test_awaitForIn_declaredVariableRightType() {
+ assertNoErrorsInCode('''
+import 'dart:async';
+f() async {
+ Stream<int> stream;
+ await for (int i in stream) {}
+}
+''');
+ }
+
+ void test_awaitForIn_existingVariableRightType() {
+ assertNoErrorsInCode('''
+import 'dart:async';
+f() async {
+ Stream<int> stream;
+ int i;
+ await for (i in stream) {}
+}
+''');
+ }
+
+ void test_awaitForIn_dynamicVariable() {
+ assertNoErrorsInCode('''
+import 'dart:async';
+f() async {
+ Stream<int> stream;
+ await for (var i in stream) {}
+}
+''');
+ }
+
+ void test_awaitForIn_streamOfDynamic() {
+ assertNoErrorsInCode('''
+import 'dart:async';
+f() async {
+ Stream stream;
+ await for (int i in stream) {}
+}
+''');
+ }
+
+ void test_awaitForIn_dynamicStream() {
+ assertNoErrorsInCode('''
+f() async {
+ dynamic stream;
+ await for (int i in stream) {}
+}
+''');
+ }
+
+ void test_awaitForIn_upcast() {
+ assertNoErrorsInCode('''
+import 'dart:async';
+f() async {
+ Stream<int> stream;
+ await for (num i in stream) {}
+}
+''');
+ }
+
+ void test_awaitForIn_downcast() {
+ assertNoErrorsInCode('''
+import 'dart:async';
+f() async {
+ Stream<num> stream;
+ await for (int i in stream) {}
+}
+''');
+ }
+
void test_yield_async_to_basic_type() {
Source source = addSource('''
int f() async* {

Powered by Google App Engine
This is Rietveld 408576698