Remove MIXIN_INFERENCE_NO_POSSIBLE_SUBSTITUTION.

When we cannot infer types, we leave `M<dynamic>` and report
other errors.

Change-Id: Ice6ebabf4bc844ee21aa1cc842e6496fcf8b3c11
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/226660
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/error/error.dart b/pkg/analyzer/lib/error/error.dart
index 441903a..3555ef1 100644
--- a/pkg/analyzer/lib/error/error.dart
+++ b/pkg/analyzer/lib/error/error.dart
@@ -293,9 +293,6 @@
   CompileTimeErrorCode.MIXIN_APPLICATION_NOT_IMPLEMENTED_INTERFACE,
   CompileTimeErrorCode.MIXIN_CLASS_DECLARES_CONSTRUCTOR,
   CompileTimeErrorCode.MIXIN_DEFERRED_CLASS,
-  CompileTimeErrorCode.MIXIN_INFERENCE_INCONSISTENT_MATCHING_CLASSES,
-  CompileTimeErrorCode.MIXIN_INFERENCE_NO_MATCHING_CLASS,
-  CompileTimeErrorCode.MIXIN_INFERENCE_NO_POSSIBLE_SUBSTITUTION,
   CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT,
   CompileTimeErrorCode.MIXIN_INSTANTIATE,
   CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS,
diff --git a/pkg/analyzer/lib/src/error/codes.g.dart b/pkg/analyzer/lib/src/error/codes.g.dart
index 6033cde..0bbf444 100644
--- a/pkg/analyzer/lib/src/error/codes.g.dart
+++ b/pkg/analyzer/lib/src/error/codes.g.dart
@@ -8912,29 +8912,6 @@
     uniqueName: 'MIXIN_DEFERRED_CLASS',
   );
 
-  static const CompileTimeErrorCode
-      MIXIN_INFERENCE_INCONSISTENT_MATCHING_CLASSES = CompileTimeErrorCode(
-    'MIXIN_INFERENCE_INCONSISTENT_MATCHING_CLASSES',
-    "Type parameters couldn't be inferred for the mixin '{0}' because the base "
-        "class implements the mixin's supertype constraint '{1}' in multiple "
-        "conflicting ways",
-  );
-
-  static const CompileTimeErrorCode MIXIN_INFERENCE_NO_MATCHING_CLASS =
-      CompileTimeErrorCode(
-    'MIXIN_INFERENCE_NO_MATCHING_CLASS',
-    "Type parameters couldn't be inferred for the mixin '{0}' because the base "
-        "class doesn't implement the mixin's supertype constraint '{1}'",
-  );
-
-  static const CompileTimeErrorCode MIXIN_INFERENCE_NO_POSSIBLE_SUBSTITUTION =
-      CompileTimeErrorCode(
-    'MIXIN_INFERENCE_NO_POSSIBLE_SUBSTITUTION',
-    "Type parameters couldn't be inferred for the mixin '{0}' because no type "
-        "parameter substitution could be found matching the mixin's supertype "
-        "constraints",
-  );
-
   /**
    * Parameters:
    * 0: the name of the mixin that is invalid
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index 2582044..56a90a4 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -1329,7 +1329,6 @@
           CompileTimeErrorCode.IMPLEMENTS_REPEATED);
       _checkImplementsSuperClass(implementsClause);
       _checkMixinsSuperClass(withClause);
-      _checkMixinInference(node, withClause);
       _checkForMixinWithConflictingPrivateMember(withClause, superclass);
       _checkForConflictingGenerics(node);
       if (node is ClassDeclaration) {
@@ -4758,56 +4757,6 @@
     }
   }
 
-  void _checkMixinInference(
-      NamedCompilationUnitMember node, WithClause? withClause) {
-    if (withClause == null) {
-      return;
-    }
-    var classElement = node.declaredElement as ClassElement;
-    var supertype = classElement.supertype;
-
-    var interfacesMerger = InterfacesMerger(typeSystem);
-    interfacesMerger.addWithSupertypes(supertype);
-
-    for (var namedType in withClause.mixinTypes2) {
-      var mixinType = namedType.type;
-      if (mixinType is InterfaceType) {
-        var mixinElement = mixinType.element;
-        if (namedType.typeArguments == null) {
-          var mixinSupertypeConstraints = typeSystem
-              .gatherMixinSupertypeConstraintsForInference(mixinElement);
-          if (mixinSupertypeConstraints.isNotEmpty) {
-            var matchingInterfaceTypes = _findInterfaceTypesForConstraints(
-              namedType,
-              mixinSupertypeConstraints,
-              interfacesMerger.typeList,
-            );
-            if (matchingInterfaceTypes != null) {
-              // Try to pattern match matchingInterfaceType against
-              // mixinSupertypeConstraint to find the correct set of type
-              // parameters to apply to the mixin.
-              var inferredTypeArguments = typeSystem.matchSupertypeConstraints(
-                mixinElement,
-                mixinSupertypeConstraints,
-                matchingInterfaceTypes,
-                genericMetadataIsEnabled: _currentLibrary.featureSet
-                    .isEnabled(Feature.generic_metadata),
-              );
-              if (inferredTypeArguments == null) {
-                errorReporter.reportErrorForToken(
-                    CompileTimeErrorCode
-                        .MIXIN_INFERENCE_NO_POSSIBLE_SUBSTITUTION,
-                    namedType.name.beginToken,
-                    [namedType]);
-              }
-            }
-          }
-        }
-        interfacesMerger.addWithSupertypes(mixinType);
-      }
-    }
-  }
-
   /// Checks the class for problems with the superclass, mixins, or implemented
   /// interfaces.
   void _checkMixinInheritance(MixinDeclaration node, OnClause? onClause,
@@ -4965,51 +4914,6 @@
     }
   }
 
-  InterfaceType? _findInterfaceTypeForMixin(NamedType mixin,
-      InterfaceType supertypeConstraint, List<InterfaceType> interfaceTypes) {
-    var element = supertypeConstraint.element;
-    InterfaceType? foundInterfaceType;
-    for (var interfaceType in interfaceTypes) {
-      if (interfaceType.element != element) continue;
-      if (foundInterfaceType == null) {
-        foundInterfaceType = interfaceType;
-      } else {
-        if (interfaceType != foundInterfaceType) {
-          errorReporter.reportErrorForToken(
-              CompileTimeErrorCode
-                  .MIXIN_INFERENCE_INCONSISTENT_MATCHING_CLASSES,
-              mixin.name.beginToken,
-              [mixin, supertypeConstraint]);
-        }
-      }
-    }
-    if (foundInterfaceType == null) {
-      errorReporter.reportErrorForToken(
-          CompileTimeErrorCode.MIXIN_INFERENCE_NO_MATCHING_CLASS,
-          mixin.name.beginToken,
-          [mixin, supertypeConstraint]);
-    }
-    return foundInterfaceType;
-  }
-
-  List<InterfaceType>? _findInterfaceTypesForConstraints(
-      NamedType mixin,
-      List<InterfaceType> supertypeConstraints,
-      List<InterfaceType> interfaceTypes) {
-    var result = <InterfaceType>[];
-    for (var constraint in supertypeConstraints) {
-      var interfaceType =
-          _findInterfaceTypeForMixin(mixin, constraint, interfaceTypes);
-      if (interfaceType == null) {
-        // No matching interface type found, so inference fails.  The error has
-        // already been reported.
-        return null;
-      }
-      result.add(interfaceType);
-    }
-    return result;
-  }
-
   /// Given an [expression] in a switch case whose value is expected to be an
   /// enum constant, return the name of the constant.
   String? _getConstantName(Expression expression) {
diff --git a/pkg/analyzer/messages.yaml b/pkg/analyzer/messages.yaml
index 3b2abaf..22d6045 100644
--- a/pkg/analyzer/messages.yaml
+++ b/pkg/analyzer/messages.yaml
@@ -7705,12 +7705,6 @@
 
       class B extends A {}
       ```
-  MIXIN_INFERENCE_INCONSISTENT_MATCHING_CLASSES:
-    problemMessage: "Type parameters couldn't be inferred for the mixin '{0}' because the base class implements the mixin's supertype constraint '{1}' in multiple conflicting ways"
-  MIXIN_INFERENCE_NO_MATCHING_CLASS:
-    problemMessage: "Type parameters couldn't be inferred for the mixin '{0}' because the base class doesn't implement the mixin's supertype constraint '{1}'"
-  MIXIN_INFERENCE_NO_POSSIBLE_SUBSTITUTION:
-    problemMessage: "Type parameters couldn't be inferred for the mixin '{0}' because no type parameter substitution could be found matching the mixin's supertype constraints"
   MIXIN_INHERITS_FROM_NOT_OBJECT:
     problemMessage: "The class '{0}' can't be used as a mixin because it extends a class other than 'Object'."
     hasPublishedDocs: true