-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
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 <eernst@google.com> Reviewed-by: Leaf Petersen <leafp@google.com>
- Loading branch information
Showing
75 changed files
with
3,528 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
tests/language/invalid_returns/async_invalid_return_00_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2018, 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. | ||
|
||
import 'dart:async'; | ||
|
||
/* `return;` is an error if the future value type of the function is not | ||
* `void`, `dynamic`, or `Null`. | ||
*/ | ||
|
||
Object test1() async { | ||
return; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
Object? test2() async { | ||
return; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
Object Function() test3 = () async { | ||
return; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
|
||
Object? Function() test4 = () async { | ||
return; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
|
||
void main() { | ||
test1(); | ||
test2(); | ||
test3(); | ||
test4(); | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/language/invalid_returns/async_invalid_return_01_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2018, 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. | ||
|
||
import 'dart:async'; | ||
|
||
/* `return;` is an error if the future value type of the function is not | ||
* `void`, `dynamic`, or `Null`. | ||
*/ | ||
|
||
Future<int> test1() async { | ||
return; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
Future<int> Function() test2 = () async { | ||
return; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
|
||
void main() { | ||
test1(); | ||
test2(); | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/language/invalid_returns/async_invalid_return_02_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2018, 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. | ||
|
||
import 'dart:async'; | ||
|
||
/* `return;` is an error if the future value type of the function is not | ||
* `void`, `dynamic`, or `Null`. | ||
*/ | ||
|
||
FutureOr<int> test1() async { | ||
return; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
FutureOr<int> Function() test2 = () async { | ||
return; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
|
||
void main() { | ||
test1(); | ||
test2(); | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/language/invalid_returns/async_invalid_return_03_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2018, 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. | ||
|
||
import 'dart:async'; | ||
|
||
/* `return;` is an error if the future value type of the function is not | ||
* `void`, `dynamic`, or `Null`. | ||
*/ | ||
|
||
Future<Object?> test1() async { | ||
return; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
Future<Object?> Function() test2 = () async { | ||
return; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
|
||
void main() { | ||
test1(); | ||
test2(); | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/language/invalid_returns/async_invalid_return_04_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2018, 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. | ||
|
||
import 'dart:async'; | ||
|
||
/* `return;` is an error if the future value type of the function is not | ||
* `void`, `dynamic`, or `Null`. | ||
*/ | ||
|
||
FutureOr<Object?> test1() async { | ||
return; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
FutureOr<Object?> Function() test2 = () async { | ||
return; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
|
||
void main() { | ||
test1(); | ||
test2(); | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/language/invalid_returns/async_invalid_return_05_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) 2018, 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. | ||
|
||
import 'dart:async'; | ||
|
||
/* `return exp;` where `exp` has static type `S` is an error if the future | ||
* value type of the function is `void` and `flatten(S)` is not | ||
* `void`, `dynamic`, `Null`, `void*`, `dynamic*`, or `Null*`. | ||
*/ | ||
|
||
int v = 0; | ||
|
||
void test1() async { | ||
return v; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
void Function() test2 = () async { | ||
return v; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
|
||
void main() { | ||
test1(); | ||
test2(); | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/language/invalid_returns/async_invalid_return_08_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) 2018, 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. | ||
|
||
import 'dart:async'; | ||
|
||
/* `return exp;` where `exp` has static type `S` is an error if the future | ||
* value type of the function is `void` and `flatten(S)` is not | ||
* `void`, `dynamic`, `Null`, `void*`, `dynamic*`, or `Null*`. | ||
*/ | ||
|
||
Object v = false; | ||
|
||
void test1() async { | ||
return v; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
void Function() test2 = () async { | ||
return v; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
|
||
void main() { | ||
test1(); | ||
test2(); | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/language/invalid_returns/async_invalid_return_11_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) 2018, 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. | ||
|
||
import 'dart:async'; | ||
|
||
/* `return exp;` where `exp` has static type `S` is an error if the future | ||
* value type of the function is `void` and `flatten(S)` is not | ||
* `void`, `dynamic`, `Null`, `void*`, `dynamic*`, or `Null*`. | ||
*/ | ||
|
||
Future<int>? v = null; | ||
|
||
void test1() async { | ||
return v; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
void Function() test2 = () async { | ||
return v; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
|
||
void main() { | ||
test1(); | ||
test2(); | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/language/invalid_returns/async_invalid_return_14_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) 2018, 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. | ||
|
||
import 'dart:async'; | ||
|
||
/* `return exp;` where `exp` has static type `S` is an error if the future | ||
* value type of the function is `void` and `flatten(S)` is not | ||
* `void`, `dynamic`, `Null`, `void*`, `dynamic*`, or `Null*`. | ||
*/ | ||
|
||
FutureOr<int> v = 0; | ||
|
||
void test1() async { | ||
return v; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
void Function() test2 = () async { | ||
return v; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
|
||
void main() { | ||
test1(); | ||
test2(); | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/language/invalid_returns/async_invalid_return_17_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) 2018, 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. | ||
|
||
import 'dart:async'; | ||
|
||
/* `return exp;` where `exp` has static type `S` is an error if the future | ||
* value type of the function is `void` and `flatten(S)` is not | ||
* `void`, `dynamic`, `Null`, `void*`, `dynamic*`, or `Null*`. | ||
*/ | ||
|
||
Future<Object> v = Future.value(Object()); | ||
|
||
void test1() async { | ||
return v; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
void Function() test2 = () async { | ||
return v; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
|
||
void main() { | ||
test1(); | ||
test2(); | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/language/invalid_returns/async_invalid_return_20_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) 2018, 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. | ||
|
||
import 'dart:async'; | ||
|
||
/* `return exp;` where `exp` has static type `S` is an error if the future | ||
* value type of the function is `void` and `flatten(S)` is not | ||
* `void`, `dynamic`, `Null`, `void*`, `dynamic*`, or `Null*`. | ||
*/ | ||
|
||
FutureOr<Object> v = true; | ||
|
||
void test1() async { | ||
return v; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
void Function() test2 = () async { | ||
return v; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
|
||
void main() { | ||
test1(); | ||
test2(); | ||
} |
Oops, something went wrong.