[CSSimplify] Fix locator of pack expansion pattern conformance constraint

This commit is contained in:
Pavel Yaskevich
2024-11-21 15:48:28 -08:00
parent e3b1f341f0
commit df6950af5d
2 changed files with 32 additions and 15 deletions

View File

@@ -8427,11 +8427,10 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
// We sometimes get a pack expansion type here.
if (auto *expansionType = type->getAs<PackExpansionType>()) {
// FIXME: Locator
addConstraint(ConstraintKind::ConformsTo,
expansionType->getPatternType(),
protocol->getDeclaredInterfaceType(),
locator);
addConstraint(
ConstraintKind::ConformsTo, expansionType->getPatternType(),
protocol->getDeclaredInterfaceType(),
locator.withPathElement(LocatorPathElt::PackExpansionPattern()));
return SolutionKind::Solved;
}
@@ -8625,17 +8624,27 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
}
// If we have something like ... -> type req # -> pack element #, we're
// solving a requirement of the form T : P where T is a type parameter pack
if (path.back().is<LocatorPathElt::PackElement>())
path.pop_back();
// Conditional conformance requirements could produce chains of
// `path element -> pack expansion pattern -> pack element`.
while (!path.empty()) {
// If we have something like ... -> type req # -> pack element #, we're
// solving a requirement of the form T : P where T is a type parameter pack
if (path.back().is<LocatorPathElt::PackElement>()) {
path.pop_back();
continue;
}
// This is similar to `PackElement` but locator points to the requirement
// associted with pack expansion pattern (i.e. `repeat each T: P`) where
// the path is something like:
// `... -> type req # -> pack expansion pattern`.
if (path.back().is<LocatorPathElt::PackExpansionPattern>())
path.pop_back();
// This is similar to `PackElement` but locator points to the requirement
// associated with pack expansion pattern (i.e. `repeat each T: P`) where
// the path is something like:
// `... -> type req # -> pack expansion pattern`.
if (path.back().is<LocatorPathElt::PackExpansionPattern>()) {
path.pop_back();
continue;
}
break;
}
if (auto req = path.back().getAs<LocatorPathElt::AnyRequirement>()) {
// If this is a requirement associated with `Self` which is bound

View File

@@ -93,3 +93,11 @@ struct Test3: Element {
}
}
}
struct Test4: Element {
var body: some Element { // expected-note {{opaque return type declared here}}
FakeElement()
// expected-error@-1 {{return type of property 'body' requires that 'FakeElement' conform to 'Element'}}
Element1()
}
}