Skip to content

Commit f1fd528

Browse files
committed
[CSFix] Add a fix to detect/diagnose references to invalid declarations
Upon attempt to generate constraints for invalid declaration reference let's turn that into a hole and record this new fix to diagnose it once solution has been reached.
1 parent 15d566d commit f1fd528

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

include/swift/Sema/CSFix.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ enum class FixKind : uint8_t {
281281

282282
/// Resolve type of `nil` by providing a contextual type.
283283
SpecifyContextualTypeForNil,
284+
285+
/// Allow expressions to reference invalid declarations by turning
286+
/// them into holes.
287+
AllowRefToInvalidDecl,
284288
};
285289

286290
class ConstraintFix {
@@ -2055,6 +2059,21 @@ class SpecifyContextualTypeForNil final : public ConstraintFix {
20552059
ConstraintLocator * locator);
20562060
};
20572061

2062+
class AllowRefToInvalidDecl final : public ConstraintFix {
2063+
AllowRefToInvalidDecl(ConstraintSystem &cs, ConstraintLocator *locator)
2064+
: ConstraintFix(cs, FixKind::AllowRefToInvalidDecl, locator) {}
2065+
2066+
public:
2067+
std::string getName() const override {
2068+
return "ignore invalid declaration reference";
2069+
}
2070+
2071+
bool diagnose(const Solution &solution, bool asNote = false) const override;
2072+
2073+
static AllowRefToInvalidDecl *create(ConstraintSystem &cs,
2074+
ConstraintLocator *locator);
2075+
};
2076+
20582077
} // end namespace constraints
20592078
} // end namespace swift
20602079

lib/Sema/CSFix.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,3 +1615,14 @@ SpecifyContextualTypeForNil::create(ConstraintSystem &cs,
16151615
ConstraintLocator *locator) {
16161616
return new (cs.getAllocator()) SpecifyContextualTypeForNil(cs, locator);
16171617
}
1618+
1619+
bool AllowRefToInvalidDecl::diagnose(const Solution &solution,
1620+
bool asNote) const {
1621+
return false;
1622+
}
1623+
1624+
AllowRefToInvalidDecl *
1625+
AllowRefToInvalidDecl::create(ConstraintSystem &cs,
1626+
ConstraintLocator *locator) {
1627+
return new (cs.getAllocator()) AllowRefToInvalidDecl(cs, locator);
1628+
}

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10144,7 +10144,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1014410144
case FixKind::SpecifyLabelToAssociateTrailingClosure:
1014510145
case FixKind::AllowKeyPathWithoutComponents:
1014610146
case FixKind::IgnoreInvalidResultBuilderBody:
10147-
case FixKind::SpecifyContextualTypeForNil: {
10147+
case FixKind::SpecifyContextualTypeForNil:
10148+
case FixKind::AllowRefToInvalidDecl: {
1014810149
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
1014910150
}
1015010151

0 commit comments

Comments
 (0)