mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[CSDiagnostics] Handle CoercionExpr empty path in ContextualMismatch
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user