Skip to content

Commit 31e0a52

Browse files
committed
[CSFix] Add a skeleton of a fix for missing each in value pack reference
1 parent 143b016 commit 31e0a52

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

include/swift/Sema/CSFix.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,9 @@ enum class FixKind : uint8_t {
444444

445445
/// Allow value pack expansion without pack references.
446446
AllowValueExpansionWithoutPackReferences,
447+
448+
/// Ignore missing 'each' keyword before value pack reference.
449+
IgnoreMissingEachKeyword,
447450
};
448451

449452
class ConstraintFix {
@@ -3506,6 +3509,33 @@ class AllowValueExpansionWithoutPackReferences final : public ConstraintFix {
35063509
}
35073510
};
35083511

3512+
class IgnoreMissingEachKeyword final : public ConstraintFix {
3513+
Type ValuePackType;
3514+
3515+
IgnoreMissingEachKeyword(ConstraintSystem &cs, Type valuePackTy,
3516+
ConstraintLocator *locator)
3517+
: ConstraintFix(cs, FixKind::IgnoreMissingEachKeyword, locator),
3518+
ValuePackType(valuePackTy) {}
3519+
3520+
public:
3521+
std::string getName() const override {
3522+
return "allow value pack reference without 'each'";
3523+
}
3524+
3525+
bool diagnose(const Solution &solution, bool asNote = false) const override;
3526+
3527+
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
3528+
return diagnose(*commonFixes.front().first);
3529+
}
3530+
3531+
static IgnoreMissingEachKeyword *
3532+
create(ConstraintSystem &cs, Type valuePackTy, ConstraintLocator *locator);
3533+
3534+
static bool classof(const ConstraintFix *fix) {
3535+
return fix->getKind() == FixKind::IgnoreMissingEachKeyword;
3536+
}
3537+
};
3538+
35093539
} // end namespace constraints
35103540
} // end namespace swift
35113541

lib/Sema/CSFix.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,3 +2784,15 @@ AllowValueExpansionWithoutPackReferences::create(ConstraintSystem &cs,
27842784
return new (cs.getAllocator())
27852785
AllowValueExpansionWithoutPackReferences(cs, locator);
27862786
}
2787+
2788+
bool IgnoreMissingEachKeyword::diagnose(const Solution &solution,
2789+
bool asNote) const {
2790+
return false;
2791+
}
2792+
2793+
IgnoreMissingEachKeyword *
2794+
IgnoreMissingEachKeyword::create(ConstraintSystem &cs, Type valuePackTy,
2795+
ConstraintLocator *locator) {
2796+
return new (cs.getAllocator())
2797+
IgnoreMissingEachKeyword(cs, valuePackTy, locator);
2798+
}

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14771,6 +14771,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1477114771
case FixKind::AddExplicitExistentialCoercion:
1477214772
case FixKind::DestructureTupleToMatchPackExpansionParameter:
1477314773
case FixKind::AllowValueExpansionWithoutPackReferences:
14774+
case FixKind::IgnoreMissingEachKeyword:
1477414775
llvm_unreachable("handled elsewhere");
1477514776
}
1477614777

0 commit comments

Comments
 (0)