Skip to content

Commit 63b9e8b

Browse files
committed
[BuilderTransform] Split build{Partial}Block matches while validating @resultBuilder attribute
1 parent b989057 commit 63b9e8b

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3938,19 +3938,22 @@ void AttributeChecker::visitPropertyWrapperAttr(PropertyWrapperAttr *attr) {
39383938
void AttributeChecker::visitResultBuilderAttr(ResultBuilderAttr *attr) {
39393939
auto *nominal = dyn_cast<NominalTypeDecl>(D);
39403940
auto &ctx = D->getASTContext();
3941-
SmallVector<ValueDecl *, 4> potentialMatches;
3941+
SmallVector<ValueDecl *, 4> buildBlockMatches;
3942+
SmallVector<ValueDecl *, 4> buildPartialBlockFirstMatches;
3943+
SmallVector<ValueDecl *, 4> buildPartialBlockAccumulatedMatches;
3944+
39423945
bool supportsBuildBlock = TypeChecker::typeSupportsBuilderOp(
39433946
nominal->getDeclaredType(), nominal, ctx.Id_buildBlock,
3944-
/*argLabels=*/{}, &potentialMatches);
3947+
/*argLabels=*/{}, &buildBlockMatches);
3948+
39453949
bool supportsBuildPartialBlock =
39463950
TypeChecker::typeSupportsBuilderOp(
3947-
nominal->getDeclaredType(), nominal,
3948-
ctx.Id_buildPartialBlock,
3949-
/*argLabels=*/{ctx.Id_first}, &potentialMatches) &&
3951+
nominal->getDeclaredType(), nominal, ctx.Id_buildPartialBlock,
3952+
/*argLabels=*/{ctx.Id_first}, &buildPartialBlockFirstMatches) &&
39503953
TypeChecker::typeSupportsBuilderOp(
3951-
nominal->getDeclaredType(), nominal,
3952-
ctx.Id_buildPartialBlock,
3953-
/*argLabels=*/{ctx.Id_accumulated, ctx.Id_next}, &potentialMatches);
3954+
nominal->getDeclaredType(), nominal, ctx.Id_buildPartialBlock,
3955+
/*argLabels=*/{ctx.Id_accumulated, ctx.Id_next},
3956+
&buildPartialBlockAccumulatedMatches);
39543957

39553958
if (!supportsBuildBlock && !supportsBuildPartialBlock) {
39563959
{
@@ -3964,7 +3967,7 @@ void AttributeChecker::visitResultBuilderAttr(ResultBuilderAttr *attr) {
39643967
Type componentType;
39653968
std::tie(buildInsertionLoc, stubIndent, componentType) =
39663969
determineResultBuilderBuildFixItInfo(nominal);
3967-
if (buildInsertionLoc.isValid() && potentialMatches.empty()) {
3970+
if (buildInsertionLoc.isValid() && buildBlockMatches.empty()) {
39683971
std::string fixItString;
39693972
{
39703973
llvm::raw_string_ostream out(fixItString);
@@ -3980,7 +3983,7 @@ void AttributeChecker::visitResultBuilderAttr(ResultBuilderAttr *attr) {
39803983

39813984
// For any close matches, attempt to explain to the user why they aren't
39823985
// valid.
3983-
for (auto *member : potentialMatches) {
3986+
for (auto *member : buildBlockMatches) {
39843987
if (member->isStatic() && isa<FuncDecl>(member))
39853988
continue;
39863989

0 commit comments

Comments
 (0)