[ConstraintSystem] Diagnose conformance failure with base of a static member lookup

Produce a tailored diagnostic when it has been established that
base type of a static member reference on protocol metatype doesn't
conform to a required protocol.
This commit is contained in:
Pavel Yaskevich
2020-10-30 13:46:30 -07:00
parent 5758ae2bcc
commit d1ab178471
2 changed files with 70 additions and 44 deletions

View File

@@ -1577,15 +1577,21 @@ ConstraintSystem::getTypeOfMemberReference(
Type baseOpenedTy = baseObjTy;
if (isStaticMemberRefOnProtocol) {
// Member type with Self applied.
auto refTy = openedType->castTo<FunctionType>()->getResult();
// If member is a function type, let's use its result type
// since it could be either a static method or a property
// which returns a function type.
if (auto *funcTy = refTy->getAs<FunctionType>())
baseOpenedTy = funcTy->getResult();
else
baseOpenedTy = refTy;
// In diagnostic mode, let's not try to replace base type
// if there is already a known issue associated with this
// reference e.g. it might be incorrect initializer call
// or result type is invalid.
if (!(shouldAttemptFixes() && hasFixFor(getConstraintLocator(locator)))) {
// Member type with Self applied.
auto refTy = openedType->castTo<FunctionType>()->getResult();
// If member is a function type, let's use its result type
// since it could be either a static method or a property
// which returns a function type.
if (auto *funcTy = refTy->getAs<FunctionType>())
baseOpenedTy = funcTy->getResult();
else
baseOpenedTy = refTy;
}
} else if (baseObjTy->isExistentialType()) {
auto openedArchetype = OpenedArchetypeType::get(baseObjTy);
OpenedExistentialTypes.push_back(