Skip to content

Commit 63cc5f9

Browse files
authored
Merge pull request #19923 from slavapestov/gsb-same-type-fix
GSB: When merging two equivalence classes, don't forget to re-process delayed requirements
2 parents 9a4d2a3 + 7edbbae commit 63cc5f9

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4926,8 +4926,11 @@ GenericSignatureBuilder::addSameTypeRequirementBetweenTypeParameters(
49264926
if (equivClass2)
49274927
equivClass->modified(*this);
49284928

4929-
// Same-type requirements.
4929+
// Same-type requirements, delayed requirements.
49304930
if (equivClass2) {
4931+
Impl->DelayedRequirements.append(equivClass2->delayedRequirements.begin(),
4932+
equivClass2->delayedRequirements.end());
4933+
49314934
equivClass->sameTypeConstraints.insert(
49324935
equivClass->sameTypeConstraints.end(),
49334936
equivClass2->sameTypeConstraints.begin(),

test/Generics/same_type_constraints.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,33 @@ func testP12a<T: P12>(_: T) where T.A == X12<Int>, T.A == X12<T.B>, T.B == Int {
393393
func testP12b<T: P12>(_: T) where T.B == Int, T.A == X12<T.B>, X12<T.B> == T.A { }
394394
// expected-warning@-1{{redundant same-type constraint 'T.A' == 'X12<Int>'}}
395395
// expected-note@-2{{same-type constraint 'T.A' == 'X12<Int>' written here}}
396+
397+
// rdar://45307061 - dropping delayed same-type constraints when merging
398+
// equivalence classes
399+
400+
protocol FakeIterator {
401+
associatedtype Element
402+
}
403+
404+
protocol FakeSequence {
405+
associatedtype Iterator : FakeIterator
406+
associatedtype Element where Iterator.Element == Element
407+
}
408+
409+
protocol ObserverType {
410+
associatedtype E
411+
}
412+
413+
struct Bad<S: FakeSequence, O> where S.Element : ObserverType, S.Element.E == O {}
414+
415+
func good<S: FakeSequence, O>(_: S, _: O) where S.Element : ObserverType, O == S.Element.E {
416+
_ = Bad<S, O>()
417+
}
418+
419+
func bad<S: FakeSequence, O>(_: S, _: O) where S.Element : ObserverType, O == S.Iterator.Element.E {
420+
_ = Bad<S, O>()
421+
}
422+
423+
func ugly<S: FakeSequence, O>(_: S, _: O) where S.Element : ObserverType, O == S.Iterator.Element.E, O == S.Element.E {
424+
_ = Bad<S, O>()
425+
}

0 commit comments

Comments
 (0)