Skip to content

Commit 2cc46ea

Browse files
eernstgcommit-bot@chromium.org
authored andcommitted
Adjust tests for new return rules, cf. language PR #941, #948.
The rules for returns with null-safety were changed in language PR #941, and this PR makes changes to async/return_types_test.dart such that it matches the new rules. Check base vs. patchset 1 to see these adjustments. The main part of this PR is that it migrates and updates the tests language/invalid_returns/{,a}sync_{,in}valid*_test.dart such that they match the new rules. Check patchset 1 vs newest patchset to see this migration. Note that some tests are new, e.g., 'sync_invalid_return_27_test', which was added because it is a new property that there is an error for "return void to Null". Also note that some of the tests are redundant: (1) It is no longer allowed to return void to Null, but (2) that's an error already with null-safety, because it's a downcast (so it doesn't matter which supertype of `Null` we have). I kept these tests anyway (and even wrote this new one), because they do check that certain changes have been implemented, even though it is in some cases redundant in the sense that it's just another verification that implicit downcasts aren't supported any more. If we don't want this redundancy then we should remove about 10 tests (sync_invalid_return, async_invalid_return). Change-Id: I3f10682e1d0ed75067d6e8651588b727ffd3648f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145587 Commit-Queue: Erik Ernst <[email protected]> Reviewed-by: Leaf Petersen <[email protected]>
1 parent d0d0952 commit 2cc46ea

File tree

75 files changed

+3528
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+3528
-10
lines changed

tests/language/async/return_types_test.dart

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,14 @@ Future<int, String>
2727
// [analyzer] STATIC_TYPE_WARNING.WRONG_NUMBER_OF_TYPE_ARGUMENTS
2828
// [cfe] Expected 1 type arguments.
2929
foo4() async {
30-
// [error line 29, column 1]
31-
// [cfe] Functions marked 'async' must have a return type assignable to 'Future'.
3230
return "String";
33-
// ^
34-
// [cfe] A value of type 'String' can't be assigned to a variable of type 'FutureOr<invalid-type>'.
3531
}
3632

3733
int
38-
// [error line 37, column 1, length 3]
34+
// [error line 33, column 1, length 3]
3935
// [analyzer] STATIC_TYPE_WARNING.ILLEGAL_ASYNC_RETURN_TYPE
4036
foo5() async {
41-
// [error line 40, column 1]
37+
// [error line 36, column 1, length 3]
4238
// [cfe] Functions marked 'async' must have a return type assignable to 'Future'.
4339
return 3;
4440
}
@@ -48,11 +44,9 @@ Future<int> foo6() async {
4844
return new Future<int>.value(3);
4945
}
5046

51-
Future<Future<int>>
52-
foo7() async {
47+
Future<Future<int>> foo7() async {
48+
// This is fine, the future is used to complete the returned future.
5349
return new Future<int>.value(3);
54-
// ^^^^^^^^^^^^^^^^^^^^^^^^
55-
// [analyzer] STATIC_TYPE_WARNING.RETURN_OF_INVALID_TYPE
5650
}
5751

5852
Iterable<int> foo8() sync* {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) 2018, 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+
import 'dart:async';
6+
7+
/* `return;` is an error if the future value type of the function is not
8+
* `void`, `dynamic`, or `Null`.
9+
*/
10+
11+
Object test1() async {
12+
return;
13+
//^
14+
// [analyzer] unspecified
15+
// [cfe] unspecified
16+
}
17+
18+
Object? test2() async {
19+
return;
20+
//^
21+
// [analyzer] unspecified
22+
// [cfe] unspecified
23+
}
24+
25+
Object Function() test3 = () async {
26+
return;
27+
//^
28+
// [analyzer] unspecified
29+
// [cfe] unspecified
30+
};
31+
32+
Object? Function() test4 = () async {
33+
return;
34+
//^
35+
// [analyzer] unspecified
36+
// [cfe] unspecified
37+
};
38+
39+
void main() {
40+
test1();
41+
test2();
42+
test3();
43+
test4();
44+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2018, 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+
import 'dart:async';
6+
7+
/* `return;` is an error if the future value type of the function is not
8+
* `void`, `dynamic`, or `Null`.
9+
*/
10+
11+
Future<int> test1() async {
12+
return;
13+
//^
14+
// [analyzer] unspecified
15+
// [cfe] unspecified
16+
}
17+
18+
Future<int> Function() test2 = () async {
19+
return;
20+
//^
21+
// [analyzer] unspecified
22+
// [cfe] unspecified
23+
};
24+
25+
void main() {
26+
test1();
27+
test2();
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2018, 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+
import 'dart:async';
6+
7+
/* `return;` is an error if the future value type of the function is not
8+
* `void`, `dynamic`, or `Null`.
9+
*/
10+
11+
FutureOr<int> test1() async {
12+
return;
13+
//^
14+
// [analyzer] unspecified
15+
// [cfe] unspecified
16+
}
17+
18+
FutureOr<int> Function() test2 = () async {
19+
return;
20+
//^
21+
// [analyzer] unspecified
22+
// [cfe] unspecified
23+
};
24+
25+
void main() {
26+
test1();
27+
test2();
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2018, 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+
import 'dart:async';
6+
7+
/* `return;` is an error if the future value type of the function is not
8+
* `void`, `dynamic`, or `Null`.
9+
*/
10+
11+
Future<Object?> test1() async {
12+
return;
13+
//^
14+
// [analyzer] unspecified
15+
// [cfe] unspecified
16+
}
17+
18+
Future<Object?> Function() test2 = () async {
19+
return;
20+
//^
21+
// [analyzer] unspecified
22+
// [cfe] unspecified
23+
};
24+
25+
void main() {
26+
test1();
27+
test2();
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2018, 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+
import 'dart:async';
6+
7+
/* `return;` is an error if the future value type of the function is not
8+
* `void`, `dynamic`, or `Null`.
9+
*/
10+
11+
FutureOr<Object?> test1() async {
12+
return;
13+
//^
14+
// [analyzer] unspecified
15+
// [cfe] unspecified
16+
}
17+
18+
FutureOr<Object?> Function() test2 = () async {
19+
return;
20+
//^
21+
// [analyzer] unspecified
22+
// [cfe] unspecified
23+
};
24+
25+
void main() {
26+
test1();
27+
test2();
28+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2018, 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+
import 'dart:async';
6+
7+
/* `return exp;` where `exp` has static type `S` is an error if the future
8+
* value type of the function is `void` and `flatten(S)` is not
9+
* `void`, `dynamic`, `Null`, `void*`, `dynamic*`, or `Null*`.
10+
*/
11+
12+
int v = 0;
13+
14+
void test1() async {
15+
return v;
16+
// ^
17+
// [analyzer] unspecified
18+
// [cfe] unspecified
19+
}
20+
21+
void Function() test2 = () async {
22+
return v;
23+
// ^
24+
// [analyzer] unspecified
25+
// [cfe] unspecified
26+
};
27+
28+
void main() {
29+
test1();
30+
test2();
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2018, 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+
import 'dart:async';
6+
7+
/* `return exp;` where `exp` has static type `S` is an error if the future
8+
* value type of the function is `void` and `flatten(S)` is not
9+
* `void`, `dynamic`, `Null`, `void*`, `dynamic*`, or `Null*`.
10+
*/
11+
12+
Object v = false;
13+
14+
void test1() async {
15+
return v;
16+
// ^
17+
// [analyzer] unspecified
18+
// [cfe] unspecified
19+
}
20+
21+
void Function() test2 = () async {
22+
return v;
23+
// ^
24+
// [analyzer] unspecified
25+
// [cfe] unspecified
26+
};
27+
28+
void main() {
29+
test1();
30+
test2();
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2018, 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+
import 'dart:async';
6+
7+
/* `return exp;` where `exp` has static type `S` is an error if the future
8+
* value type of the function is `void` and `flatten(S)` is not
9+
* `void`, `dynamic`, `Null`, `void*`, `dynamic*`, or `Null*`.
10+
*/
11+
12+
Future<int>? v = null;
13+
14+
void test1() async {
15+
return v;
16+
// ^
17+
// [analyzer] unspecified
18+
// [cfe] unspecified
19+
}
20+
21+
void Function() test2 = () async {
22+
return v;
23+
// ^
24+
// [analyzer] unspecified
25+
// [cfe] unspecified
26+
};
27+
28+
void main() {
29+
test1();
30+
test2();
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2018, 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+
import 'dart:async';
6+
7+
/* `return exp;` where `exp` has static type `S` is an error if the future
8+
* value type of the function is `void` and `flatten(S)` is not
9+
* `void`, `dynamic`, `Null`, `void*`, `dynamic*`, or `Null*`.
10+
*/
11+
12+
FutureOr<int> v = 0;
13+
14+
void test1() async {
15+
return v;
16+
// ^
17+
// [analyzer] unspecified
18+
// [cfe] unspecified
19+
}
20+
21+
void Function() test2 = () async {
22+
return v;
23+
// ^
24+
// [analyzer] unspecified
25+
// [cfe] unspecified
26+
};
27+
28+
void main() {
29+
test1();
30+
test2();
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2018, 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+
import 'dart:async';
6+
7+
/* `return exp;` where `exp` has static type `S` is an error if the future
8+
* value type of the function is `void` and `flatten(S)` is not
9+
* `void`, `dynamic`, `Null`, `void*`, `dynamic*`, or `Null*`.
10+
*/
11+
12+
Future<Object> v = Future.value(Object());
13+
14+
void test1() async {
15+
return v;
16+
// ^
17+
// [analyzer] unspecified
18+
// [cfe] unspecified
19+
}
20+
21+
void Function() test2 = () async {
22+
return v;
23+
// ^
24+
// [analyzer] unspecified
25+
// [cfe] unspecified
26+
};
27+
28+
void main() {
29+
test1();
30+
test2();
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2018, 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+
import 'dart:async';
6+
7+
/* `return exp;` where `exp` has static type `S` is an error if the future
8+
* value type of the function is `void` and `flatten(S)` is not
9+
* `void`, `dynamic`, `Null`, `void*`, `dynamic*`, or `Null*`.
10+
*/
11+
12+
FutureOr<Object> v = true;
13+
14+
void test1() async {
15+
return v;
16+
// ^
17+
// [analyzer] unspecified
18+
// [cfe] unspecified
19+
}
20+
21+
void Function() test2 = () async {
22+
return v;
23+
// ^
24+
// [analyzer] unspecified
25+
// [cfe] unspecified
26+
};
27+
28+
void main() {
29+
test1();
30+
test2();
31+
}

0 commit comments

Comments
 (0)