Skip to content

Commit

Permalink
Adjust tests for new return rules, cf. language PR #941, #948.
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
eernstg authored and commit-bot@chromium.org committed May 7, 2020
1 parent d0d0952 commit 2cc46ea
Show file tree
Hide file tree
Showing 75 changed files with 3,528 additions and 10 deletions.
14 changes: 4 additions & 10 deletions tests/language/async/return_types_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,14 @@ Future<int, String>
// [analyzer] STATIC_TYPE_WARNING.WRONG_NUMBER_OF_TYPE_ARGUMENTS
// [cfe] Expected 1 type arguments.
foo4() async {
// [error line 29, column 1]
// [cfe] Functions marked 'async' must have a return type assignable to 'Future'.
return "String";
// ^
// [cfe] A value of type 'String' can't be assigned to a variable of type 'FutureOr<invalid-type>'.
}

int
// [error line 37, column 1, length 3]
// [error line 33, column 1, length 3]
// [analyzer] STATIC_TYPE_WARNING.ILLEGAL_ASYNC_RETURN_TYPE
foo5() async {
// [error line 40, column 1]
// [error line 36, column 1, length 3]
// [cfe] Functions marked 'async' must have a return type assignable to 'Future'.
return 3;
}
Expand All @@ -48,11 +44,9 @@ Future<int> foo6() async {
return new Future<int>.value(3);
}

Future<Future<int>>
foo7() async {
Future<Future<int>> foo7() async {
// This is fine, the future is used to complete the returned future.
return new Future<int>.value(3);
// ^^^^^^^^^^^^^^^^^^^^^^^^
// [analyzer] STATIC_TYPE_WARNING.RETURN_OF_INVALID_TYPE
}

Iterable<int> foo8() sync* {
Expand Down
44 changes: 44 additions & 0 deletions tests/language/invalid_returns/async_invalid_return_00_test.dart
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 tests/language/invalid_returns/async_invalid_return_01_test.dart
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 tests/language/invalid_returns/async_invalid_return_02_test.dart
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 tests/language/invalid_returns/async_invalid_return_03_test.dart
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 tests/language/invalid_returns/async_invalid_return_04_test.dart
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 tests/language/invalid_returns/async_invalid_return_05_test.dart
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 tests/language/invalid_returns/async_invalid_return_08_test.dart
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 tests/language/invalid_returns/async_invalid_return_11_test.dart
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 tests/language/invalid_returns/async_invalid_return_14_test.dart
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 tests/language/invalid_returns/async_invalid_return_17_test.dart
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 tests/language/invalid_returns/async_invalid_return_20_test.dart
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();
}
Loading

0 comments on commit 2cc46ea

Please sign in to comment.