[dart2js] Fix spurious `!` in ConstantMap.

Change-Id: I45ab75005c4f3d658c476886ede3ba37dbb067e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/204625
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
diff --git a/sdk/lib/_internal/js_runtime/lib/constant_map.dart b/sdk/lib/_internal/js_runtime/lib/constant_map.dart
index 0f673d8..d5a5174 100644
--- a/sdk/lib/_internal/js_runtime/lib/constant_map.dart
+++ b/sdk/lib/_internal/js_runtime/lib/constant_map.dart
@@ -74,7 +74,10 @@
   void addAll(Map<K, V> other) => _throwUnmodifiable();
 
   Iterable<MapEntry<K, V>> get entries sync* {
-    for (var key in keys) yield new MapEntry<K, V>(key, this[key]!);
+    // `this[key]` has static type `V?` but is always `V`. Rather than `as V`,
+    // we use `as dynamic` so the upcast requires no checking and the implicit
+    // downcast to `V` will be discarded in production.
+    for (var key in keys) yield new MapEntry<K, V>(key, this[key] as dynamic);
   }
 
   void addEntries(Iterable<MapEntry<K, V>> entries) {
diff --git a/tests/web/regress/46417_test.dart b/tests/web/regress/46417_test.dart
new file mode 100644
index 0000000..3ba7d9b
--- /dev/null
+++ b/tests/web/regress/46417_test.dart
@@ -0,0 +1,12 @@
+// Copyright (c) 2021, 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 'package:expect/expect.dart';
+
+void main() {
+  var v = {
+    ...Map.unmodifiable({'x': null})
+  };
+  Expect.equals(null, v['x']);
+}
diff --git a/tests/web_2/regress/46417_test.dart b/tests/web_2/regress/46417_test.dart
new file mode 100644
index 0000000..3ba7d9b
--- /dev/null
+++ b/tests/web_2/regress/46417_test.dart
@@ -0,0 +1,12 @@
+// Copyright (c) 2021, 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 'package:expect/expect.dart';
+
+void main() {
+  var v = {
+    ...Map.unmodifiable({'x': null})
+  };
+  Expect.equals(null, v['x']);
+}