Merge pull request #71701 from li3zhen1/my-branch

[CSDiagnostics] Add diagnostics for holes in generic parameter packs
This commit is contained in:
Pavel Yaskevich
2024-03-06 11:58:19 -08:00
committed by GitHub
11 changed files with 156 additions and 1 deletions

View File

@@ -8200,6 +8200,45 @@ bool UnableToInferClosureReturnType::diagnoseAsError() {
return true;
}
bool UnableToInferGenericPackElementType::diagnoseAsError() {
auto *locator = getLocator();
auto path = locator->getPath();
auto packElementElt = locator->getLastElementAs<LocatorPathElt::PackElement>();
assert(packElementElt && "Expected path to end with a pack element locator");
if (isExpr<NilLiteralExpr>(getAnchor())) {
// `nil` appears as an element of generic pack params, let's record a
// specify contextual type for nil fix.
emitDiagnostic(diag::unresolved_nil_literal);
} else {
// unable to infer the type of an element of generic pack params
emitDiagnostic(diag::could_not_infer_pack_element,
packElementElt->getIndex());
}
if (isExpr<ApplyExpr>(locator->getAnchor())) {
// emit callee side diagnostics
if (auto *calleeLocator = getSolution().getCalleeLocator(locator)) {
if (const auto choice = getOverloadChoiceIfAvailable(calleeLocator)) {
if (auto *decl = choice->choice.getDeclOrNull()) {
if (auto applyArgToParamElt =
locator->findFirst<LocatorPathElt::ApplyArgToParam>()) {
if (auto paramDecl =
getParameterAt(decl, applyArgToParamElt->getParamIdx())) {
emitDiagnosticAt(
paramDecl->getLoc(), diag::note_in_opening_pack_element,
packElementElt->getIndex(), paramDecl->getNameStr());
}
}
}
}
}
}
return true;
}
static std::pair<StringRef, StringRef>
getImportModuleAndDefaultType(const ASTContext &ctx,
const ObjectLiteralExpr *expr) {