Skip to content

Commit df6950a

Browse files
committed
[CSSimplify] Fix locator of pack expansion pattern conformance constraint
1 parent e3b1f34 commit df6950a

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8427,11 +8427,10 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
84278427

84288428
// We sometimes get a pack expansion type here.
84298429
if (auto *expansionType = type->getAs<PackExpansionType>()) {
8430-
// FIXME: Locator
8431-
addConstraint(ConstraintKind::ConformsTo,
8432-
expansionType->getPatternType(),
8433-
protocol->getDeclaredInterfaceType(),
8434-
locator);
8430+
addConstraint(
8431+
ConstraintKind::ConformsTo, expansionType->getPatternType(),
8432+
protocol->getDeclaredInterfaceType(),
8433+
locator.withPathElement(LocatorPathElt::PackExpansionPattern()));
84358434

84368435
return SolutionKind::Solved;
84378436
}
@@ -8625,17 +8624,27 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
86258624
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
86268625
}
86278626

8628-
// If we have something like ... -> type req # -> pack element #, we're
8629-
// solving a requirement of the form T : P where T is a type parameter pack
8630-
if (path.back().is<LocatorPathElt::PackElement>())
8631-
path.pop_back();
8627+
// Conditional conformance requirements could produce chains of
8628+
// `path element -> pack expansion pattern -> pack element`.
8629+
while (!path.empty()) {
8630+
// If we have something like ... -> type req # -> pack element #, we're
8631+
// solving a requirement of the form T : P where T is a type parameter pack
8632+
if (path.back().is<LocatorPathElt::PackElement>()) {
8633+
path.pop_back();
8634+
continue;
8635+
}
86328636

8633-
// This is similar to `PackElement` but locator points to the requirement
8634-
// associted with pack expansion pattern (i.e. `repeat each T: P`) where
8635-
// the path is something like:
8636-
// `... -> type req # -> pack expansion pattern`.
8637-
if (path.back().is<LocatorPathElt::PackExpansionPattern>())
8638-
path.pop_back();
8637+
// This is similar to `PackElement` but locator points to the requirement
8638+
// associated with pack expansion pattern (i.e. `repeat each T: P`) where
8639+
// the path is something like:
8640+
// `... -> type req # -> pack expansion pattern`.
8641+
if (path.back().is<LocatorPathElt::PackExpansionPattern>()) {
8642+
path.pop_back();
8643+
continue;
8644+
}
8645+
8646+
break;
8647+
}
86398648

86408649
if (auto req = path.back().getAs<LocatorPathElt::AnyRequirement>()) {
86418650
// If this is a requirement associated with `Self` which is bound

test/Constraints/result_builder_nested_diags.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,11 @@ struct Test3: Element {
9393
}
9494
}
9595
}
96+
97+
struct Test4: Element {
98+
var body: some Element { // expected-note {{opaque return type declared here}}
99+
FakeElement()
100+
// expected-error@-1 {{return type of property 'body' requires that 'FakeElement' conform to 'Element'}}
101+
Element1()
102+
}
103+
}

0 commit comments

Comments
 (0)