mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CSFix] Add a skeleton of a fix for argument destructuring to match pack expansion
This commit is contained in:
committed by
Pavel Yaskevich
parent
b5aae065c2
commit
b9ef2cabe4
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user