Skip to content

Commit 0202785

Browse files
committed
[ResultBuilder] Diagnostics: Don't diagnose unsupported statement if it is a brace
Brace statement are marked unsuported only if there is no appropriate overload of `buildBlock` and that is diagnosed inline.
1 parent 99acd8c commit 0202785

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6203,19 +6203,6 @@ void SkipUnhandledConstructInResultBuilderFailure::diagnosePrimary(
62036203
}
62046204

62056205
if (auto stmt = unhandled.dyn_cast<Stmt *>()) {
6206-
if (auto *switchStmt = getAsStmt<SwitchStmt>(stmt)) {
6207-
auto caseStmts = switchStmt->getCases();
6208-
if (caseStmts.empty())
6209-
return;
6210-
}
6211-
6212-
// Empty case statements are diagnosed by parser.
6213-
if (auto *caseStmt = getAsStmt<CaseStmt>(stmt)) {
6214-
auto *body = caseStmt->getBody();
6215-
if (body->getNumElements() == 0)
6216-
return;
6217-
}
6218-
62196206
emitDiagnostic(asNote ? diag::note_result_builder_control_flow
62206207
: diag::result_builder_control_flow,
62216208
builder->getName());
@@ -6287,6 +6274,27 @@ void SkipUnhandledConstructInResultBuilderFailure::diagnosePrimary(
62876274
}
62886275

62896276
bool SkipUnhandledConstructInResultBuilderFailure::diagnoseAsError() {
6277+
// Following errors are already diagnosed:
6278+
// - brace statement - error related to absence of appropriate buildBlock
6279+
// - switch/case statements - empty body
6280+
if (auto *stmt = unhandled.dyn_cast<Stmt *>()) {
6281+
if (isa<BraceStmt>(stmt))
6282+
return true;
6283+
6284+
if (auto *switchStmt = getAsStmt<SwitchStmt>(stmt)) {
6285+
auto caseStmts = switchStmt->getCases();
6286+
if (caseStmts.empty())
6287+
return true;
6288+
}
6289+
6290+
// Empty case statements are diagnosed by parser.
6291+
if (auto *caseStmt = getAsStmt<CaseStmt>(stmt)) {
6292+
auto *body = caseStmt->getBody();
6293+
if (body->getNumElements() == 0)
6294+
return true;
6295+
}
6296+
}
6297+
62906298
diagnosePrimary(/*asNote=*/false);
62916299
emitDiagnosticAt(builder, diag::kind_declname_declared_here,
62926300
builder->getDescriptiveKind(), builder->getName());

0 commit comments

Comments
 (0)