[CSDiagnostics] Handle CoercionExpr empty path in ContextualMismatch

This commit is contained in:
Luciano Almeida
2020-01-04 15:58:52 -03:00
parent 533d9acf73
commit 49e8eee3e5

View File

@@ -1853,6 +1853,22 @@ bool ContextualFailure::diagnoseAsError() {
getFromType(), getToType());
return true;
}
if (auto *coerceExpr = dyn_cast<CoerceExpr>(anchor)) {
auto fromType = getFromType();
auto toType = getType(coerceExpr->getCastTypeLoc());
auto diagnostic =
getDiagnosticFor(CTP_CoerceOperand,
/*forProtocol=*/toType->isAnyExistentialType());
auto diag =
emitDiagnostic(anchor->getLoc(), *diagnostic, fromType, toType);
diag.highlight(anchor->getSourceRange());
(void)tryFixIts(diag);
return true;
}
return false;
}