Skip to content

Commit 7b73135

Browse files
authored
Merge pull request #21698 from slavapestov/gsb-same-type-order
AST: Fix failure to diagnose with redundant same-type constraints
2 parents cbca568 + 98287ca commit 7b73135

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6838,7 +6838,7 @@ void GenericSignatureBuilder::checkSameTypeConstraints(
68386838
// Put invalid locations after valid ones.
68396839
if (locA.isInvalid() || locB.isInvalid()) {
68406840
if (locA.isInvalid() != locB.isInvalid())
6841-
return locA.isInvalid() ? 1 : -1;
6841+
return locA.isValid() ? 1 : -1;
68426842

68436843
return 0;
68446844
}

test/Constraints/same_types.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,14 @@ func testSameTypeCommutativity5<U, T: P1>(_ t: T, _ u: U)
309309
func testSameTypeCommutativity6<U, T: P1>(_ t: T, _ u: U)
310310
where U & P3 == T.Assoc { } // Equivalent to T.Assoc == U & P3
311311
// expected-error@-1 2 {{non-protocol, non-class type 'U' cannot be used within a protocol-constrained type}}
312+
313+
// rdar;//problem/46848889
314+
struct Foo<A: P1, B: P1, C: P1> where A.Assoc == B.Assoc, A.Assoc == C.Assoc {}
315+
316+
struct Bar<A: P1, B: P1> where A.Assoc == B.Assoc {
317+
func f<C: P1>(with other: C) -> Foo<A, B, C> where A.Assoc == C.Assoc {
318+
// expected-note@-1 {{previous same-type constraint 'B.Assoc' == 'C.Assoc' inferred from type here}}
319+
// expected-warning@-2 {{redundant same-type constraint 'A.Assoc' == 'C.Assoc'}}
320+
fatalError()
321+
}
322+
}

0 commit comments

Comments
 (0)