Skip to content

Commit ccc0c8b

Browse files
authored
Merge pull request #38177 from xedin/rdar-79746785
[ResultBuilders] Allow pre-check to look into single-statement closures
2 parents bb32a75 + 3374500 commit ccc0c8b

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,12 +1869,8 @@ class PreCheckResultBuilderApplication : public ASTWalker {
18691869
E, DC, /*replaceInvalidRefsWithErrors=*/true);
18701870
HasError |= transaction.hasErrors();
18711871

1872-
if (!HasError) {
1873-
E->forEachChildExpr([&](Expr *expr) {
1874-
HasError |= isa<ErrorExpr>(expr);
1875-
return HasError ? nullptr : expr;
1876-
});
1877-
}
1872+
if (!HasError)
1873+
HasError |= containsErrorExpr(E);
18781874

18791875
if (SuppressDiagnostics)
18801876
transaction.abort();
@@ -1896,6 +1892,29 @@ class PreCheckResultBuilderApplication : public ASTWalker {
18961892
return std::make_pair(true, S);
18971893
}
18981894

1895+
/// Check whether given expression (including single-statement
1896+
/// closures) contains `ErrorExpr` as one of its sub-expressions.
1897+
bool containsErrorExpr(Expr *expr) {
1898+
bool hasError = false;
1899+
1900+
expr->forEachChildExpr([&](Expr *expr) -> Expr * {
1901+
hasError |= isa<ErrorExpr>(expr);
1902+
if (hasError)
1903+
return nullptr;
1904+
1905+
if (auto *closure = dyn_cast<ClosureExpr>(expr)) {
1906+
if (shouldTypeCheckInEnclosingExpression(closure)) {
1907+
hasError |= containsErrorExpr(closure->getSingleExpressionBody());
1908+
return hasError ? nullptr : expr;
1909+
}
1910+
}
1911+
1912+
return expr;
1913+
});
1914+
1915+
return hasError;
1916+
}
1917+
18991918
/// Ignore patterns.
19001919
std::pair<bool, Pattern*> walkToPatternPre(Pattern *pat) override {
19011920
return { false, pat };

test/Constraints/result_builder_diags.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,4 +727,13 @@ struct TuplifiedStructWithInvalidClosure {
727727
42
728728
}
729729
}
730+
731+
@TupleBuilder var nestedErrorsDiagnosedByParser: some Any {
732+
tuplify(true) { _ in
733+
tuplify { _ in
734+
self. // expected-error {{expected member name following '.'}}
735+
}
736+
42
737+
}
738+
}
730739
}

0 commit comments

Comments
 (0)