Make `Future.wait` not return a `const <Never>[]` when given no futures.

Fixes #43445.

Bug: https://github.com/dart-lang/sdk/issues/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>
diff --git a/runtime/vm/compiler/recognized_methods_list.h b/runtime/vm/compiler/recognized_methods_list.h
index bd837eb..7044628 100644
--- a/runtime/vm/compiler/recognized_methods_list.h
+++ b/runtime/vm/compiler/recognized_methods_list.h
@@ -192,7 +192,7 @@
   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).
diff --git a/sdk/lib/async/future.dart b/sdk/lib/async/future.dart
index bb6ed77..0e1d703 100644
--- a/sdk/lib/async/future.dart
+++ b/sdk/lib/async/future.dart
@@ -433,7 +433,7 @@
         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) {
diff --git a/tests/lib/async/future_test.dart b/tests/lib/async/future_test.dart
index b084c86..f2d9710 100644
--- a/tests/lib/async/future_test.dart
+++ b/tests/lib/async/future_test.dart
@@ -143,6 +143,17 @@
     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]
diff --git a/tests/lib_2/async/future_test.dart b/tests/lib_2/async/future_test.dart
index 3a4f09d..6c227cf 100644
--- a/tests/lib_2/async/future_test.dart
+++ b/tests/lib_2/async/future_test.dart
@@ -140,6 +140,17 @@
     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]