Skip to content

Commit 956edcc

Browse files
committed
[CSFix] Add a fix to allow value pack expansions without pack references
Situations like `repeat x` where `x` is `Int` where pack expansion expression doesn't have any pack references.
1 parent a10c56b commit 956edcc

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

include/swift/Sema/CSFix.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ enum class FixKind : uint8_t {
438438
/// Allow a pack expansion parameter of N elements to be matched
439439
/// with a single tuple literal argument of the same arity.
440440
DestructureTupleToMatchPackExpansionParameter,
441+
442+
/// Allow value pack expansion without pack references.
443+
AllowValueExpansionWithoutPackReferences,
441444
};
442445

443446
class ConstraintFix {
@@ -3453,6 +3456,31 @@ class DestructureTupleToMatchPackExpansionParameter final
34533456
}
34543457
};
34553458

3459+
class AllowValueExpansionWithoutPackReferences final : public ConstraintFix {
3460+
AllowValueExpansionWithoutPackReferences(ConstraintSystem &cs,
3461+
ConstraintLocator *locator)
3462+
: ConstraintFix(cs, FixKind::AllowValueExpansionWithoutPackReferences,
3463+
locator) {}
3464+
3465+
public:
3466+
std::string getName() const override {
3467+
return "allow value pack expansion without pack references";
3468+
}
3469+
3470+
bool diagnose(const Solution &solution, bool asNote = false) const override;
3471+
3472+
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
3473+
return diagnose(*commonFixes.front().first);
3474+
}
3475+
3476+
static AllowValueExpansionWithoutPackReferences *
3477+
create(ConstraintSystem &cs, ConstraintLocator *locator);
3478+
3479+
static bool classof(const ConstraintFix *fix) {
3480+
return fix->getKind() == FixKind::AllowValueExpansionWithoutPackReferences;
3481+
}
3482+
};
3483+
34563484
} // end namespace constraints
34573485
} // end namespace swift
34583486

lib/Sema/CSFix.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,3 +2756,15 @@ DestructureTupleToMatchPackExpansionParameter::create(
27562756
return new (cs.getAllocator())
27572757
DestructureTupleToMatchPackExpansionParameter(cs, paramShapeTy, locator);
27582758
}
2759+
2760+
bool AllowValueExpansionWithoutPackReferences::diagnose(
2761+
const Solution &solution, bool asNote) const {
2762+
return false;
2763+
}
2764+
2765+
AllowValueExpansionWithoutPackReferences *
2766+
AllowValueExpansionWithoutPackReferences::create(ConstraintSystem &cs,
2767+
ConstraintLocator *locator) {
2768+
return new (cs.getAllocator())
2769+
AllowValueExpansionWithoutPackReferences(cs, locator);
2770+
}

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14814,6 +14814,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1481414814
case FixKind::AllowTupleLabelMismatch:
1481514815
case FixKind::AddExplicitExistentialCoercion:
1481614816
case FixKind::DestructureTupleToMatchPackExpansionParameter:
14817+
case FixKind::AllowValueExpansionWithoutPackReferences:
1481714818
llvm_unreachable("handled elsewhere");
1481814819
}
1481914820

0 commit comments

Comments
 (0)