Skip to content

Commit 49e8eee

Browse files
[CSDiagnostics] Handle CoercionExpr empty path in ContextualMismatch
1 parent 533d9ac commit 49e8eee

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,6 +1853,22 @@ bool ContextualFailure::diagnoseAsError() {
18531853
getFromType(), getToType());
18541854
return true;
18551855
}
1856+
1857+
if (auto *coerceExpr = dyn_cast<CoerceExpr>(anchor)) {
1858+
auto fromType = getFromType();
1859+
auto toType = getType(coerceExpr->getCastTypeLoc());
1860+
auto diagnostic =
1861+
getDiagnosticFor(CTP_CoerceOperand,
1862+
/*forProtocol=*/toType->isAnyExistentialType());
1863+
1864+
auto diag =
1865+
emitDiagnostic(anchor->getLoc(), *diagnostic, fromType, toType);
1866+
diag.highlight(anchor->getSourceRange());
1867+
1868+
(void)tryFixIts(diag);
1869+
1870+
return true;
1871+
}
18561872

18571873
return false;
18581874
}

0 commit comments

Comments
 (0)