Skip to content

Commit

Permalink
Make Future.wait not return a const <Never>[] when given no futures.
Browse files Browse the repository at this point in the history
Fixes flutter#43445.

Bug: dart-lang/sdk#43445
Change-Id: I70f722f6bee1d4cfe4d53a5f37bc29f0751edd78
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164162
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
  • Loading branch information
lrhn authored and commit-bot@chromium.org committed Sep 25, 2020
1 parent 316128d commit 02923c6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion runtime/vm/compiler/recognized_methods_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ namespace dart {
V(::, reachabilityFence, ReachabilityFence, 0xad39d0a6) \
V(_Utf8Decoder, _scan, Utf8DecoderScan, 0x78f44c3c) \
V(_Future, timeout, FutureTimeout, 0x010f8ad4) \
V(Future, wait, FutureWait, 0x486414a9) \
V(Future, wait, FutureWait, 0x9a812df7) \

// List of intrinsics:
// (class-name, function-name, intrinsification method, fingerprint).
Expand Down
2 changes: 1 addition & 1 deletion sdk/lib/async/future.dart
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ abstract class Future<T> {
remaining++;
}
if (remaining == 0) {
return new Future<List<T>>.value(const <Never>[]);
return _future.._completeWithValue(<T>[]);
}
values = new List<T?>.filled(remaining, null);
} catch (e, st) {
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/async/future_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ void testCompleteManySuccessHandlers() {
Expect.equals(3, after2);
asyncEnd();
});

// Regression test for fix to issue:
// https://github.com/dart-lang/sdk/issues/43445
asyncStart();
Future.wait<int>(<Future<int>>[]).then((list) {
Expect.equals(0, list.length);
Expect.type<List<int>>(list);
Expect.notType<List<Null>>(list);
Expect.notType<List<Never>>(list);
asyncEnd();
});
}

// Tests for [catchError]
Expand Down
11 changes: 11 additions & 0 deletions tests/lib_2/async/future_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ void testCompleteManySuccessHandlers() {
Expect.equals(3, after2);
asyncEnd();
});

// Regression test for fix to issue:
// https://github.com/dart-lang/sdk/issues/43445
asyncStart();
Future.wait<int>(<Future<int>>[]).then((list) {
Expect.equals(0, list.length);
Expect.type<List<int>>(list);
Expect.notType<List<Null>>(list);
Expect.notType<List<Never>>(list);
asyncEnd();
});
}

// Tests for [catchError]
Expand Down

0 comments on commit 02923c6

Please sign in to comment.