Skip to content

Commit 9750762

Browse files
committed
[csdiag] missing function call failure here as a backup
1 parent 1b62039 commit 9750762

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,6 +2316,25 @@ bool FailureDiagnosis::diagnoseContextualConversionError(
23162316
return false;
23172317
}
23182318

2319+
// If we're trying to convert something of type "() -> T" to T, then we
2320+
// probably meant to call the value.
2321+
if (auto srcFT = exprType->getAs<AnyFunctionType>()) {
2322+
if (srcFT->getParams().empty() &&
2323+
!isUnresolvedOrTypeVarType(srcFT->getResult()) &&
2324+
CS.TC.isConvertibleTo(srcFT->getResult(), contextualType, CS.DC)) {
2325+
2326+
auto locator = CS.getConstraintLocator(expr);
2327+
auto extendedLocator =
2328+
CS.getConstraintLocator(locator, ConstraintLocator::ContextualType);
2329+
ContextualFailure failure = ContextualFailure(
2330+
nullptr, CS, srcFT, contextualType, extendedLocator);
2331+
auto diagnosed = failure.diagnoseAsError();
2332+
assert(diagnosed && "Failed to produce contextual failure diagnostic");
2333+
(void)diagnosed;
2334+
return true;
2335+
}
2336+
}
2337+
23192338
// If this is a conversion from T to () in a call argument context, it is
23202339
// almost certainly an extra argument being passed in.
23212340
if (CTP == CTP_CallArgument && contextualType->isVoid()) {

lib/Sema/CSDiagnostics.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,11 @@ bool ContextualFailure::diagnoseMissingFunctionCall() const {
13571357
//
13581358
// Let's offer another fix-it to remove the '=' to turn the stored
13591359
// property into a computed property. If the variable is immutable, then
1360-
// replace the 'let' with a 'var'
1360+
// replace the 'let' with a 'var'.
1361+
1362+
if (getAnchor() && !isa<ClosureExpr>(getAnchor())) {
1363+
return true;
1364+
}
13611365

13621366
// First, check if the variable is declared top level or not. If it is
13631367
// not, then it means we're inside a decl like a class or an extension.

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,10 +1994,9 @@ repairFailures(ConstraintSystem &cs, Type lhs, Type rhs,
19941994
auto *fix = ContextualMismatch::create(cs, lhs, rhs,
19951995
cs.getConstraintLocator(locator));
19961996
conversionsOrFixes.push_back(fix);
1997-
break;
19981997
}
19991998

2000-
return;
1999+
break;
20012000
}
20022001

20032002
default:

0 commit comments

Comments
 (0)