Skip to content

AST: Fix failure to diagnose with redundant same-type constraints #21698

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
Jan 8, 2019
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
2 changes: 1 addition & 1 deletion lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6838,7 +6838,7 @@ void GenericSignatureBuilder::checkSameTypeConstraints(
// Put invalid locations after valid ones.
if (locA.isInvalid() || locB.isInvalid()) {
if (locA.isInvalid() != locB.isInvalid())
return locA.isInvalid() ? 1 : -1;
return locA.isValid() ? 1 : -1;

return 0;
}
Expand Down
11 changes: 11 additions & 0 deletions test/Constraints/same_types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,14 @@ func testSameTypeCommutativity5<U, T: P1>(_ t: T, _ u: U)
func testSameTypeCommutativity6<U, T: P1>(_ t: T, _ u: U)
where U & P3 == T.Assoc { } // Equivalent to T.Assoc == U & P3
// expected-error@-1 2 {{non-protocol, non-class type 'U' cannot be used within a protocol-constrained type}}

// rdar;//problem/46848889
struct Foo<A: P1, B: P1, C: P1> where A.Assoc == B.Assoc, A.Assoc == C.Assoc {}

struct Bar<A: P1, B: P1> where A.Assoc == B.Assoc {
func f<C: P1>(with other: C) -> Foo<A, B, C> where A.Assoc == C.Assoc {
// expected-note@-1 {{previous same-type constraint 'B.Assoc' == 'C.Assoc' inferred from type here}}
// expected-warning@-2 {{redundant same-type constraint 'A.Assoc' == 'C.Assoc'}}
fatalError()
}
}