Ensure that nullability promotion of the `Null` type yields `Never`.

Change-Id: I2232f80bbf5c8a9e51f305a603c06ca2b3ad8aea
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103573
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/lib/src/generated/type_system.dart b/pkg/analyzer/lib/src/generated/type_system.dart
index c27b9b3..0fe7754 100644
--- a/pkg/analyzer/lib/src/generated/type_system.dart
+++ b/pkg/analyzer/lib/src/generated/type_system.dart
@@ -2107,7 +2107,10 @@
     return null;
   }
 
+  /// Returns a non-nullable version of [type].  This is equivalent to the
+  /// operation `NonNull` defined in the spec.
   DartType promoteToNonNull(TypeImpl type) {
+    if (type.isDartCoreNull) return typeProvider.bottomType;
     // TODO(mfairhurst): handle type parameter types
     return type.withNullability(NullabilitySuffix.none);
   }
diff --git a/pkg/analyzer/test/src/dart/resolution/non_nullable_test.dart b/pkg/analyzer/test/src/dart/resolution/non_nullable_test.dart
index b99a66d..da04a06 100644
--- a/pkg/analyzer/test/src/dart/resolution/non_nullable_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/non_nullable_test.dart
@@ -207,6 +207,18 @@
     assertType(findNode.methodInvocation('first').methodName, 'Function?');
   }
 
+  test_null_assertion_operator_changes_null_to_never() async {
+    addTestFile('''
+main() {
+  Null x = null;
+  x!;
+}
+''');
+    await resolveTestFile();
+    assertNoTestErrors();
+    assertType(findNode.postfix('x!'), 'Never');
+  }
+
   test_null_assertion_operator_removes_nullability() async {
     addTestFile('''
 main() {
diff --git a/tests/language_2/nnbd/resolution/null_assertion_null_type_test.dart b/tests/language_2/nnbd/resolution/null_assertion_null_type_test.dart
new file mode 100644
index 0000000..159731d
--- /dev/null
+++ b/tests/language_2/nnbd/resolution/null_assertion_null_type_test.dart
@@ -0,0 +1,21 @@
+// Copyright (c) 2019, 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.
+
+// SharedOptions=--enable-experiment=non-nullable
+
+// Test that the trailing "!" properly promotes the type `Null` to `Never`, by
+// verifying that it's statically ok to pass it to a function expecting a
+// non-null parameter.
+import 'package:expect/expect.dart';
+
+void f(int i) {}
+
+void g(Null n) {
+   // Statically ok because `Never <: int`.  Throws at runtime.
+  f(n!);
+}
+
+main() {
+  Expect.throws(() => g(null));
+}