Skip to content

Commit 36a50c7

Browse files
committed
[ResultBuilder] Don't run syntactic diagnostics on transformed do statements
Visiting of transformed `do` shouldn't run syntatic diagnostics because they are going to be performed by `visit` that called `visitDoStmt`.
1 parent 697dfba commit 36a50c7

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

lib/Sema/CSSyntacticElement.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,13 +1290,17 @@ class SyntacticElementSolutionApplication
12901290
virtual ~SyntacticElementSolutionApplication() {}
12911291

12921292
private:
1293-
ASTNode visit(Stmt *S) {
1293+
1294+
ASTNode visit(Stmt *S, bool performSyntacticDiagnostics = true) {
12941295
auto rewritten = ASTVisitor::visit(S);
12951296
if (!rewritten)
12961297
return {};
12971298

1298-
if (auto *stmt = getAsStmt(rewritten))
1299-
performStmtDiagnostics(stmt, context.getAsDeclContext());
1299+
if (performSyntacticDiagnostics) {
1300+
if (auto *stmt = getAsStmt(rewritten)) {
1301+
performStmtDiagnostics(stmt, context.getAsDeclContext());
1302+
}
1303+
}
13001304

13011305
return rewritten;
13021306
}
@@ -1819,8 +1823,9 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
18191823

18201824
private:
18211825
ASTNode visitDoStmt(DoStmt *doStmt) override {
1822-
if (auto transformed = transformDo(doStmt))
1823-
return visit(transformed.get());
1826+
if (auto transformed = transformDo(doStmt)) {
1827+
return visit(transformed.get(), /*performSyntacticDiagnostics=*/false);
1828+
}
18241829

18251830
auto newBody = visit(doStmt->getBody());
18261831
if (!newBody)

validation-test/Sema/SwiftUI/mixed_swiftui_and_multistatement_closures.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ struct MyView : View {
3535
switch (status) {
3636
case .complete:
3737
ForEach(items, id: \.self) { item in
38-
if let question = item.question,
39-
let answer = item.answer {
38+
if let question = item.question, // expected-error {{initializer for conditional binding must have Optional type, not 'String'}}
39+
let answer = item.answer { // expected-error {{initializer for conditional binding must have Optional type, not 'Int'}}
4040
ItemView {
4141
currItem.question = question
4242
currItem.answer = answer

0 commit comments

Comments
 (0)