Skip to content

GSB: When merging two equivalence classes, don't forget to re-process delayed requirements #19923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4926,8 +4926,11 @@ GenericSignatureBuilder::addSameTypeRequirementBetweenTypeParameters(
if (equivClass2)
equivClass->modified(*this);

// Same-type requirements.
// Same-type requirements, delayed requirements.
if (equivClass2) {
Impl->DelayedRequirements.append(equivClass2->delayedRequirements.begin(),
equivClass2->delayedRequirements.end());

equivClass->sameTypeConstraints.insert(
equivClass->sameTypeConstraints.end(),
equivClass2->sameTypeConstraints.begin(),
Expand Down
30 changes: 30 additions & 0 deletions test/Generics/same_type_constraints.swift
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,33 @@ func testP12a<T: P12>(_: T) where T.A == X12<Int>, T.A == X12<T.B>, T.B == Int {
func testP12b<T: P12>(_: T) where T.B == Int, T.A == X12<T.B>, X12<T.B> == T.A { }
// expected-warning@-1{{redundant same-type constraint 'T.A' == 'X12<Int>'}}
// expected-note@-2{{same-type constraint 'T.A' == 'X12<Int>' written here}}

// rdar://45307061 - dropping delayed same-type constraints when merging
// equivalence classes

protocol FakeIterator {
associatedtype Element
}

protocol FakeSequence {
associatedtype Iterator : FakeIterator
associatedtype Element where Iterator.Element == Element
}

protocol ObserverType {
associatedtype E
}

struct Bad<S: FakeSequence, O> where S.Element : ObserverType, S.Element.E == O {}

func good<S: FakeSequence, O>(_: S, _: O) where S.Element : ObserverType, O == S.Element.E {
_ = Bad<S, O>()
}

func bad<S: FakeSequence, O>(_: S, _: O) where S.Element : ObserverType, O == S.Iterator.Element.E {
_ = Bad<S, O>()
}

func ugly<S: FakeSequence, O>(_: S, _: O) where S.Element : ObserverType, O == S.Iterator.Element.E, O == S.Element.E {
_ = Bad<S, O>()
}