Improve diagnoses of generic specializations

Always add constraints, find fixes during simplify.
New separate fix for allow generic function specialization.
Improve parse heuristic for isGenericTypeDisambiguatingToken.
This commit is contained in:
Greg Titus
2024-07-21 06:21:21 -07:00
parent 0350023bb0
commit 6e917b567a
12 changed files with 164 additions and 76 deletions

View File

@@ -13926,6 +13926,8 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
// Bail out if we haven't selected an overload yet.
auto simplifiedBoundType = simplifyType(type1, flags);
if (simplifiedBoundType->isPlaceholder())
return SolutionKind::Solved;
if (simplifiedBoundType->isTypeVariableOrMember())
return formUnsolved();
@@ -14018,13 +14020,12 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
}
}
if (!decl->getAsGenericContext())
return SolutionKind::Error;
auto genericParams = getGenericParams(decl);
if (!genericParams) {
// FIXME: Record an error here that we're ignoring the parameters.
return SolutionKind::Solved;
if (!decl->getAsGenericContext() || !genericParams) {
return recordFix(AllowConcreteTypeSpecialization::create(
*this, type1, getConstraintLocator(locator)))
? SolutionKind::Error
: SolutionKind::Solved;
}
// Map the generic parameters we have over to their opened types.
@@ -14057,12 +14058,14 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
}
}
if (openedGenericParams.empty()) {
// FIXME: We could support explicit function specialization.
if (openedGenericParams.empty() ||
(isa<AbstractFunctionDecl>(decl) && !hasParameterPack)) {
if (!shouldAttemptFixes())
return SolutionKind::Error;
return recordFix(AllowConcreteTypeSpecialization::create(
*this, type1, getConstraintLocator(locator)))
return recordFix(AllowGenericFunctionSpecialization::create(
*this, decl, getConstraintLocator(locator)))
? SolutionKind::Error
: SolutionKind::Solved;
}
@@ -15193,6 +15196,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
case FixKind::AllowAssociatedValueMismatch:
case FixKind::GenericArgumentsMismatch:
case FixKind::AllowConcreteTypeSpecialization:
case FixKind::AllowGenericFunctionSpecialization:
case FixKind::IgnoreGenericSpecializationArityMismatch:
case FixKind::IgnoreKeyPathSubscriptIndexMismatch:
case FixKind::AllowMemberRefOnExistential: {