Skip to content

Commit 60c2053

Browse files
committed
[ConstraintSystem] NFC: Extract isResultBuilderMethodReference into a namespace method
1 parent e7475c8 commit 60c2053

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

Diff for: include/swift/Sema/ConstraintSystem.h

+3
Original file line numberDiff line numberDiff line change
@@ -6448,6 +6448,9 @@ bool containsPackExpansionType(TupleType *tuple);
64486448
/// \returns null if \c type is not a single unlabeled pack expansion tuple.
64496449
Type getPatternTypeOfSingleUnlabeledPackExpansionTuple(Type type);
64506450

6451+
/// Check whether this is a reference to one of the special result builder
6452+
/// methods prefixed with `build*` i.e. `buildBlock`, `buildExpression` etc.
6453+
bool isResultBuilderMethodReference(ASTContext &, UnresolvedDotExpr *);
64516454
} // end namespace constraints
64526455

64536456
template<typename ...Args>

Diff for: lib/Sema/ConstraintSystem.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -5496,21 +5496,6 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
54965496
// Aggregate all requirement fixes that belong to the same callee
54975497
// and attempt to diagnose possible ambiguities.
54985498
{
5499-
auto isResultBuilderMethodRef = [&](ASTNode node) {
5500-
auto *UDE = getAsExpr<UnresolvedDotExpr>(node);
5501-
if (!(UDE && UDE->isImplicit()))
5502-
return false;
5503-
5504-
auto &ctx = getASTContext();
5505-
SmallVector<Identifier, 4> builderMethods(
5506-
{ctx.Id_buildBlock, ctx.Id_buildExpression, ctx.Id_buildPartialBlock,
5507-
ctx.Id_buildFinalResult});
5508-
5509-
return llvm::any_of(builderMethods, [&](const Identifier &methodId) {
5510-
return UDE->getName().compare(DeclNameRef(methodId)) == 0;
5511-
});
5512-
};
5513-
55145499
// Aggregates fixes fixes attached to `buildExpression` and `buildBlock`
55155500
// methods at the particular source location.
55165501
llvm::MapVector<SourceLoc, SmallVector<FixInContext, 4>>
@@ -5526,7 +5511,8 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
55265511

55275512
auto *calleeLoc = entry.first->getCalleeLocator(fix->getLocator());
55285513

5529-
if (isResultBuilderMethodRef(calleeLoc->getAnchor())) {
5514+
auto *UDE = getAsExpr<UnresolvedDotExpr>(calleeLoc->getAnchor());
5515+
if (UDE && isResultBuilderMethodReference(getASTContext(), UDE)) {
55305516
auto *anchor = castToExpr<Expr>(calleeLoc->getAnchor());
55315517
builderMethodRequirementFixes[anchor->getLoc()].push_back(entry);
55325518
} else {
@@ -7971,3 +7957,17 @@ void constraints::dumpAnchor(ASTNode anchor, SourceManager *SM,
79717957
}
79727958
// TODO(diagnostics): Implement the rest of the cases.
79737959
}
7960+
7961+
bool constraints::isResultBuilderMethodReference(ASTContext &ctx,
7962+
UnresolvedDotExpr *UDE) {
7963+
if (!(UDE && UDE->isImplicit()))
7964+
return false;
7965+
7966+
SmallVector<Identifier, 4> builderMethods(
7967+
{ctx.Id_buildBlock, ctx.Id_buildExpression, ctx.Id_buildPartialBlock,
7968+
ctx.Id_buildFinalResult});
7969+
7970+
return llvm::any_of(builderMethods, [&](const Identifier &methodId) {
7971+
return UDE->getName().compare(DeclNameRef(methodId)) == 0;
7972+
});
7973+
}

0 commit comments

Comments
 (0)