Skip to content

Commit 34b9ef2

Browse files
committed
dart-lang#1401. Async for-in element tests added
1 parent be5c6fa commit 34b9ef2

15 files changed

+1524
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion It is a compile-time error if an asynchronous for-in element
6+
/// appears inside a synchronous function
7+
///
8+
/// @description Checks that it is a compile-time error if an asynchronous
9+
/// for-in element appears inside a synchronous function. Test a list literal
10+
/// @author [email protected]
11+
/// @issue 52228
12+
13+
// SharedOptions=--enable-experiment=patterns,records
14+
15+
import "patterns_lib.dart";
16+
17+
List<int> test1() {
18+
return [
19+
0,
20+
await for (var (v1 && v2) in Stream.fromIterable([1, 2, 3])) v1 + v2,
21+
// ^^
22+
// [analyzer] unspecified
23+
// [cfe] unspecified
24+
];
25+
}
26+
27+
List<num> test2() {
28+
return [0, await for (final (num v) in Stream.fromIterable([1, 2, 3])) v];
29+
// ^^
30+
// [analyzer] unspecified
31+
// [cfe] unspecified
32+
}
33+
34+
List<int> test3() {
35+
return [0, await for (var (v) in Stream.fromIterable([1, 2, 3])) v];
36+
// ^^
37+
// [analyzer] unspecified
38+
// [cfe] unspecified
39+
}
40+
41+
List<int> test4() {
42+
return [0, await for (final [v] in Stream.fromIterable([[1], [2], [3]])) v];
43+
// ^^
44+
// [analyzer] unspecified
45+
// [cfe] unspecified
46+
}
47+
48+
List<int> test5() {
49+
return [0, await for (var {"k": v} in Stream.fromIterable([{"k": 1}])) v];
50+
// ^^
51+
// [analyzer] unspecified
52+
// [cfe] unspecified
53+
}
54+
55+
List<int> test6() => [
56+
0,
57+
await for (final (v1, n: v2) in Stream.fromIterable([(1, n: 2)])) v1 + v2];
58+
// ^^
59+
// [analyzer] unspecified
60+
// [cfe] unspecified
61+
62+
List<dynamic> test7() => [
63+
0,
64+
await for (var Square(area: v) in Stream.fromIterable([Square(1)])) v];
65+
// ^^
66+
// [analyzer] unspecified
67+
// [cfe] unspecified
68+
69+
main() async {
70+
test1();
71+
test2();
72+
test3();
73+
test4();
74+
test5();
75+
test6();
76+
test7();
77+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion It is a compile-time error if an asynchronous for-in element
6+
/// appears inside a synchronous function
7+
///
8+
/// @description Checks that it is a compile-time error if an asynchronous
9+
/// for-in element appears inside a synchronous function. Test a map literal
10+
/// @author [email protected]
11+
/// @issue 52228
12+
13+
// SharedOptions=--enable-experiment=patterns,records
14+
15+
import "patterns_lib.dart";
16+
17+
Map<String, int> test1() {
18+
return {
19+
"k0": 0,
20+
await for (var (v1 && v2) in Stream.fromIterable([1, 2, 3])) "k$v1": v2,
21+
// ^^
22+
// [analyzer] unspecified
23+
// [cfe] unspecified
24+
};
25+
}
26+
27+
Map<String, num> test2() {
28+
return {"k0": 0, await for (final (num v) in Stream.fromIterable([1, 2, 3])) "k$v": v};
29+
// ^^
30+
// [analyzer] unspecified
31+
// [cfe] unspecified
32+
}
33+
34+
Map<String, int> test3() {
35+
return {"k0": 0, await for (var (v) in Stream.fromIterable([1, 2, 3])) "k$v": v};
36+
// ^^
37+
// [analyzer] unspecified
38+
// [cfe] unspecified
39+
}
40+
41+
Map<String, int> test4() {
42+
return {
43+
"k0": 0,
44+
await for (final [v] in Stream.fromIterable([[1], [2], [3]])) "k$v": v
45+
// ^^
46+
// [analyzer] unspecified
47+
// [cfe] unspecified
48+
};
49+
}
50+
51+
Map<String, int> test5() {
52+
return {
53+
"k0": 0,
54+
await for (var {"k": v} in Stream.fromIterable([{"k": 1}])) "k$v": v
55+
// ^^
56+
// [analyzer] unspecified
57+
// [cfe] unspecified
58+
};
59+
}
60+
61+
Map<String, int> test6() => {
62+
"k0": 0,
63+
await for (final (v1, n: v2) in Stream.fromIterable([(1, n: 2)])) "k$v1": v2
64+
// ^^
65+
// [analyzer] unspecified
66+
// [cfe] unspecified
67+
};
68+
69+
Map<String, dynamic> test7() => {
70+
"k0": 0,
71+
await for (var Square(area: v) in Stream.fromIterable([Square(1)])) "k$v": v
72+
// ^^
73+
// [analyzer] unspecified
74+
// [cfe] unspecified
75+
};
76+
77+
main() async {
78+
test1();
79+
test2();
80+
test3();
81+
test4();
82+
test5();
83+
test6();
84+
test7();
85+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion It is a compile-time error if an asynchronous for-in element
6+
/// appears inside a synchronous function
7+
///
8+
/// @description Checks that it is a compile-time error if an asynchronous
9+
/// for-in element appears inside a synchronous function. Test a set literal
10+
/// @author [email protected]
11+
/// @issue 52228
12+
13+
// SharedOptions=--enable-experiment=patterns,records
14+
15+
import "patterns_lib.dart";
16+
17+
Set<int> test1() {
18+
return {
19+
0,
20+
await for (var (v1 && v2) in Stream.fromIterable([1, 2, 3])) v1 + v2,
21+
// ^^
22+
// [analyzer] unspecified
23+
// [cfe] unspecified
24+
};
25+
}
26+
27+
Set<num> test2() {
28+
return {0, await for (final (num v) in Stream.fromIterable([1, 2, 3])) v};
29+
// ^^
30+
// [analyzer] unspecified
31+
// [cfe] unspecified
32+
}
33+
34+
Set<int> test3() {
35+
return {0, await for (var (v) in Stream.fromIterable([1, 2, 3])) v};
36+
// ^^
37+
// [analyzer] unspecified
38+
// [cfe] unspecified
39+
}
40+
41+
Set<int> test4() {
42+
return {
43+
0,
44+
await for (final [v] in Stream.fromIterable([[1], [2], [3]])) v
45+
// ^^
46+
// [analyzer] unspecified
47+
// [cfe] unspecified
48+
};
49+
}
50+
51+
Set<int> test5() {
52+
return {
53+
0,
54+
await for (var {"k": v} in Stream.fromIterable([{"k": 1}])) v
55+
// ^^
56+
// [analyzer] unspecified
57+
// [cfe] unspecified
58+
};
59+
}
60+
61+
Set<int> test6() => {
62+
0,
63+
await for (final (v1, n: v2) in Stream.fromIterable([(1, n: 2)])) v1 + v2
64+
// ^^
65+
// [analyzer] unspecified
66+
// [cfe] unspecified
67+
};
68+
69+
Set<dynamic> test7() => {
70+
0,
71+
await for (var Square(area: v) in Stream.fromIterable([Square(1)])) v
72+
// ^^
73+
// [analyzer] unspecified
74+
// [cfe] unspecified
75+
};
76+
77+
main() async {
78+
test1();
79+
test2();
80+
test3();
81+
test4();
82+
test5();
83+
test6();
84+
test7();
85+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion It is a compile-time error if an asynchronous for-in element
6+
/// appears inside a synchronous function
7+
///
8+
/// @description Checks that in an async for-in element it is a compile-time
9+
/// error if a <keyword> is empty. Test a list literal
10+
/// @author [email protected]
11+
12+
// SharedOptions=--enable-experiment=patterns,records
13+
14+
import "patterns_lib.dart";
15+
16+
Future<List<int>> test1() async {
17+
var v1 = 0;
18+
var v2 = 0;
19+
return [
20+
0,
21+
await for ((v1 && v2) in Stream.fromIterable([1, 2, 3])) v1 + v2,
22+
// ^
23+
// [analyzer] unspecified
24+
// [cfe] unspecified
25+
];
26+
}
27+
28+
Future<List<int>> test2() async {
29+
var v = 0;
30+
return [0, await for ((v) in Stream.fromIterable([1, 2, 3])) v];
31+
// ^
32+
// [analyzer] unspecified
33+
// [cfe] unspecified
34+
}
35+
36+
Future<List<int>> test3() async {
37+
var v = 0;
38+
return [0, await for ([v] in Stream.fromIterable([[1], [2], [3]])) v];
39+
// ^
40+
// [analyzer] unspecified
41+
// [cfe] unspecified
42+
}
43+
44+
Future<List<int>> test4() async {
45+
var v = 0;
46+
return [0, await for ({"k": v} in Stream.fromIterable([{"k": 1}])) v];
47+
// ^
48+
// [analyzer] unspecified
49+
// [cfe] unspecified
50+
}
51+
52+
Future<List<int>> test5() async {
53+
var v1 = 0;
54+
var v2 = 0;
55+
return [
56+
0,
57+
await for ((v1, n: v2) in Stream.fromIterable([(1, n: 2)])) v1 + v2];
58+
// ^
59+
// [analyzer] unspecified
60+
// [cfe] unspecified
61+
}
62+
63+
Future<List<int>> test6() async {
64+
var v = 0;
65+
return [
66+
0,
67+
await for (Square(area: v) in Stream.fromIterable([Square(1)])) v];
68+
// ^
69+
// [analyzer] unspecified
70+
// [cfe] unspecified
71+
}
72+
73+
main() async {
74+
test1();
75+
test2();
76+
test3();
77+
test4();
78+
test5();
79+
test6();
80+
}

0 commit comments

Comments
 (0)