@@ -2603,10 +2603,9 @@ static ConstraintFix *fixRequirementFailure(ConstraintSystem &cs, Type type1,
2603
2603
Type type2,
2604
2604
ConstraintLocatorBuilder locator) {
2605
2605
SmallVector<LocatorPathElt, 4> path;
2606
- if (auto anchor = locator.getLocatorParts(path)) {
2607
- return fixRequirementFailure(cs, type1, type2, anchor, path);
2608
- }
2609
- return nullptr;
2606
+
2607
+ auto anchor = locator.getLocatorParts(path);
2608
+ return fixRequirementFailure(cs, type1, type2, anchor, path);
2610
2609
}
2611
2610
2612
2611
static unsigned
@@ -4140,6 +4139,11 @@ static ConstraintFix *fixRequirementFailure(ConstraintSystem &cs, Type type1,
4140
4139
if (type1->isTypeVariableOrMember() || type2->isTypeVariableOrMember())
4141
4140
return nullptr;
4142
4141
4142
+ // If we have something like ... -> type req # -> pack element #, we're
4143
+ // solving a requirement of the form T : P where T is a type parameter pack
4144
+ if (path.back().is<LocatorPathElt::PackElement>())
4145
+ path = path.drop_back();
4146
+
4143
4147
auto req = path.back().castTo<LocatorPathElt::AnyRequirement>();
4144
4148
if (req.isConditionalRequirement()) {
4145
4149
// path is - ... -> open generic -> type req # -> cond req #,
@@ -7630,6 +7634,11 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
7630
7634
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
7631
7635
}
7632
7636
7637
+ // If we have something like ... -> type req # -> pack element #, we're
7638
+ // solving a requirement of the form T : P where T is a type parameter pack
7639
+ if (path.back().is<LocatorPathElt::PackElement>())
7640
+ path.pop_back();
7641
+
7633
7642
if (auto req = path.back().getAs<LocatorPathElt::AnyRequirement>()) {
7634
7643
// If this is a requirement associated with `Self` which is bound
7635
7644
// to `Any`, let's consider this "too incorrect" to continue.
@@ -13869,7 +13878,16 @@ void ConstraintSystem::addConstraint(Requirement req,
13869
13878
case RequirementKind::Conformance:
13870
13879
kind = ConstraintKind::ConformsTo;
13871
13880
break;
13872
- case RequirementKind::Superclass:
13881
+ case RequirementKind::Superclass: {
13882
+ // FIXME: Should always use ConstraintKind::SubclassOf, but that breaks
13883
+ // a couple of diagnostics
13884
+ if (auto *typeVar = req.getFirstType()->getAs<TypeVariableType>()) {
13885
+ if (typeVar->getImpl().canBindToPack()) {
13886
+ kind = ConstraintKind::SubclassOf;
13887
+ break;
13888
+ }
13889
+ }
13890
+
13873
13891
conformsToAnyObject = true;
13874
13892
kind = ConstraintKind::Subtype;
13875
13893
break;
0 commit comments