Skip to content

Commit 1d9b202

Browse files
committed
GSB: Fix inconsistent 'redundant conformance' diagnostic
1 parent 299ff02 commit 1d9b202

13 files changed

+61
-62
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,11 +2395,10 @@ ERROR(requires_generic_param_same_type_does_not_conform,none,
23952395
ERROR(requires_same_concrete_type,none,
23962396
"generic signature requires types %0 and %1 to be the same", (Type, Type))
23972397
WARNING(redundant_conformance_constraint,none,
2398-
"redundant conformance constraint %0: %1", (Type, ProtocolDecl *))
2398+
"redundant conformance constraint %0 : %1", (Type, ProtocolDecl *))
23992399
NOTE(redundant_conformance_here,none,
2400-
"conformance constraint %1: %2 %select{written here|implied here|"
2401-
"inferred from type here}0",
2402-
(unsigned, Type, ProtocolDecl *))
2400+
"conformance constraint %0 : %1 implied here",
2401+
(Type, ProtocolDecl *))
24032402

24042403
ERROR(unsupported_recursive_requirements, none,
24052404
"requirement involves recursion that is not currently supported", ())

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7107,7 +7107,7 @@ void GenericSignatureBuilder::diagnoseRedundantRequirements() const {
71077107
continue;
71087108

71097109
Context.Diags.diagnose(otherLoc, diag::redundant_conformance_here,
7110-
1, subjectType, proto);
7110+
subjectType, proto);
71117111
}
71127112

71137113
break;

test/Generics/canonicalization.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ protocol Q : P {
1212
}
1313

1414
func f<T>(t: T) where T : P, T : Q, T.A : P0 { } // expected-note{{'f(t:)' previously declared here}}
15-
// expected-warning@-1{{redundant conformance constraint 'T': 'P'}}
16-
// expected-note@-2{{conformance constraint 'T': 'P' implied here}}
15+
// expected-warning@-1{{redundant conformance constraint 'T' : 'P'}}
16+
// expected-note@-2{{conformance constraint 'T' : 'P' implied here}}
1717

1818
func f<T>(t: T) where T : Q, T : P, T.A : P0 { } // expected-error{{invalid redeclaration of 'f(t:)'}}
19-
// expected-warning@-1{{redundant conformance constraint 'T': 'P'}}
20-
// expected-note@-2{{conformance constraint 'T': 'P' implied here}}
19+
// expected-warning@-1{{redundant conformance constraint 'T' : 'P'}}
20+
// expected-note@-2{{conformance constraint 'T' : 'P' implied here}}

test/Generics/conformance_access_path.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ func testPaths3<V: P5>(_ v: V) {
4848
acceptQ0(v.getAssocP3())
4949
}
5050

51-
protocol P6Unordered: P5Unordered { // expected-note{{conformance constraint 'Self.A': 'P0' implied here}}
52-
associatedtype A: P0 // expected-warning{{redundant conformance constraint 'Self.A': 'P0'}}
51+
protocol P6Unordered: P5Unordered { // expected-note{{conformance constraint 'Self.A' : 'P0' implied here}}
52+
associatedtype A: P0 // expected-warning{{redundant conformance constraint 'Self.A' : 'P0'}}
5353
// expected-warning@-1{{redeclaration of associated type 'A'}}
5454
}
5555

test/Generics/protocol_requirement_signatures.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ protocol Q5: Q2, Q3, Q4 {}
5858
// CHECK-LABEL: .Q6@
5959
// CHECK-NEXT: Requirement signature: <Self where Self : Q2, Self : Q3, Self : Q4>
6060
// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0 : Q2, τ_0_0 : Q3, τ_0_0 : Q4>
61-
protocol Q6: Q2, // expected-note{{conformance constraint 'Self.X': 'P1' implied here}}
61+
protocol Q6: Q2, // expected-note{{conformance constraint 'Self.X' : 'P1' implied here}}
6262
Q3, Q4 {
63-
associatedtype X: P1 // expected-warning{{redundant conformance constraint 'Self.X': 'P1'}}
63+
associatedtype X: P1 // expected-warning{{redundant conformance constraint 'Self.X' : 'P1'}}
6464
// expected-warning@-1{{redeclaration of associated type 'X' from protocol 'Q4' is}}
6565
}
6666

test/Generics/rdar62903491.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@ protocol P {
77

88
// Anything that mentions 'T : P' minimizes to 'U : P'.
99

10-
// expected-warning@+2 {{redundant conformance constraint 'U': 'P'}}
11-
// expected-note@+1 {{conformance constraint 'U': 'P' implied here}}
10+
// expected-warning@+2 {{redundant conformance constraint 'U' : 'P'}}
11+
// expected-note@+1 {{conformance constraint 'U' : 'P' implied here}}
1212
func oneProtocol1<T, U>(_: T, _: U) where T : P, U : P, T.X == U, U.X == T {}
1313
// CHECK-LABEL: oneProtocol1
1414
// CHECK: Generic signature: <T, U where T : P, T == U.X, U == T.X>
1515

16-
// expected-warning@+2 {{redundant conformance constraint 'U': 'P'}}
17-
// expected-note@+1 {{conformance constraint 'U': 'P' implied here}}
16+
// expected-warning@+2 {{redundant conformance constraint 'U' : 'P'}}
17+
// expected-note@+1 {{conformance constraint 'U' : 'P' implied here}}
1818
func oneProtocol2<T, U>(_: T, _: U) where U : P, T : P, T.X == U, U.X == T {}
1919
// CHECK-LABEL: oneProtocol2
2020
// CHECK: Generic signature: <T, U where T : P, T == U.X, U == T.X>
2121

22-
// expected-warning@+2 {{redundant conformance constraint 'U': 'P'}}
23-
// expected-note@+1 {{conformance constraint 'U': 'P' implied here}}
22+
// expected-warning@+2 {{redundant conformance constraint 'U' : 'P'}}
23+
// expected-note@+1 {{conformance constraint 'U' : 'P' implied here}}
2424
func oneProtocol3<T, U>(_: T, _: U) where T : P, T.X == U, U : P, U.X == T {}
2525
// CHECK-LABEL: oneProtocol3
2626
// CHECK: Generic signature: <T, U where T : P, T == U.X, U == T.X>
2727

28-
// expected-warning@+2 {{redundant conformance constraint 'U': 'P'}}
29-
// expected-note@+1 {{conformance constraint 'U': 'P' implied here}}
28+
// expected-warning@+2 {{redundant conformance constraint 'U' : 'P'}}
29+
// expected-note@+1 {{conformance constraint 'U' : 'P' implied here}}
3030
func oneProtocol4<T, U>(_: T, _: U) where U : P, T.X == U, T : P, U.X == T {}
3131
// CHECK-LABEL: oneProtocol4
3232
// CHECK: Generic signature: <T, U where T : P, T == U.X, U == T.X>
@@ -59,38 +59,38 @@ protocol P2 {
5959
associatedtype Y : P1
6060
}
6161

62-
// expected-warning@+2 {{redundant conformance constraint 'U': 'P2'}}
63-
// expected-note@+1 {{conformance constraint 'U': 'P2' implied here}}
62+
// expected-warning@+2 {{redundant conformance constraint 'U' : 'P2'}}
63+
// expected-note@+1 {{conformance constraint 'U' : 'P2' implied here}}
6464
func twoProtocols1<T, U>(_: T, _: U) where T : P1, U : P2, T.X == U, U.Y == T {}
6565
// CHECK-LABEL: twoProtocols1
6666
// CHECK: Generic signature: <T, U where T : P1, T == U.Y, U == T.X>
6767

68-
// expected-warning@+2 {{redundant conformance constraint 'U': 'P2'}}
69-
// expected-note@+1 {{conformance constraint 'U': 'P2' implied here}}
68+
// expected-warning@+2 {{redundant conformance constraint 'U' : 'P2'}}
69+
// expected-note@+1 {{conformance constraint 'U' : 'P2' implied here}}
7070
func twoProtocols2<T, U>(_: T, _: U) where U : P2, T : P1, T.X == U, U.Y == T {}
7171
// CHECK-LABEL: twoProtocols2
7272
// CHECK: Generic signature: <T, U where T : P1, T == U.Y, U == T.X>
7373

74-
// expected-warning@+2 {{redundant conformance constraint 'U': 'P2'}}
75-
// expected-note@+1 {{conformance constraint 'U': 'P2' implied here}}
74+
// expected-warning@+2 {{redundant conformance constraint 'U' : 'P2'}}
75+
// expected-note@+1 {{conformance constraint 'U' : 'P2' implied here}}
7676
func twoProtocols3<T, U>(_: T, _: U) where T : P1, T.X == U, U : P2, U.Y == T {}
7777
// CHECK-LABEL: twoProtocols3
7878
// CHECK: Generic signature: <T, U where T : P1, T == U.Y, U == T.X>
7979

80-
// expected-warning@+2 {{redundant conformance constraint 'U': 'P2'}}
81-
// expected-note@+1 {{conformance constraint 'U': 'P2' implied here}}
80+
// expected-warning@+2 {{redundant conformance constraint 'U' : 'P2'}}
81+
// expected-note@+1 {{conformance constraint 'U' : 'P2' implied here}}
8282
func twoProtocols4<T, U>(_: T, _: U) where U : P2, T.X == U, T : P1, U.Y == T {}
8383
// CHECK-LABEL: twoProtocols4
8484
// CHECK: Generic signature: <T, U where T : P1, T == U.Y, U == T.X>
8585

86-
// expected-warning@+2 {{redundant conformance constraint 'U': 'P2'}}
87-
// expected-note@+1 {{conformance constraint 'U': 'P2' implied here}}
86+
// expected-warning@+2 {{redundant conformance constraint 'U' : 'P2'}}
87+
// expected-note@+1 {{conformance constraint 'U' : 'P2' implied here}}
8888
func twoProtocols5<T, U>(_: T, _: U) where T : P1, T.X == U, U.Y == T, U : P2 {}
8989
// CHECK-LABEL: twoProtocols5
9090
// CHECK: Generic signature: <T, U where T : P1, T == U.Y, U == T.X>
9191

92-
// expected-warning@+2 {{redundant conformance constraint 'T': 'P1'}}
93-
// expected-note@+1 {{conformance constraint 'T': 'P1' implied here}}
92+
// expected-warning@+2 {{redundant conformance constraint 'T' : 'P1'}}
93+
// expected-note@+1 {{conformance constraint 'T' : 'P1' implied here}}
9494
func twoProtocols6<T, U>(_: T, _: U) where U : P2, T.X == U, U.Y == T, T : P1 {}
9595
// CHECK-LABEL: twoProtocols6
9696
// CHECK: Generic signature: <T, U where T == U.Y, U : P2, U == T.X>

test/Generics/rdar65263302.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ public class C<O: P>: P {
1111

1212
// CHECK: Generic signature: <T, O, E where T : C<E>, O : P, E : P, O.Element == E.Element>
1313
public func toe1<T, O, E>(_: T, _: O, _: E, _: T.Element)
14-
where T : P, // expected-warning {{redundant conformance constraint 'T': 'P'}}
14+
where T : P, // expected-warning {{redundant conformance constraint 'T' : 'P'}}
1515
O : P,
1616
O.Element == T.Element,
17-
T : C<E> {} // expected-note {{conformance constraint 'T': 'P' implied here}}
17+
T : C<E> {} // expected-note {{conformance constraint 'T' : 'P' implied here}}
1818

1919
// CHECK: Generic signature: <T, O, E where T : C<E>, O : P, E : P, O.Element == E.Element>
2020
public func toe2<T, O, E>(_: T, _: O, _: E, _: T.Element)

test/Generics/rdar75656022.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ struct OriginalExampleWithWarning<A, B> where A : P2, B : P2, A.T == B.T {
4747
// CHECK-LABEL: Generic signature: <A, B, C, D, E where A == S1<C, E, S2<D>>, B : P2, C : P1, D == B.T, E == D.T, B.T == C.T>
4848
init<C, D, E>(_: C)
4949
where C : P1,
50-
D : P1, // expected-warning {{redundant conformance constraint 'D': 'P1'}}
51-
C.T : P1, // expected-warning {{redundant conformance constraint 'C.T': 'P1'}}
50+
D : P1, // expected-warning {{redundant conformance constraint 'D' : 'P1'}}
51+
C.T : P1, // expected-warning {{redundant conformance constraint 'C.T' : 'P1'}}
5252
A == S1<C, C.T.T, S2<C.T>>,
5353
C.T == D,
5454
E == D.T { }
@@ -69,7 +69,7 @@ struct WithoutBogusGenericParametersWithWarning<A, B> where A : P2, B : P2, A.T
6969
// CHECK-LABEL: Generic signature: <A, B, C where A == S1<C, B.T.T, S2<B.T>>, B : P2, C : P1, B.T == C.T>
7070
init<C>(_: C)
7171
where C : P1,
72-
C.T : P1, // expected-warning {{redundant conformance constraint 'C.T': 'P1'}}
72+
C.T : P1, // expected-warning {{redundant conformance constraint 'C.T' : 'P1'}}
7373
A == S1<C, C.T.T, S2<C.T>> {}
7474
}
7575

test/Generics/redundant_requirement_self_conforming_protocol.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ struct G<T> {}
55

66
// CHECK-LABEL: Generic signature: <T where T == Error>
77
extension G where T : Error, T == Error {}
8-
// expected-warning@-1 {{redundant conformance constraint 'T': 'Error'}}
9-
// expected-note@-2 {{conformance constraint 'T': 'Error' implied here}}
8+
// expected-warning@-1 {{redundant conformance constraint 'T' : 'Error'}}
9+
// expected-note@-2 {{conformance constraint 'T' : 'Error' implied here}}

test/Generics/requirement_inference.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ func inferSameType1<T, U>(_ x: Model_P3_P4_Eq<T, U>) {
114114
}
115115

116116
func inferSameType2<T : P3, U : P4>(_: T, _: U) where U.P4Assoc : P2, T.P3Assoc == U.P4Assoc {}
117-
// expected-warning@-1{{redundant conformance constraint 'U.P4Assoc': 'P2'}}
118-
// expected-note@-2{{conformance constraint 'U.P4Assoc': 'P2' implied here}}
117+
// expected-warning@-1{{redundant conformance constraint 'U.P4Assoc' : 'P2'}}
118+
// expected-note@-2{{conformance constraint 'U.P4Assoc' : 'P2' implied here}}
119119

120120
func inferSameType3<T : PCommonAssoc1>(_: T) where T.CommonAssoc : P1, T : PCommonAssoc2 {
121121
}
@@ -134,8 +134,8 @@ protocol P7 : P6 {
134134

135135
// CHECK-LABEL: P7@
136136
// CHECK: Canonical generic signature: <τ_0_0 where τ_0_0 : P7, τ_0_0.AssocP6.Element : P6, τ_0_0.AssocP6.Element == τ_0_0.AssocP7.AssocP6.Element>
137-
extension P7 where AssocP6.Element : P6, // expected-note{{conformance constraint 'Self.AssocP7.AssocP6.Element': 'P6' implied here}}
138-
AssocP7.AssocP6.Element : P6, // expected-warning{{redundant conformance constraint 'Self.AssocP7.AssocP6.Element': 'P6'}}
137+
extension P7 where AssocP6.Element : P6, // expected-note{{conformance constraint 'Self.AssocP7.AssocP6.Element' : 'P6' implied here}}
138+
AssocP7.AssocP6.Element : P6, // expected-warning{{redundant conformance constraint 'Self.AssocP7.AssocP6.Element' : 'P6'}}
139139
AssocP6.Element == AssocP7.AssocP6.Element {
140140
func nestedSameType1() { }
141141
}
@@ -327,8 +327,8 @@ struct X24<T: P20> : P24 {
327327
// CHECK-NEXT: Requirement signature: <Self where Self.A == X24<Self.B>, Self.B : P20>
328328
// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.A == X24<τ_0_0.B>, τ_0_0.B : P20>
329329
protocol P25a {
330-
associatedtype A: P24 // expected-warning{{redundant conformance constraint 'Self.A': 'P24'}}
331-
associatedtype B: P20 where A == X24<B> // expected-note{{conformance constraint 'Self.A': 'P24' implied here}}
330+
associatedtype A: P24 // expected-warning{{redundant conformance constraint 'Self.A' : 'P24'}}
331+
associatedtype B: P20 where A == X24<B> // expected-note{{conformance constraint 'Self.A' : 'P24' implied here}}
332332
}
333333

334334
// CHECK-LABEL: .P25b@
@@ -362,8 +362,8 @@ struct X26<T: X3> : P26 {
362362
// CHECK-NEXT: Requirement signature: <Self where Self.A == X26<Self.B>, Self.B : X3>
363363
// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.A == X26<τ_0_0.B>, τ_0_0.B : X3>
364364
protocol P27a {
365-
associatedtype A: P26 // expected-warning{{redundant conformance constraint 'Self.A': 'P26'}}
366-
associatedtype B: X3 where A == X26<B> // expected-note{{conformance constraint 'Self.A': 'P26' implied here}}
365+
associatedtype A: P26 // expected-warning{{redundant conformance constraint 'Self.A' : 'P26'}}
366+
associatedtype B: X3 where A == X26<B> // expected-note{{conformance constraint 'Self.A' : 'P26' implied here}}
367367
}
368368

369369
// CHECK-LABEL: .P27b@

0 commit comments

Comments
 (0)