Skip to content

Commit d8c8a39

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 0db6746 commit d8c8a39

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
@@ -14803,6 +14803,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1480314803
case FixKind::AllowTupleLabelMismatch:
1480414804
case FixKind::AddExplicitExistentialCoercion:
1480514805
case FixKind::DestructureTupleToMatchPackExpansionParameter:
14806+
case FixKind::AllowValueExpansionWithoutPackReferences:
1480614807
llvm_unreachable("handled elsewhere");
1480714808
}
1480814809

0 commit comments

Comments
 (0)