Issue 48004. Report when null-aware operator is used on type.

Bug: https://github.com/dart-lang/sdk/issues/48004
Change-Id: I61c658f9974fdb2023aa999bf34ee873e348058a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/246301
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index a860d87..ba4d938 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -4518,6 +4518,19 @@
         return;
       }
     } else if (targetType == null) {
+      if (target is Identifier) {
+        final targetElement = target.staticElement;
+        if (targetElement is ClassElement ||
+            targetElement is ExtensionElement ||
+            targetElement is TypeAliasElement) {
+          errorReporter.reportErrorForOffset(
+            errorCode,
+            operator.offset,
+            endToken.end - operator.offset,
+            arguments,
+          );
+        }
+      }
       return;
     }
 
diff --git a/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart b/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart
index 342e26d..aa551dd 100644
--- a/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart
@@ -5053,16 +5053,20 @@
   }
 
   test_error_undefinedMethod_typeLiteral_conditional() async {
-    // When applied to a type literal, the conditional access operator '?.'
-    // cannot be used to access instance methods of Type.
-    await assertErrorsInCode(r'''
+    await assertErrorsInCode(
+      r'''
 class A {}
 main() {
   A?.toString();
 }
-''', [
-      error(CompileTimeErrorCode.UNDEFINED_METHOD, 25, 8),
-    ]);
+''',
+      expectedErrorsByNullability(nullable: [
+        error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 23, 2),
+        error(CompileTimeErrorCode.UNDEFINED_METHOD, 25, 8),
+      ], legacy: [
+        error(CompileTimeErrorCode.UNDEFINED_METHOD, 25, 8),
+      ]),
+    );
   }
 
   test_error_undefinedSuperMethod() async {
diff --git a/pkg/analyzer/test/src/diagnostics/invalid_null_aware_operator_test.dart b/pkg/analyzer/test/src/diagnostics/invalid_null_aware_operator_test.dart
index 60e0fd0..bc80d9b 100644
--- a/pkg/analyzer/test/src/diagnostics/invalid_null_aware_operator_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/invalid_null_aware_operator_test.dart
@@ -171,7 +171,7 @@
   }
 
   test_getter_class() async {
-    await assertNoErrorsInCode('''
+    await assertErrorsInCode('''
 class C {
   static int x = 0;
 }
@@ -179,11 +179,13 @@
 f() {
   C?.x;
 }
-''');
+''', [
+      error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 42, 2),
+    ]);
   }
 
   test_getter_extension() async {
-    await assertNoErrorsInCode('''
+    await assertErrorsInCode('''
 extension E on int {
   static int x = 0;
 }
@@ -191,7 +193,9 @@
 f() {
   E?.x;
 }
-''');
+''', [
+      error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 53, 2),
+    ]);
   }
 
   test_getter_legacy() async {
@@ -213,7 +217,7 @@
   }
 
   test_getter_mixin() async {
-    await assertNoErrorsInCode('''
+    await assertErrorsInCode('''
 mixin M {
   static int x = 0;
 }
@@ -221,7 +225,9 @@
 f() {
   M?.x;
 }
-''');
+''', [
+      error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 42, 2),
+    ]);
   }
 
   test_getter_nonNullable() async {
@@ -303,7 +309,7 @@
   }
 
   test_method_class() async {
-    await assertNoErrorsInCode('''
+    await assertErrorsInCode('''
 class C {
   static void foo() {}
 }
@@ -311,11 +317,31 @@
 f() {
   C?.foo();
 }
+''', [
+      error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 45, 2),
+    ]);
+  }
+
+  test_method_class_prefixed() async {
+    newFile('$testPackageLibPath/a.dart', r'''
+class C {
+  static void foo() {}
+}
 ''');
+
+    await assertErrorsInCode('''
+import 'a.dart' as prefix;
+
+void f() {
+  prefix.C?.foo();
+}
+''', [
+      error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 49, 2),
+    ]);
   }
 
   test_method_extension() async {
-    await assertNoErrorsInCode('''
+    await assertErrorsInCode('''
 extension E on int {
   static void foo() {}
 }
@@ -323,7 +349,27 @@
 f() {
   E?.foo();
 }
+''', [
+      error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 56, 2),
+    ]);
+  }
+
+  test_method_extension_prefixed() async {
+    newFile('$testPackageLibPath/a.dart', r'''
+extension E on int {
+  static void foo() {}
+}
 ''');
+
+    await assertErrorsInCode('''
+import 'a.dart' as prefix;
+
+f() {
+  prefix.E?.foo();
+}
+''', [
+      error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 44, 2),
+    ]);
   }
 
   test_method_legacy() async {
@@ -345,7 +391,7 @@
   }
 
   test_method_mixin() async {
-    await assertNoErrorsInCode('''
+    await assertErrorsInCode('''
 mixin M {
   static void foo() {}
 }
@@ -353,7 +399,27 @@
 f() {
   M?.foo();
 }
+''', [
+      error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 45, 2),
+    ]);
+  }
+
+  test_method_mixin_prefixed() async {
+    newFile('$testPackageLibPath/a.dart', r'''
+mixin M {
+  static void foo() {}
+}
 ''');
+
+    await assertErrorsInCode('''
+import 'a.dart' as prefix;
+
+f() {
+  prefix.M?.foo();
+}
+''', [
+      error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 44, 2),
+    ]);
   }
 
   test_method_nonNullable() async {
@@ -377,6 +443,22 @@
 ''');
   }
 
+  test_method_typeAlias_class() async {
+    await assertErrorsInCode('''
+class A {
+  static void foo() {}
+}
+
+typedef B = A; 
+
+f() {
+  B?.foo();
+}
+''', [
+      error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 62, 2),
+    ]);
+  }
+
   test_nonNullableSpread_nullableType() async {
     await assertNoErrorsInCode('''
 f(List<int> x) {
@@ -421,7 +503,7 @@
   }
 
   test_setter_class() async {
-    await assertNoErrorsInCode('''
+    await assertErrorsInCode('''
 class C {
   static int x = 0;
 }
@@ -429,11 +511,13 @@
 f() {
   C?.x = 0;
 }
-''');
+''', [
+      error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 42, 2),
+    ]);
   }
 
   test_setter_extension() async {
-    await assertNoErrorsInCode('''
+    await assertErrorsInCode('''
 extension E on int {
   static int x = 0;
 }
@@ -441,11 +525,13 @@
 f() {
   E?.x = 0;
 }
-''');
+''', [
+      error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 53, 2),
+    ]);
   }
 
   test_setter_mixin() async {
-    await assertNoErrorsInCode('''
+    await assertErrorsInCode('''
 mixin M {
   static int x = 0;
 }
@@ -453,7 +539,9 @@
 f() {
   M?.x = 0;
 }
-''');
+''', [
+      error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 42, 2),
+    ]);
   }
 
   /// Here we test that analysis does not crash while checking whether to
diff --git a/pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart b/pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart
index 2f1bacb..1fe9cd4 100644
--- a/pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart
@@ -479,15 +479,18 @@
     ]);
   }
 
-  test_static_conditionalAcces_defined() async {
-    // The conditional access operator '?.' can be used to access static
-    // fields.
-    await assertNoErrorsInCode('''
+  test_static_conditionalAccess_defined() async {
+    await assertErrorsInCode(
+      '''
 class A {
   static var x;
 }
 var a = A?.x;
-''');
+''',
+      expectedErrorsByNullability(nullable: [
+        error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 37, 2),
+      ], legacy: []),
+    );
   }
 
   test_static_definedInSuperclass() async {
@@ -527,14 +530,18 @@
   }
 
   test_typeLiteral_conditionalAccess() async {
-    // When applied to a type literal, the conditional access operator '?.'
-    // cannot be used to access instance getters of Type.
-    await assertErrorsInCode('''
+    await assertErrorsInCode(
+      '''
 class A {}
 f() => A?.hashCode;
-''', [
-      error(CompileTimeErrorCode.UNDEFINED_GETTER, 21, 8),
-    ]);
+''',
+      expectedErrorsByNullability(nullable: [
+        error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 19, 2),
+        error(CompileTimeErrorCode.UNDEFINED_GETTER, 21, 8),
+      ], legacy: [
+        error(CompileTimeErrorCode.UNDEFINED_GETTER, 21, 8),
+      ]),
+    );
   }
 
   test_typeSubstitution_defined() async {
diff --git a/pkg/analyzer/test/src/diagnostics/undefined_method_test.dart b/pkg/analyzer/test/src/diagnostics/undefined_method_test.dart
index ed18c21..6b5bc62 100644
--- a/pkg/analyzer/test/src/diagnostics/undefined_method_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/undefined_method_test.dart
@@ -228,14 +228,14 @@
   }
 
   test_static_conditionalAccess_defined() async {
-    // The conditional access operator '?.' can be used to access static
-    // methods.
-    await assertNoErrorsInCode('''
+    await assertErrorsInCode('''
 class A {
   static void m() {}
 }
 f() { A?.m(); }
-''');
+''', [
+      error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 40, 2),
+    ]);
   }
 
   test_static_mixinApplication_superConstructorIsFactory() async {
diff --git a/pkg/analyzer/test/src/diagnostics/undefined_setter_test.dart b/pkg/analyzer/test/src/diagnostics/undefined_setter_test.dart
index f234428..9882644 100644
--- a/pkg/analyzer/test/src/diagnostics/undefined_setter_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/undefined_setter_test.dart
@@ -212,14 +212,17 @@
   }
 
   test_static_conditionalAccess_defined() async {
-    // The conditional access operator '?.' can be used to access static
-    // fields.
-    await assertNoErrorsInCode('''
+    await assertErrorsInCode(
+      '''
 class A {
   static var x;
 }
 f() { A?.x = 1; }
-''');
+''',
+      expectedErrorsByNullability(nullable: [
+        error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 35, 2),
+      ], legacy: []),
+    );
   }
 
   test_static_definedInSuperclass() async {
diff --git a/tests/language/if_null/assignment_behavior_runtime_26_test.dart b/tests/language/if_null/assignment_behavior_runtime_26_test.dart
index afd709b..6fe8e95 100644
--- a/tests/language/if_null/assignment_behavior_runtime_26_test.dart
+++ b/tests/language/if_null/assignment_behavior_runtime_26_test.dart
@@ -204,6 +204,9 @@
 
   yGetValue = 1;
   check(1, () => C?.x ??= y, ['C.x', 'y', 'C.x=1']);
-
+  //             ^
+  // [cfe] The class 'C' cannot be null.
+  //              ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
 
 }
diff --git a/tests/language/if_null/assignment_behavior_runtime_27_test.dart b/tests/language/if_null/assignment_behavior_runtime_27_test.dart
index 97fa09c..d932daa 100644
--- a/tests/language/if_null/assignment_behavior_runtime_27_test.dart
+++ b/tests/language/if_null/assignment_behavior_runtime_27_test.dart
@@ -206,4 +206,8 @@
 
   yGetValue = 1;
   check(1, () => h.C?.x ??= y, ['h.C.x', 'y', 'h.C.x=1']);
+  //               ^
+  // [cfe] The class 'C' cannot be null.
+  //                ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
 }
diff --git a/tests/language/if_null/assignment_behavior_test.dart b/tests/language/if_null/assignment_behavior_test.dart
index ab3f20c..a0d6f11 100644
--- a/tests/language/if_null/assignment_behavior_test.dart
+++ b/tests/language/if_null/assignment_behavior_test.dart
@@ -257,6 +257,8 @@
   // C?.v ??= e2 is equivalent to C.v ??= e2.
   C.xGetValue = 1;
   check(1, () => C?.x ??= bad(), ['C.x']);
+  //              ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
   //             ^
   // [cfe] The class 'C' cannot be null.
   h.C.xgetValue = 1;
@@ -269,10 +271,14 @@
   // [cfe] Undefined name 'c'.
   yGetValue = 1;
   check(1, () => C?.x ??= y, ['C.x', 'y', 'C.x=1']);
+  //              ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
   //             ^
   // [cfe] The class 'C' cannot be null.
   yGetValue = 1;
   check(1, () => h.C?.x ??= y, ['h.C.x', 'y', 'h.C.x=1']);
+  //                ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
   //               ^
   // [cfe] The class 'C' cannot be null.
 }
diff --git a/tests/language/nnbd/flow_analysis/never_runtime_check_nnbd.dart b/tests/language/nnbd/flow_analysis/never_runtime_check_nnbd.dart
index a59bdd2..52d691c 100644
--- a/tests/language/nnbd/flow_analysis/never_runtime_check_nnbd.dart
+++ b/tests/language/nnbd/flow_analysis/never_runtime_check_nnbd.dart
@@ -227,7 +227,8 @@
 }
 
 int ifNullAssignNullAwareStatic(int f()) {
-  return C?.staticField ??= f(); // ignore: dead_null_aware_expression
+  // ignore: dead_null_aware_expression, invalid_null_aware_operator
+  return C?.staticField ??= f();
 }
 
 void unnecessaryNullAwareAccess(int f()) {
diff --git a/tests/language/null_aware/access_runtime_test.dart b/tests/language/null_aware/access_runtime_test.dart
index 9495fef..49e606e 100644
--- a/tests/language/null_aware/access_runtime_test.dart
+++ b/tests/language/null_aware/access_runtime_test.dart
@@ -28,9 +28,17 @@
   // C?.id is equivalent to C.id.
   C.staticInt = 1;
   Expect.equals(1, C?.staticInt);
+  //               ^
+  // [cfe] The class 'C' cannot be null.
+  //                ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
 
   h.C.staticInt = 1;
   Expect.equals(1, h.C?.staticInt);
+  //                 ^
+  // [cfe] The class 'C' cannot be null.
+  //                  ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
 
   // The static type of e1?.id is the static type of e1.id.
   {
@@ -41,12 +49,20 @@
   {
     C.staticInt = 1;
     int? i = C?.staticInt;
+    //       ^
+    // [cfe] The class 'C' cannot be null.
+    //        ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(1, i);
   }
 
   {
     h.C.staticInt = 1;
     int? i = h.C?.staticInt;
+    //         ^
+    // [cfe] The class 'C' cannot be null.
+    //          ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(1, i);
   }
 }
diff --git a/tests/language/null_aware/access_test.dart b/tests/language/null_aware/access_test.dart
index 6fc1daa..61b4207 100644
--- a/tests/language/null_aware/access_test.dart
+++ b/tests/language/null_aware/access_test.dart
@@ -35,6 +35,8 @@
   {
     C.staticInt = 1;
     Expect.equals(1, C?.staticInt);
+    //                ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     //               ^
     // [cfe] The class 'C' cannot be null.
   }
@@ -43,6 +45,8 @@
     Expect.equals(1, h.C?.staticInt);
     //                 ^
     // [cfe] The class 'C' cannot be null.
+    //                  ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
   }
 
   // The static type of e1?.d is the static type of e1.id.
@@ -70,6 +74,8 @@
     int? i = C?.staticInt;
     //       ^
     // [cfe] The class 'C' cannot be null.
+    //        ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(1, i);
   }
   {
@@ -77,6 +83,8 @@
     int? i = h.C?.staticInt;
     //         ^
     // [cfe] The class 'C' cannot be null.
+    //          ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(1, i);
   }
   {
@@ -87,6 +95,8 @@
     // [cfe] The class 'C' cannot be null.
     //             ^
     // [cfe] A value of type 'int?' can't be assigned to a variable of type 'String?'.
+    //           ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(null, s);
   }
   {
@@ -94,6 +104,8 @@
     String? s = h.C?.staticNullable;
     //          ^^^^^^^^^^^^^^^^^^^
     // [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
+    //             ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     //            ^
     // [cfe] The class 'C' cannot be null.
     //               ^
@@ -125,10 +137,14 @@
 
   // Nor can it be used to access the hashCode getter on the class Type.
   Expect.throwsNoSuchMethodError(() => C?.hashCode);
+  //                                    ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
   //                                      ^^^^^^^^
   // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_GETTER
   // [cfe] Member not found: 'hashCode'.
   Expect.throwsNoSuchMethodError(() => h.C?.hashCode);
+  //                                      ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
   //                                        ^^^^^^^^
   // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_GETTER
   // [cfe] Member not found: 'hashCode'.
diff --git a/tests/language/null_aware/assignment_runtime_test.dart b/tests/language/null_aware/assignment_runtime_test.dart
index 6e73e75..69f1258 100644
--- a/tests/language/null_aware/assignment_runtime_test.dart
+++ b/tests/language/null_aware/assignment_runtime_test.dart
@@ -52,10 +52,18 @@
   // C?.v = e2 is equivalent to C.v = e2.
   C.staticInt = 1;
   Expect.equals(2, C?.staticInt = 2);
+  //               ^
+  // [cfe] The class 'C' cannot be null.
+  //                ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
   Expect.equals(2, C.staticInt);
 
   h.C.staticInt = 1;
   Expect.equals(2, h.C?.staticInt = 2);
+  //                 ^
+  // [cfe] The class 'C' cannot be null.
+  //                  ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
   Expect.equals(2, h.C.staticInt);
 
   // The static type of e1?.v = e2 is the static type of e2.
@@ -70,12 +78,20 @@
     D.staticE = new E();
     G g = new G();
     F? f = (D?.staticE = g);
+    //      ^
+    // [cfe] The class 'D' cannot be null.
+    //       ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(f, g);
   }
 
   h.D.staticE = new h.E();
   h.G g = new h.G();
   h.F? f = (h.D?.staticE = g);
+  //          ^
+  // [cfe] The class 'D' cannot be null.
+  //           ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
   Expect.identical(f, g);
 
   // Exactly the same errors that would be caused by e1.v = e2 are
@@ -92,7 +108,15 @@
   // C?.v op= e2 is equivalent to C.v op= e2.
   C.staticInt = 1;
   Expect.equals(3, C?.staticInt += 2);
+  //               ^
+  // [cfe] The class 'C' cannot be null.
+  //                ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
   Expect.equals(3, C?.staticInt);
+  //               ^
+  // [cfe] The class 'C' cannot be null.
+  //                ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
 
   // The static type of e1?.v op= e2 is the static type of e1.v op e2.
   {
@@ -104,12 +128,20 @@
   {
     D.staticE = new E();
     F? f = (D?.staticE += 1);
+    //      ^
+    // [cfe] The class 'D' cannot be null.
+    //       ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(D.staticE, f);
   }
 
   {
     h.D.staticE = new h.E();
     h.F? f = (h.D?.staticE += 1);
+    //          ^
+    // [cfe] The class 'D' cannot be null.
+    //           ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(h.D.staticE, f);
   }
 }
diff --git a/tests/language/null_aware/assignment_test.dart b/tests/language/null_aware/assignment_test.dart
index 59397b3..3fdb555 100644
--- a/tests/language/null_aware/assignment_test.dart
+++ b/tests/language/null_aware/assignment_test.dart
@@ -64,6 +64,8 @@
     Expect.equals(2, C?.staticInt = 2);
     //               ^
     // [cfe] The class 'C' cannot be null.
+    //                ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(2, C.staticInt);
   }
   {
@@ -71,6 +73,8 @@
     Expect.equals(2, h.C?.staticInt = 2);
     //                 ^
     // [cfe] The class 'C' cannot be null.
+    //                  ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(2, h.C.staticInt);
   }
 
@@ -95,6 +99,8 @@
     F? f = (D?.staticE = g);
     //      ^
     // [cfe] The class 'D' cannot be null.
+    //       ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(f, g);
   }
   {
@@ -103,6 +109,8 @@
     h.F? f = (h.D?.staticE = g);
     //          ^
     // [cfe] The class 'D' cannot be null.
+    //           ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(f, g);
   }
   {
@@ -112,6 +120,8 @@
     //      ^^^^^^^^^^^^^^
     // [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
     // [cfe] The class 'D' cannot be null.
+    //       ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     //         ^
     // [cfe] A value of type 'E' can't be assigned to a variable of type 'F?'.
   }
@@ -123,6 +133,8 @@
     // [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
     //         ^
     // [cfe] The class 'D' cannot be null.
+    //          ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     //            ^
     // [cfe] A value of type 'E' can't be assigned to a variable of type 'F'.
   }
@@ -163,9 +175,13 @@
     Expect.equals(3, C?.staticInt += 2);
     //               ^
     // [cfe] The class 'C' cannot be null.
+    //                ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(3, C?.staticInt);
     //               ^
     // [cfe] The class 'C' cannot be null.
+    //                ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
   }
 
   // The static type of e1?.v op= e2 is the static type of e1.v op e2.
@@ -183,6 +199,8 @@
     F? f = (D?.staticE += 1);
     //      ^
     // [cfe] The class 'D' cannot be null.
+    //       ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(D.staticE, f);
   }
   {
@@ -190,6 +208,8 @@
     h.F? f = (h.D?.staticE += 1);
     //          ^
     // [cfe] The class 'D' cannot be null.
+    //           ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(h.D.staticE, f);
   }
 
@@ -239,6 +259,8 @@
     F? f = (D?.staticE += nullC());
     //      ^
     // [cfe] The class 'D' cannot be null.
+    //       ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     //                    ^^^^^^^
     // [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
     // [cfe] A value of type 'C?' can't be assigned to a variable of type 'int'.
@@ -248,6 +270,8 @@
     h.F? f = (h.D?.staticE += h.nullC());
     //          ^
     // [cfe] The class 'D' cannot be null.
+    //           ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     //                        ^^^^^^^^^
     // [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
     //                          ^
@@ -259,6 +283,8 @@
     //      ^^^^^^^^^^^^^^^
     // [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
     // [cfe] The class 'D' cannot be null.
+    //       ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     //         ^
     // [cfe] A value of type 'G' can't be assigned to a variable of type 'H?'.
   }
@@ -269,6 +295,8 @@
     // [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
     //           ^
     // [cfe] The class 'D' cannot be null.
+    //            ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     //              ^
     // [cfe] A value of type 'G' can't be assigned to a variable of type 'H?'.
   }
diff --git a/tests/language/null_aware/increment_decrement_runtime_test.dart b/tests/language/null_aware/increment_decrement_runtime_test.dart
index 0229341..01c72da 100644
--- a/tests/language/null_aware/increment_decrement_runtime_test.dart
+++ b/tests/language/null_aware/increment_decrement_runtime_test.dart
@@ -55,11 +55,19 @@
   {
     C.staticInt = 1;
     Expect.equals(1, C?.staticInt++);
+    //               ^
+    // [cfe] The class 'C' cannot be null.
+    //                ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(2, C.staticInt);
   }
   {
     h.C.staticInt = 1;
     Expect.equals(1, h.C?.staticInt++);
+    //                 ^
+    // [cfe] The class 'C' cannot be null.
+    //                  ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(2, h.C.staticInt);
   }
 
@@ -75,12 +83,20 @@
     E e1 = new E();
     D.staticE = e1;
     E? e2 = D?.staticE++;
+    //      ^
+    // [cfe] The class 'D' cannot be null.
+    //       ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(e1, e2);
   }
   {
     h.E e1 = new h.E();
     h.D.staticE = e1;
     h.E? e2 = h.D?.staticE++;
+    //          ^
+    // [cfe] The class 'D' cannot be null.
+    //           ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(e1, e2);
   }
 
@@ -96,11 +112,19 @@
   {
     C.staticInt = 1;
     Expect.equals(1, C?.staticInt--);
+    //               ^
+    // [cfe] The class 'C' cannot be null.
+    //                ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(0, C.staticInt);
   }
   {
     h.C.staticInt = 1;
     Expect.equals(1, h.C?.staticInt--);
+    //                 ^
+    // [cfe] The class 'C' cannot be null.
+    //                  ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(0, h.C.staticInt);
   }
 
@@ -116,12 +140,20 @@
     E e1 = new E();
     D.staticE = e1;
     E? e2 = D?.staticE--;
+    //      ^
+    // [cfe] The class 'D' cannot be null.
+    //       ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(e1, e2);
   }
   {
     h.E e1 = new h.E();
     h.D.staticE = e1;
     h.E? e2 = h.D?.staticE--;
+    //          ^
+    // [cfe] The class 'D' cannot be null.
+    //           ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(e1, e2);
   }
 
@@ -137,11 +169,19 @@
   {
     C.staticInt = 1;
     Expect.equals(2, ++C?.staticInt);
+    //                 ^
+    // [cfe] The class 'C' cannot be null.
+    //                  ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(2, C.staticInt);
   }
   {
     h.C.staticInt = 1;
     Expect.equals(2, ++h.C?.staticInt);
+    //                   ^
+    // [cfe] The class 'C' cannot be null.
+    //                    ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(2, h.C.staticInt);
   }
 
@@ -160,6 +200,10 @@
   {
     h.D.staticE = new h.E();
     h.F? f = ++h.D?.staticE;
+    //           ^
+    // [cfe] The class 'D' cannot be null.
+    //            ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(h.D.staticE, f);
   }
 
@@ -175,11 +219,19 @@
   {
     C.staticInt = 1;
     Expect.equals(0, --C?.staticInt);
+    //                 ^
+    // [cfe] The class 'C' cannot be null.
+    //                  ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(0, C.staticInt);
   }
   {
     h.C.staticInt = 1;
     Expect.equals(0, --h.C?.staticInt);
+    //                   ^
+    // [cfe] The class 'C' cannot be null.
+    //                    ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(0, h.C.staticInt);
   }
 
@@ -193,12 +245,20 @@
   {
     D.staticE = new E();
     F? f = --D?.staticE;
+    //       ^
+    // [cfe] The class 'D' cannot be null.
+    //        ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(D.staticE, f);
   }
 
   {
     h.D.staticE = new h.E();
     h.F? f = --h.D?.staticE;
+    //           ^
+    // [cfe] The class 'D' cannot be null.
+    //            ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(h.D.staticE, f);
   }
 }
diff --git a/tests/language/null_aware/increment_decrement_test.dart b/tests/language/null_aware/increment_decrement_test.dart
index d1916b6..0e99f75 100644
--- a/tests/language/null_aware/increment_decrement_test.dart
+++ b/tests/language/null_aware/increment_decrement_test.dart
@@ -54,6 +54,8 @@
     Expect.equals(1, C?.staticInt++);
     //               ^
     // [cfe] The class 'C' cannot be null.
+    //                ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(2, C.staticInt);
   }
   {
@@ -61,6 +63,8 @@
     Expect.equals(1, h.C?.staticInt++);
     //                 ^
     // [cfe] The class 'C' cannot be null.
+    //                  ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(2, h.C.staticInt);
   }
 
@@ -86,6 +90,8 @@
     E? e2 = D?.staticE++;
     //      ^
     // [cfe] The class 'D' cannot be null.
+    //       ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(e1, e2);
   }
   {
@@ -94,6 +100,8 @@
     h.E? e2 = h.D?.staticE++;
     //          ^
     // [cfe] The class 'D' cannot be null.
+    //           ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(e1, e2);
   }
   {
@@ -103,6 +111,8 @@
     //     ^^^^^^^^^^^^
     // [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
     // [cfe] The class 'D' cannot be null.
+    //      ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     //               ^
     // [cfe] A value of type 'E' can't be assigned to a variable of type 'F?'.
     Expect.identical(f, g);
@@ -115,6 +125,8 @@
     // [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
     //         ^
     // [cfe] The class 'D' cannot be null.
+    //          ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     //                   ^
     // [cfe] A value of type 'E' can't be assigned to a variable of type 'F?'.
     Expect.identical(f, g);
@@ -134,6 +146,8 @@
     Expect.equals(1, C?.staticInt--);
     //               ^
     // [cfe] The class 'C' cannot be null.
+    //                ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(0, C.staticInt);
   }
   {
@@ -141,6 +155,8 @@
     Expect.equals(1, h.C?.staticInt--);
     //                 ^
     // [cfe] The class 'C' cannot be null.
+    //                  ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(0, h.C.staticInt);
   }
 
@@ -166,6 +182,8 @@
     E? e2 = D?.staticE--;
     //      ^
     // [cfe] The class 'D' cannot be null.
+    //       ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(e1, e2);
   }
   {
@@ -174,6 +192,8 @@
     h.E? e2 = h.D?.staticE--;
     //          ^
     // [cfe] The class 'D' cannot be null.
+    //           ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(e1, e2);
   }
   {
@@ -183,6 +203,8 @@
     //     ^^^^^^^^^^^^
     // [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
     // [cfe] The class 'D' cannot be null.
+    //      ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     //               ^
     // [cfe] A value of type 'E' can't be assigned to a variable of type 'F?'.
     Expect.identical(f, g);
@@ -195,6 +217,8 @@
     // [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
     //         ^
     // [cfe] The class 'D' cannot be null.
+    //          ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     //                   ^
     // [cfe] A value of type 'E' can't be assigned to a variable of type 'F?'.
     Expect.identical(f, g);
@@ -214,6 +238,8 @@
     Expect.equals(2, ++C?.staticInt);
     //                 ^
     // [cfe] The class 'C' cannot be null.
+    //                  ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(2, C.staticInt);
   }
   {
@@ -221,6 +247,8 @@
     Expect.equals(2, ++h.C?.staticInt);
     //                   ^
     // [cfe] The class 'C' cannot be null.
+    //                    ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(2, h.C.staticInt);
   }
 
@@ -244,6 +272,8 @@
     F? f = ++D?.staticE;
     //       ^
     // [cfe] The class 'D' cannot be null.
+    //        ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(D.staticE, f);
   }
   {
@@ -251,6 +281,8 @@
     h.F? f = ++h.D?.staticE;
     //           ^
     // [cfe] The class 'D' cannot be null.
+    //            ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(h.D.staticE, f);
   }
   {
@@ -260,6 +292,8 @@
     // [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
     //       ^
     // [cfe] The class 'D' cannot be null.
+    //        ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     //          ^
     // [cfe] A value of type 'G' can't be assigned to a variable of type 'H?'.
     Expect.identical(D.staticE, h);
@@ -271,6 +305,8 @@
     // [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
     //            ^
     // [cfe] The class 'D' cannot be null.
+    //             ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     //               ^
     // [cfe] A value of type 'G' can't be assigned to a variable of type 'H?'.
     Expect.identical(h.D.staticE, hh);
@@ -290,6 +326,8 @@
     Expect.equals(0, --C?.staticInt);
     //                 ^
     // [cfe] The class 'C' cannot be null.
+    //                  ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(0, C.staticInt);
   }
   {
@@ -297,6 +335,8 @@
     Expect.equals(0, --h.C?.staticInt);
     //                   ^
     // [cfe] The class 'C' cannot be null.
+    //                    ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(0, h.C.staticInt);
   }
 
@@ -320,6 +360,8 @@
     F? f = --D?.staticE;
     //       ^
     // [cfe] The class 'D' cannot be null.
+    //        ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(D.staticE, f);
   }
   {
@@ -327,6 +369,8 @@
     h.F? f = --h.D?.staticE;
     //           ^
     // [cfe] The class 'D' cannot be null.
+    //            ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.identical(h.D.staticE, f);
   }
   {
@@ -336,6 +380,8 @@
     // [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
     //       ^
     // [cfe] The class 'D' cannot be null.
+    //        ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     //          ^
     // [cfe] A value of type 'G' can't be assigned to a variable of type 'H?'.
     Expect.identical(D.staticE, h);
@@ -347,6 +393,8 @@
     // [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
     //            ^
     // [cfe] The class 'D' cannot be null.
+    //             ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     //               ^
     // [cfe] A value of type 'G' can't be assigned to a variable of type 'H?'.
     Expect.identical(h.D.staticE, hh);
diff --git a/tests/language/null_aware/invocation_runtime_test.dart b/tests/language/null_aware/invocation_runtime_test.dart
index a4bd1d5..72d6942 100644
--- a/tests/language/null_aware/invocation_runtime_test.dart
+++ b/tests/language/null_aware/invocation_runtime_test.dart
@@ -32,7 +32,11 @@
   Expect.equals(1, c?.f(() => 1));
   // C?.m(...) is equivalent to C.m(...).
   Expect.equals(1, C?.staticF(() => 1));
+  //                ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
   Expect.equals(1, h.C?.staticF(() => 1));
+  //                  ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
 
   // The static type of o?.m(...) is the same as the static type of
   // o.m(...).
@@ -46,10 +50,14 @@
   }
   {
     int? i = C?.staticG(() => 1);
+    //        ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(1, i);
   }
   {
     int? i = h.C?.staticG(() => 1);
+    //          ^^
+    // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
     Expect.equals(1, i);
   }
 }
diff --git a/tests/language/null_aware/invocation_test.dart b/tests/language/null_aware/invocation_test.dart
index b1f38e6..1eaf015 100644
--- a/tests/language/null_aware/invocation_test.dart
+++ b/tests/language/null_aware/invocation_test.dart
@@ -35,7 +35,11 @@
 
   // C?.m(...) is equivalent to C.m(...).
   Expect.equals(1, C?.staticF(() => 1));
+  //                ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
   Expect.equals(1, h.C?.staticF(() => 1));
+  //                  ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
 
   // The static type of o?.m(...) is the same as the static type of
   // o.m(...).
@@ -51,15 +55,23 @@
   //            ^
   // [cfe] A value of type 'int?' can't be assigned to a variable of type 'String?'.
   { int? i = C?.staticG(() => 1); Expect.equals(1, i); }
+  //          ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
   { int? i = h.C?.staticG(() => 1); Expect.equals(1, i); }
+  //            ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
   { String? s = C?.staticG(() => null); Expect.equals(null, s); }
   //            ^^^^^^^^^^^^^^^^^^^^^^
   // [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
+  //             ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
   //               ^
   // [cfe] A value of type 'int?' can't be assigned to a variable of type 'String?'.
   { String? s = h.C?.staticG(() => null); Expect.equals(null, s); }
   //            ^^^^^^^^^^^^^^^^^^^^^^^^
   // [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
+  //               ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
   //                 ^
   // [cfe] A value of type 'int?' can't be assigned to a variable of type 'String?'.
 
@@ -84,10 +96,14 @@
 
   // Nor can it be used to access the toString method on the class Type.
   Expect.throwsNoSuchMethodError(() => C?.toString());
+  //                                    ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
   //                                      ^^^^^^^^
   // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD
   // [cfe] Method not found: 'C.toString'.
   Expect.throwsNoSuchMethodError(() => h.C?.toString());
+  //                                      ^^
+  // [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
   //                                        ^^^^^^^^
   // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD
   // [cfe] Method not found: 'C.toString'.