Skip to content

Commit da8159c

Browse files
committed
[ConstraintSystem] Add a new fix to diagnose extraneous return(s) in result build body
1 parent 057e836 commit da8159c

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

include/swift/Sema/CSFix.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,8 @@ class AllowKeyPathWithoutComponents final : public ConstraintFix {
20232023
ConstraintLocator *locator);
20242024
};
20252025

2026-
class IgnoreInvalidResultBuilderBody final : public ConstraintFix {
2026+
class IgnoreInvalidResultBuilderBody : public ConstraintFix {
2027+
protected:
20272028
enum class ErrorInPhase {
20282029
PreCheck,
20292030
ConstraintGeneration,
@@ -2062,6 +2063,22 @@ class IgnoreInvalidResultBuilderBody final : public ConstraintFix {
20622063
create(ConstraintSystem &cs, ErrorInPhase phase, ConstraintLocator *locator);
20632064
};
20642065

2066+
class IgnoreResultBuilderWithReturnStmts final
2067+
: public IgnoreInvalidResultBuilderBody {
2068+
Type BuilderType;
2069+
2070+
IgnoreResultBuilderWithReturnStmts(ConstraintSystem &cs, Type builderTy,
2071+
ConstraintLocator *locator)
2072+
: IgnoreInvalidResultBuilderBody(cs, ErrorInPhase::PreCheck, locator),
2073+
BuilderType(builderTy) {}
2074+
2075+
public:
2076+
bool diagnose(const Solution &solution, bool asNote = false) const override;
2077+
2078+
static IgnoreResultBuilderWithReturnStmts *
2079+
create(ConstraintSystem &cs, Type builderTy, ConstraintLocator *locator);
2080+
};
2081+
20652082
class SpecifyContextualTypeForNil final : public ConstraintFix {
20662083
SpecifyContextualTypeForNil(ConstraintSystem &cs,
20672084
ConstraintLocator *locator)

lib/Sema/CSFix.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,3 +1644,15 @@ AllowRefToInvalidDecl::create(ConstraintSystem &cs,
16441644
ConstraintLocator *locator) {
16451645
return new (cs.getAllocator()) AllowRefToInvalidDecl(cs, locator);
16461646
}
1647+
1648+
bool IgnoreResultBuilderWithReturnStmts::diagnose(const Solution &solution,
1649+
bool asNote) const {
1650+
return false;
1651+
}
1652+
1653+
IgnoreResultBuilderWithReturnStmts *
1654+
IgnoreResultBuilderWithReturnStmts::create(ConstraintSystem &cs, Type builderTy,
1655+
ConstraintLocator *locator) {
1656+
return new (cs.getAllocator())
1657+
IgnoreResultBuilderWithReturnStmts(cs, builderTy, locator);
1658+
}

0 commit comments

Comments
 (0)