Skip to content

Commit 06a762b

Browse files
committed
[CSFix] Add a specific kind for IgnoreResultBuilderWithReturnStmts
1 parent 0a42548 commit 06a762b

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

include/swift/Sema/CSFix.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ enum class FixKind : uint8_t {
290290
/// Ignore result builder body which fails `pre-check` call.
291291
IgnoreInvalidResultBuilderBody,
292292

293+
/// Ignore result builder body if it has `return` statements.
294+
IgnoreResultBuilderWithReturnStmts,
295+
293296
/// Resolve type of `nil` by providing a contextual type.
294297
SpecifyContextualTypeForNil,
295298

@@ -2503,10 +2506,15 @@ class AllowKeyPathWithoutComponents final : public ConstraintFix {
25032506
};
25042507

25052508
class IgnoreInvalidResultBuilderBody : public ConstraintFix {
2506-
protected:
25072509
IgnoreInvalidResultBuilderBody(ConstraintSystem &cs,
25082510
ConstraintLocator *locator)
2509-
: ConstraintFix(cs, FixKind::IgnoreInvalidResultBuilderBody, locator) {}
2511+
: IgnoreInvalidResultBuilderBody(
2512+
cs, FixKind::IgnoreInvalidResultBuilderBody, locator) {}
2513+
2514+
protected:
2515+
IgnoreInvalidResultBuilderBody(ConstraintSystem &cs, FixKind kind,
2516+
ConstraintLocator *locator)
2517+
: ConstraintFix(cs, kind, locator) {}
25102518

25112519
public:
25122520
std::string getName() const override {
@@ -2533,13 +2541,19 @@ class IgnoreResultBuilderWithReturnStmts final
25332541

25342542
IgnoreResultBuilderWithReturnStmts(ConstraintSystem &cs, Type builderTy,
25352543
ConstraintLocator *locator)
2536-
: IgnoreInvalidResultBuilderBody(cs, locator), BuilderType(builderTy) {}
2544+
: IgnoreInvalidResultBuilderBody(
2545+
cs, FixKind::IgnoreResultBuilderWithReturnStmts, locator),
2546+
BuilderType(builderTy) {}
25372547

25382548
public:
25392549
bool diagnose(const Solution &solution, bool asNote = false) const override;
25402550

25412551
static IgnoreResultBuilderWithReturnStmts *
25422552
create(ConstraintSystem &cs, Type builderTy, ConstraintLocator *locator);
2553+
2554+
static bool classof(ConstraintFix *fix) {
2555+
return fix->getKind() == FixKind::IgnoreResultBuilderWithReturnStmts;
2556+
}
25432557
};
25442558

25452559
class SpecifyContextualTypeForNil final : public ConstraintFix {

lib/Sema/CSBindings.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,8 +1871,9 @@ TypeVariableBinding::fixForHole(ConstraintSystem &cs) const {
18711871
// If the whole body is being ignored due to a pre-check failure,
18721872
// let's not record a fix about result type since there is
18731873
// just not enough context to infer it without a body.
1874-
if (cs.hasFixFor(cs.getConstraintLocator(closure),
1875-
FixKind::IgnoreInvalidResultBuilderBody))
1874+
auto *closureLoc = cs.getConstraintLocator(closure);
1875+
if (cs.hasFixFor(closureLoc, FixKind::IgnoreInvalidResultBuilderBody) ||
1876+
cs.hasFixFor(closureLoc, FixKind::IgnoreResultBuilderWithReturnStmts))
18761877
return None;
18771878

18781879
ConstraintFix *fix = SpecifyClosureReturnType::create(cs, dstLocator);

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11553,6 +11553,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1155311553
case FixKind::SpecifyLabelToAssociateTrailingClosure:
1155411554
case FixKind::AllowKeyPathWithoutComponents:
1155511555
case FixKind::IgnoreInvalidResultBuilderBody:
11556+
case FixKind::IgnoreResultBuilderWithReturnStmts:
1155611557
case FixKind::SpecifyContextualTypeForNil:
1155711558
case FixKind::AllowRefToInvalidDecl:
1155811559
case FixKind::SpecifyBaseTypeForOptionalUnresolvedMember:

0 commit comments

Comments
 (0)