mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CS] Diagnose UnresolvedPatternExprs as part of constraint solving
Instead of diagnosing in CSApply, let's create a fix and diagnose in the solver instead. Additionally, make sure we assign ErrorTypes to any VarDecls bound by the invalid pattern, which fixes a crash. rdar://110638279
This commit is contained in:
@@ -306,6 +306,9 @@ enum class FixKind : uint8_t {
|
||||
/// This issue should already have been diagnosed elsewhere.
|
||||
IgnoreUnresolvedPatternVar,
|
||||
|
||||
/// Ignore a nested UnresolvedPatternExpr in an ExprPattern, which is invalid.
|
||||
IgnoreInvalidPatternInExpr,
|
||||
|
||||
/// Resolve type of `nil` by providing a contextual type.
|
||||
SpecifyContextualTypeForNil,
|
||||
|
||||
@@ -2959,6 +2962,33 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class IgnoreInvalidPatternInExpr final : public ConstraintFix {
|
||||
Pattern *P;
|
||||
|
||||
IgnoreInvalidPatternInExpr(ConstraintSystem &cs, Pattern *pattern,
|
||||
ConstraintLocator *locator)
|
||||
: ConstraintFix(cs, FixKind::IgnoreInvalidPatternInExpr, locator),
|
||||
P(pattern) {}
|
||||
|
||||
public:
|
||||
std::string getName() const override {
|
||||
return "ignore invalid Pattern nested in Expr";
|
||||
}
|
||||
|
||||
bool diagnose(const Solution &solution, bool asNote = false) const override;
|
||||
|
||||
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
|
||||
return diagnose(*commonFixes.front().first);
|
||||
}
|
||||
|
||||
static IgnoreInvalidPatternInExpr *
|
||||
create(ConstraintSystem &cs, Pattern *pattern, ConstraintLocator *locator);
|
||||
|
||||
static bool classof(const ConstraintFix *fix) {
|
||||
return fix->getKind() == FixKind::IgnoreInvalidPatternInExpr;
|
||||
}
|
||||
};
|
||||
|
||||
class SpecifyContextualTypeForNil final : public ConstraintFix {
|
||||
SpecifyContextualTypeForNil(ConstraintSystem &cs,
|
||||
ConstraintLocator *locator)
|
||||
|
||||
Reference in New Issue
Block a user