Skip to content

Commit bb45b60

Browse files
committed
[CSDiagnostics] Add fix checks before could_not_infer_pack_element fallback
1 parent 971e3e9 commit bb45b60

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8202,20 +8202,17 @@ bool UnableToInferClosureReturnType::diagnoseAsError() {
82028202
bool UnableToInferGenericPackElementType::diagnoseAsError() {
82038203
auto *locator = getLocator();
82048204
auto path = locator->getPath();
8205-
8206-
const auto applyArgToParamElt =
8207-
(path.end() - 2)->getAs<LocatorPathElt::ApplyArgToParam>();
8208-
const auto packElementElt =
8209-
(path.end() - 1)->getAs<LocatorPathElt::PackElement>();
8210-
if (!applyArgToParamElt || !packElementElt) {
8211-
return false;
8212-
}
8205+
const auto packElementElt = (path.end() - 1)->getAs<LocatorPathElt::PackElement>();
82138206

82148207
if (isExpr<NilLiteralExpr>(getAnchor())) {
82158208
// `nil` appears as an element of generic pack params, let's record a
82168209
// specify contextual type for nil fix.
82178210
emitDiagnostic(diag::unresolved_nil_literal);
82188211
} else {
8212+
if (llvm::any_of(getSolution().Fixes, [&locator](const ConstraintFix *fix) {
8213+
return fix->getLocator() == locator;
8214+
}))
8215+
return false;
82198216
// unable to infer the type of an element of generic pack params
82208217
emitDiagnostic(diag::could_not_infer_pack_element,
82218218
packElementElt->getIndex());
@@ -8226,6 +8223,8 @@ bool UnableToInferGenericPackElementType::diagnoseAsError() {
82268223
if (auto *calleeLocator = getSolution().getCalleeLocator(locator)) {
82278224
if (const auto choice = getOverloadChoiceIfAvailable(calleeLocator)) {
82288225
if (auto *decl = choice->choice.getDeclOrNull()) {
8226+
const auto applyArgToParamElt =
8227+
(path.end() - 2)->getAs<LocatorPathElt::ApplyArgToParam>();
82298228
if (auto paramDecl =
82308229
getParameterAt(decl, applyArgToParamElt->getParamIdx())) {
82318230
emitDiagnosticAt(

0 commit comments

Comments
 (0)