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>
This commit is contained in:
committed by
Commit Bot
parent
c997e57c99
commit
edbf6300a1
@@ -293,9 +293,6 @@ const List<ErrorCode> 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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1329,7 +1329,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
|
||||
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>
|
||||
}
|
||||
}
|
||||
|
||||
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<void>
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user