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

Unified Diff: pkg/front_end/testcases/inference/infer_types_on_loop_indices_for_each_loop.dart

Issue 2846103002: Generated front_end/testcases/inference test files from Analyzer tests. (Closed)
Patch Set: Created 3 years, 8 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/front_end/testcases/inference/infer_types_on_loop_indices_for_each_loop.dart
diff --git a/pkg/front_end/testcases/inference/infer_types_on_loop_indices_for_each_loop.dart b/pkg/front_end/testcases/inference/infer_types_on_loop_indices_for_each_loop.dart
new file mode 100644
index 0000000000000000000000000000000000000000..483aaa1f14d19147d206780d513953d0a73b2acf
--- /dev/null
+++ b/pkg/front_end/testcases/inference/infer_types_on_loop_indices_for_each_loop.dart
@@ -0,0 +1,73 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/*@testedFeatures=inference*/
+library test;
+
+class Foo {
+ int bar = 42;
+}
+
+class Bar<T extends Iterable<String>> {
+ void foo(T t) {
+ for (var /*@promotedType=none*/ i in t) {
+ int x = /*error:INVALID_ASSIGNMENT*/ /*@promotedType=none*/ i;
+ }
+ }
+}
+
+class Baz<T, E extends Iterable<T>, S extends E> {
+ void foo(S t) {
+ for (var /*@promotedType=none*/ i in t) {
+ int x = /*error:INVALID_ASSIGNMENT*/ /*@promotedType=none*/ i;
+ T y = /*@promotedType=none*/ i;
+ }
+ }
+}
+
+test() {
+ var /*@type=List<Foo>*/ list = <Foo>[];
+ for (var /*@promotedType=none*/ x in /*@promotedType=none*/ list) {
+ String y = /*error:INVALID_ASSIGNMENT*/ /*@promotedType=none*/ x;
+ }
+
+ for (dynamic /*@promotedType=none*/ x in /*@promotedType=none*/ list) {
+ String y = /*info:DYNAMIC_CAST*/ /*@promotedType=none*/ x;
+ }
+
+ for (String /*@promotedType=none*/ x
+ in /*error:FOR_IN_OF_INVALID_ELEMENT_TYPE*/ /*@promotedType=none*/ list) {
+ String y = /*@promotedType=none*/ x;
+ }
+
+ var /*@type=dynamic*/ z;
+ for (z in /*@promotedType=none*/ list) {
+ String y = /*info:DYNAMIC_CAST*/ /*@promotedType=none*/ z;
+ }
+
+ Iterable iter = /*@promotedType=none*/ list;
+ for (Foo /*info:DYNAMIC_CAST*/ /*@promotedType=none*/ x
+ in /*@promotedType=none*/ iter) {
+ var /*@type=Foo*/ y = /*@promotedType=none*/ x;
+ }
+
+ dynamic iter2 = /*@promotedType=none*/ list;
+ for (Foo /*info:DYNAMIC_CAST*/ /*@promotedType=none*/ x
+ in /*info:DYNAMIC_CAST*/ /*@promotedType=none*/ iter2) {
+ var /*@type=Foo*/ y = /*@promotedType=none*/ x;
+ }
+
+ var /*@type=Map<String, Foo>*/ map = <String, Foo>{};
+ // Error: map must be an Iterable.
+ for (var /*@promotedType=none*/ x
+ in /*error:FOR_IN_OF_INVALID_TYPE*/ /*@promotedType=none*/ map) {
+ String y = /*info:DYNAMIC_CAST*/ /*@promotedType=none*/ x;
+ }
+
+ // We're not properly inferring that map.keys is an Iterable<String>
+ // and that x is a String.
+ for (var /*@promotedType=none*/ x in /*@promotedType=none*/ map.keys) {
+ String y = /*@promotedType=none*/ x;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698