Sema: Require CS to certify conversions associated w/ existential member accesses

This commit is contained in:
Anthony Latsis
2024-04-18 18:18:23 +03:00
parent 52d613e2c2
commit d18a7fd073
8 changed files with 184 additions and 74 deletions

View File

@@ -5620,6 +5620,23 @@ bool ConstraintSystem::repairFailures(
}
}
// If there is a conversion associated with an existential member access
// along the path, the problem is that the constraint system does not support
// the (formally sane) upcast required to access the member.
if (llvm::find_if(path, [](const LocatorPathElt &elt) -> bool {
return elt.is<LocatorPathElt::ExistentialMemberAccessConversion>();
}) != path.end()) {
if (auto overload = findSelectedOverloadFor(castToExpr(anchor))) {
auto &choice = overload->choice;
conversionsOrFixes.push_back(AllowMemberRefOnExistential::create(
*this, choice.getBaseType(), choice.getDecl(),
DeclNameRef(choice.getDecl()->getName()),
getConstraintLocator(locator)));
return true;
}
}
auto elt = path.back();
switch (elt.getKind()) {
case ConstraintLocator::LValueConversion: {
@@ -15153,7 +15170,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
case FixKind::GenericArgumentsMismatch:
case FixKind::AllowConcreteTypeSpecialization:
case FixKind::IgnoreGenericSpecializationArityMismatch:
case FixKind::IgnoreKeyPathSubscriptIndexMismatch: {
case FixKind::IgnoreKeyPathSubscriptIndexMismatch:
case FixKind::AllowMemberRefOnExistential: {
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
}
case FixKind::IgnoreThrownErrorMismatch: {
@@ -15376,7 +15394,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
case FixKind::RemoveCall:
case FixKind::RemoveUnwrap:
case FixKind::DefineMemberBasedOnUse:
case FixKind::AllowMemberRefOnExistential:
case FixKind::AllowTypeOrInstanceMember:
case FixKind::AllowInvalidPartialApplication:
case FixKind::AllowInvalidInitRef: