diff --git a/pkg/analyzer/lib/error/error.dart b/pkg/analyzer/lib/error/error.dart index 441903a7316..3555ef1f30c 100644 --- a/pkg/analyzer/lib/error/error.dart +++ b/pkg/analyzer/lib/error/error.dart @@ -293,9 +293,6 @@ const List errorCodeValues = [ 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 6033cde9ddb..0bbf444b6ba 100644 --- a/pkg/analyzer/lib/src/error/codes.g.dart +++ b/pkg/analyzer/lib/src/error/codes.g.dart @@ -8912,29 +8912,6 @@ class CompileTimeErrorCode extends AnalyzerErrorCode { 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 25820443c34..56a90a4011a 100644 --- a/pkg/analyzer/lib/src/generated/error_verifier.dart +++ b/pkg/analyzer/lib/src/generated/error_verifier.dart @@ -1329,7 +1329,6 @@ class ErrorVerifier extends RecursiveAstVisitor CompileTimeErrorCode.IMPLEMENTS_REPEATED); _checkImplementsSuperClass(implementsClause); _checkMixinsSuperClass(withClause); - _checkMixinInference(node, withClause); _checkForMixinWithConflictingPrivateMember(withClause, superclass); _checkForConflictingGenerics(node); if (node is ClassDeclaration) { @@ -4758,56 +4757,6 @@ class ErrorVerifier extends RecursiveAstVisitor } } - 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 @@ class ErrorVerifier extends RecursiveAstVisitor } } - InterfaceType? _findInterfaceTypeForMixin(NamedType mixin, - InterfaceType supertypeConstraint, List 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? _findInterfaceTypesForConstraints( - NamedType mixin, - List supertypeConstraints, - List interfaceTypes) { - var result = []; - 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 3b2abaf9afd..22d6045546d 100644 --- a/pkg/analyzer/messages.yaml +++ b/pkg/analyzer/messages.yaml @@ -7705,12 +7705,6 @@ CompileTimeErrorCode: 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