[NFC] Sema: Refactor for recursive MemberTypeRepr representation

This commit is contained in:
Anthony Latsis
2023-12-05 12:40:12 +03:00
parent bbf03c0481
commit 14d38e7f01
4 changed files with 28 additions and 17 deletions

View File

@@ -6757,10 +6757,11 @@ void MissingGenericArgumentsFailure::emitGenericSignatureNote(
auto diagnostic = emitDiagnosticAt(
baseType->getLoc(), diag::unbound_generic_parameter_explicit_fix);
if (auto *genericTy = dyn_cast<GenericIdentTypeRepr>(baseType)) {
// If some of the eneric arguments have been specified, we need to
auto *declRefTR = dyn_cast<DeclRefTypeRepr>(baseType);
if (declRefTR && declRefTR->getAngleBrackets().isValid()) {
// If some of the generic arguments have been specified, we need to
// replace existing signature with a new one.
diagnostic.fixItReplace(genericTy->getAngleBrackets(), paramsAsString);
diagnostic.fixItReplace(declRefTR->getAngleBrackets(), paramsAsString);
} else {
// Otherwise we can simply insert new generic signature.
diagnostic.fixItInsertAfter(baseType->getEndLoc(), paramsAsString);
@@ -6770,7 +6771,7 @@ void MissingGenericArgumentsFailure::emitGenericSignatureNote(
bool MissingGenericArgumentsFailure::findArgumentLocations(
llvm::function_ref<void(TypeRepr *, GenericTypeParamType *)> callback) {
using Callback = llvm::function_ref<void(TypeRepr *, GenericTypeParamType *)>;
using Callback = decltype(callback);
auto *const typeRepr = [this]() -> TypeRepr * {
const auto anchor = getRawAnchor();
@@ -6799,14 +6800,14 @@ bool MissingGenericArgumentsFailure::findArgumentLocations(
}
PreWalkAction walkToTypeReprPre(TypeRepr *T) override {
if (Params.empty())
return Action::SkipNode();
if (allParamsAssigned())
return Action::Stop();
auto *ident = dyn_cast<IdentTypeRepr>(T);
if (!ident)
auto *declRefTR = dyn_cast<DeclRefTypeRepr>(T);
if (!declRefTR)
return Action::Continue();
auto *decl = dyn_cast_or_null<GenericTypeDecl>(ident->getBoundDecl());
auto *decl = dyn_cast_or_null<GenericTypeDecl>(declRefTR->getBoundDecl());
if (!decl)
return Action::Continue();
@@ -6817,9 +6818,8 @@ bool MissingGenericArgumentsFailure::findArgumentLocations(
// There could a situation like `S<S>()`, so we need to be
// careful not to point at first `S` because it has all of
// its generic parameters specified.
if (auto *generic = dyn_cast<GenericIdentTypeRepr>(ident)) {
if (paramList->size() == generic->getNumGenericArgs())
return Action::Continue();
if (paramList->size() == declRefTR->getNumGenericArgs()) {
return Action::Continue();
}
for (auto *candidate : paramList->getParams()) {
@@ -6829,7 +6829,7 @@ bool MissingGenericArgumentsFailure::findArgumentLocations(
});
if (result != Params.end()) {
Fn(ident, *result);
Fn(declRefTR, *result);
Params.erase(result);
}
}