Fix #36956, report undefined getter for uses on Null.

Bug: 36956
Change-Id: I5b8f40f5c1f7fd9304b02054e3d8d7d607c12af1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106021
Commit-Queue: Mike Fairhurst <mfairhurst@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
diff --git a/pkg/analyzer/lib/src/generated/element_resolver.dart b/pkg/analyzer/lib/src/generated/element_resolver.dart
index 0ab26fe..22baf4d 100644
--- a/pkg/analyzer/lib/src/generated/element_resolver.dart
+++ b/pkg/analyzer/lib/src/generated/element_resolver.dart
@@ -1743,14 +1743,10 @@
 
   /**
    * Return `true` if we should report an error for a [member] lookup that found
-   * no match on the given [type], or accessing a [member] on a nullable type.
+   * no match on the given [type].
    */
-  bool _shouldReportInvalidMember(DartType type, Element member) {
-    return type != null &&
-        member == null &&
-        !type.isDynamic &&
-        !type.isDartCoreNull;
-  }
+  bool _shouldReportInvalidMember(DartType type, Element member) =>
+      type != null && member == null && !type.isDynamic;
 
   /**
    * Checks whether the given [expression] is a reference to a class. If it is
diff --git a/pkg/analyzer/test/generated/compile_time_error_code.dart b/pkg/analyzer/test/generated/compile_time_error_code.dart
index e1db296..181575f 100644
--- a/pkg/analyzer/test/generated/compile_time_error_code.dart
+++ b/pkg/analyzer/test/generated/compile_time_error_code.dart
@@ -648,25 +648,28 @@
 
   test_constEvalThrowsException_unaryBitNot_null() async {
     await assertErrorsInCode('''
-const C = ~null;
+const dynamic D = null;
+const C = ~D;
 ''', [
-      error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 10, 5),
+      error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 34, 2),
     ]);
   }
 
   test_constEvalThrowsException_unaryNegated_null() async {
     await assertErrorsInCode('''
-const C = -null;
+const dynamic D = null;
+const C = -D;
 ''', [
-      error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 10, 5),
+      error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 34, 2),
     ]);
   }
 
   test_constEvalThrowsException_unaryNot_null() async {
     await assertErrorsInCode('''
-const C = !null;
+const dynamic D = null;
+const C = !D;
 ''', [
-      error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 10, 5),
+      error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 34, 2),
     ]);
   }
 
@@ -5547,9 +5550,10 @@
   Future<void> _check_constEvalThrowsException_binary_null(
       String expr, bool resolved) async {
     await assertErrorsInCode('''
-const C = $expr;
+const dynamic D = null;
+const C = ${expr.replaceAll('null', 'D')};
 ''', [
-      error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 10, 8),
+      error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 34, 5),
     ]);
   }
 
diff --git a/pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart b/pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart
index 6feaae5..3958e85 100644
--- a/pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart
@@ -91,6 +91,15 @@
 ''');
   }
 
+  test_nullMember_undefined() async {
+    await assertErrorCodesInCode(r'''
+m() {
+  Null _null;
+  _null.foo;
+}
+''', [StaticTypeWarningCode.UNDEFINED_GETTER]);
+  }
+
   test_promotedTypeParameter_regress35305() async {
     await assertErrorsInCode(r'''
 void f<X extends num, Y extends X>(Y y) {
diff --git a/tests/language_2/null_no_such_method_test.dart b/tests/language_2/null_no_such_method_test.dart
index 600c6bb..299ba2d 100644
--- a/tests/language_2/null_no_such_method_test.dart
+++ b/tests/language_2/null_no_such_method_test.dart
@@ -4,10 +4,10 @@
 
 import "package:expect/expect.dart";
 
-var array = <dynamic>[1];
-
 main() {
-  Expect.throwsNoSuchMethodError(() => -null);
+  Expect.throwsNoSuchMethodError(() => -(null as dynamic));
   // Make sure we have an untyped call to operator-.
   print(-array[0]);
 }
+
+var array = <dynamic>[1];