Skip to content

Commit 3273be7

Browse files
committed
[GenericEnvironment] Drop same-element requirements from opened element generic
signatures to avoid ending up with a same-element requirement on the element generic parameter.
1 parent 8db8b7c commit 3273be7

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

lib/AST/ASTContext.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5662,28 +5662,40 @@ ASTContext::getOpenedElementSignature(CanGenericSignature baseGenericSig) {
56625662
};
56635663

56645664
for (auto requirement : baseGenericSig.getRequirements()) {
5665-
requirements.push_back(requirement);
5666-
56675665
// If this requirement contains parameter packs, create a new requirement
56685666
// for the corresponding pack element.
56695667
switch (requirement.getKind()) {
56705668
case RequirementKind::SameShape:
5671-
// Drop same-shape requirements from the element signature.
5669+
requirements.push_back(requirement);
5670+
// Same-shape requirements don't apply to elements.
56725671
break;
56735672
case RequirementKind::Conformance:
56745673
case RequirementKind::Superclass:
56755674
case RequirementKind::SameType: {
56765675
auto firstType = eraseParameterPackRec(requirement.getFirstType());
56775676
auto secondType = eraseParameterPackRec(requirement.getSecondType());
56785677
if (firstType->isEqual(requirement.getFirstType()) &&
5679-
secondType->isEqual(requirement.getSecondType()))
5678+
secondType->isEqual(requirement.getSecondType())) {
5679+
requirements.push_back(requirement);
56805680
break;
5681+
}
5682+
5683+
// FIXME: For now, Drop same-element requirements from opened
5684+
// element signatures. Otherwise, we can end up with a signature:
5685+
//
5686+
// <T..., U, T_Element> where T == U, T_Element == U
5687+
//
5688+
// implying that T == T_Element
5689+
if (requirement.getKind() != RequirementKind::SameType) {
5690+
requirements.push_back(requirement);
5691+
}
56815692

56825693
requirements.emplace_back(requirement.getKind(),
56835694
firstType, secondType);
56845695
break;
56855696
}
56865697
case RequirementKind::Layout: {
5698+
requirements.push_back(requirement);
56875699
auto firstType = eraseParameterPackRec(requirement.getFirstType());
56885700
if (firstType->isEqual(requirement.getFirstType()))
56895701
break;

test/Constraints/pack-expansion-expressions.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,19 @@ func localValuePack<T...>(_ t: T...) -> (T..., T...) {
4242

4343
return (local..., localAnnotated...)
4444
}
45+
46+
protocol P {
47+
associatedtype A
48+
49+
var value: A { get }
50+
51+
func f(_ self: Self) -> Self
52+
}
53+
54+
func outerArchetype<T..., U>(t: T..., u: U) where T: P {
55+
let _: ((T.A, U)...) = ((t.value, u)...)
56+
}
57+
58+
func sameElement<T..., U>(t: T..., u: U) where T: P, T == U {
59+
let _: (T...) = (t.f(u)...)
60+
}

0 commit comments

Comments
 (0)