Skip to content

Commit 0d07cd8

Browse files
committed
[ConstraintSystem] Detect and diagnose contextual mismatches in key path components
1 parent 57c7702 commit 0d07cd8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1888,7 +1888,16 @@ bool ContextualFailure::diagnoseAsError() {
18881888
if (diagnoseConversionToNil())
18891889
return true;
18901890

1891-
assert(!path.empty());
1891+
if (path.empty()) {
1892+
if (auto *KPE = dyn_cast<KeyPathExpr>(anchor)) {
1893+
emitDiagnostic(KPE->getLoc(),
1894+
diag::expr_smart_keypath_value_covert_to_contextual_type,
1895+
getFromType(), getToType());
1896+
return true;
1897+
}
1898+
1899+
return false;
1900+
}
18921901

18931902
if (diagnoseMissingFunctionCall())
18941903
return true;

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,10 @@ bool ConstraintSystem::repairFailures(
25232523
auto *fnType = lhs->getAs<FunctionType>();
25242524
if (fnType && fnType->getResult()->isEqual(rhs))
25252525
return true;
2526+
2527+
conversionsOrFixes.push_back(IgnoreContextualType::create(
2528+
*this, lhs, rhs, getConstraintLocator(locator)));
2529+
return true;
25262530
}
25272531

25282532
if (auto *AE = dyn_cast<AssignExpr>(anchor)) {

0 commit comments

Comments
 (0)