[CSFix] Add a skeleton of a fix for argument destructuring to match pack expansion

This commit is contained in:
Pavel Yaskevich
2023-04-25 12:45:26 -07:00
committed by Pavel Yaskevich
parent b5aae065c2
commit b9ef2cabe4
3 changed files with 50 additions and 0 deletions

View File

@@ -434,6 +434,10 @@ enum class FixKind : uint8_t {
/// Allow pack expansion expressions in a context that does not support them.
AllowInvalidPackExpansion,
/// Allow a pack expansion parameter of N elements to be matched
/// with a single tuple literal argument of the same arity.
DestructureTupleToMatchPackExpansionParameter,
};
class ConstraintFix {
@@ -3416,6 +3420,39 @@ public:
}
};
/// Passing an argument of tuple type to a value pack expansion parameter
/// that expected N distinct elements.
class DestructureTupleToMatchPackExpansionParameter final
: public ConstraintFix {
PackType *ParamShape;
DestructureTupleToMatchPackExpansionParameter(ConstraintSystem &cs,
PackType *paramShapeTy,
ConstraintLocator *locator)
: ConstraintFix(cs,
FixKind::DestructureTupleToMatchPackExpansionParameter,
locator),
ParamShape(paramShapeTy) {
assert(locator->isLastElement<LocatorPathElt::ApplyArgToParam>());
}
public:
std::string getName() const override {
return "allow pack expansion to match tuple argument";
}
bool diagnose(const Solution &solution, bool asNote = false) const override;
static DestructureTupleToMatchPackExpansionParameter *
create(ConstraintSystem &cs, PackType *paramShapeTy,
ConstraintLocator *locator);
static bool classof(const ConstraintFix *fix) {
return fix->getKind() ==
FixKind::DestructureTupleToMatchPackExpansionParameter;
}
};
} // end namespace constraints
} // end namespace swift