mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Diagnostics] Diagnose use of one or more return statements in a result builder body
This commit is contained in:
@@ -7052,3 +7052,22 @@ bool ReferenceToInvalidDeclaration::diagnoseAsError() {
|
||||
emitDiagnosticAt(decl, diag::decl_declared_here, decl->getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InvalidReturnInResultBuilderBody::diagnoseAsError() {
|
||||
auto *closure = castToExpr<ClosureExpr>(getAnchor());
|
||||
|
||||
auto returnStmts = TypeChecker::findReturnStatements(closure);
|
||||
assert(!returnStmts.empty());
|
||||
|
||||
auto loc = returnStmts.front()->getReturnLoc();
|
||||
emitDiagnosticAt(loc, diag::result_builder_disabled_by_return, BuilderType);
|
||||
|
||||
// Note that one can remove all of the return statements.
|
||||
{
|
||||
auto diag = emitDiagnosticAt(loc, diag::result_builder_remove_returns);
|
||||
for (auto returnStmt : returnStmts)
|
||||
diag.fixItRemove(returnStmt->getReturnLoc());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user