Split out two codes from STRICT_RAW_TYPE

Bug: https://github.com/dart-lang/sdk/issues/36445
Change-Id: Ic716d89b1a6d00945a74c7484f8301403b8ea371
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/101420
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
diff --git a/pkg/analyzer/lib/error/error.dart b/pkg/analyzer/lib/error/error.dart
index 59e0168..8902935 100644
--- a/pkg/analyzer/lib/error/error.dart
+++ b/pkg/analyzer/lib/error/error.dart
@@ -354,6 +354,8 @@
   HintCode.SDK_VERSION_SET_LITERAL,
   HintCode.SDK_VERSION_UI_AS_CODE,
   HintCode.STRICT_RAW_TYPE,
+  HintCode.STRICT_RAW_TYPE_IN_AS,
+  HintCode.STRICT_RAW_TYPE_IN_IS,
   HintCode.SUBTYPE_OF_SEALED_CLASS,
   HintCode.TYPE_CHECK_IS_NOT_NULL,
   HintCode.TYPE_CHECK_IS_NULL,
diff --git a/pkg/analyzer/lib/src/dart/error/hint_codes.dart b/pkg/analyzer/lib/src/dart/error/hint_codes.dart
index a11b0d2..a4376d3 100644
--- a/pkg/analyzer/lib/src/dart/error/hint_codes.dart
+++ b/pkg/analyzer/lib/src/dart/error/hint_codes.dart
@@ -653,6 +653,24 @@
       correction: "Use explicit type arguments for '{0}'.");
 
   /**
+   * When "strict-raw-types" is enabled, raw types must be inferred via the
+   * context type, or have type arguments.
+   */
+  static const HintCode STRICT_RAW_TYPE_IN_AS = HintCode(
+      'STRICT_RAW_TYPE_IN_AS',
+      "The generic type '{0}' should have explicit type arguments but doesn't.",
+      correction: "Use explicit type arguments for '{0}'.");
+
+  /**
+   * When "strict-raw-types" is enabled, raw types must be inferred via the
+   * context type, or have type arguments.
+   */
+  static const HintCode STRICT_RAW_TYPE_IN_IS = HintCode(
+      'STRICT_RAW_TYPE_IN_IS',
+      "The generic type '{0}' should have explicit type arguments but doesn't.",
+      correction: "Use explicit type arguments for '{0}'.");
+
+  /**
    * This hint is generated anywhere where a `@sealed` class or mixin is used as
    * a super-type of a class.
    */
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index 97ecdd6..dae105c 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -4810,6 +4810,17 @@
   /// or inferred type arguments. When that happens, it reports error code
   /// [StrongModeCode.STRICT_RAW_TYPE].
   void _checkForRawTypeName(TypeName node) {
+    AstNode parentEscapingTypeArguments(TypeName node) {
+      AstNode parent = node.parent;
+      while (parent is TypeArgumentList || parent is TypeName) {
+        if (parent.parent == null) {
+          return parent;
+        }
+        parent = parent.parent;
+      }
+      return parent;
+    }
+
     if (!_options.strictRawTypes || node == null) return;
     if (node.typeArguments != null) {
       // Type has explicit type arguments.
@@ -4817,8 +4828,17 @@
     }
     if (_isMissingTypeArguments(
         node, node.type, node.name.staticElement, null)) {
-      _errorReporter
-          .reportErrorForNode(HintCode.STRICT_RAW_TYPE, node, [node.type]);
+      AstNode unwrappedParent = parentEscapingTypeArguments(node);
+      if (unwrappedParent is AsExpression) {
+        _errorReporter.reportErrorForNode(
+            HintCode.STRICT_RAW_TYPE_IN_AS, node, [node.type]);
+      } else if (unwrappedParent is IsExpression) {
+        _errorReporter.reportErrorForNode(
+            HintCode.STRICT_RAW_TYPE_IN_IS, node, [node.type]);
+      } else {
+        _errorReporter
+            .reportErrorForNode(HintCode.STRICT_RAW_TYPE, node, [node.type]);
+      }
     }
   }
 
diff --git a/pkg/analyzer/test/src/task/strong/checker_test.dart b/pkg/analyzer/test/src/task/strong/checker_test.dart
index 40a67fd..46590c8 100644
--- a/pkg/analyzer/test/src/task/strong/checker_test.dart
+++ b/pkg/analyzer/test/src/task/strong/checker_test.dart
@@ -4414,14 +4414,22 @@
 
   {
     Object isCheck;
-    if (isCheck is /*info:STRICT_RAW_TYPE*/List) {}
-    if (isCheck is /*info:STRICT_RAW_TYPE*/C) {}
+    if (isCheck is /*info:STRICT_RAW_TYPE_IN_IS*/List) {}
+    if (isCheck is List</*info:STRICT_RAW_TYPE_IN_IS*/List>) {}
+    if (isCheck is /*info:STRICT_RAW_TYPE_IN_IS*/C) {}
 
     if (isCheck is List<dynamic>) {}
     if (isCheck is List<int>) {}
     if (isCheck is C<dynamic>) {}
     if (isCheck is C<int>) {}
   }
+
+  {
+    Object asCheck;
+    var asList = asCheck as /*info:STRICT_RAW_TYPE_IN_AS*/List;
+    var asMap = asCheck as Map<dynamic, /*info:STRICT_RAW_TYPE_IN_AS*/List>;
+    var asC = asCheck as /*info:STRICT_RAW_TYPE_IN_AS*/C;
+  }
 }
     ''');
     await check(strictRawTypes: true);
diff --git a/pkg/analyzer/test/src/task/strong/strong_test_helper.dart b/pkg/analyzer/test/src/task/strong/strong_test_helper.dart
index e066173..b78eabd 100644
--- a/pkg/analyzer/test/src/task/strong/strong_test_helper.dart
+++ b/pkg/analyzer/test/src/task/strong/strong_test_helper.dart
@@ -338,6 +338,8 @@
         return code.errorSeverity.ordinal > ErrorSeverity.INFO.ordinal ||
             code == HintCode.INFERENCE_FAILURE_ON_COLLECTION_LITERAL ||
             code == HintCode.INFERENCE_FAILURE_ON_INSTANCE_CREATION ||
+            code == HintCode.STRICT_RAW_TYPE_IN_AS ||
+            code == HintCode.STRICT_RAW_TYPE_IN_IS ||
             code == HintCode.STRICT_RAW_TYPE;
       }
       return true;