Skip to content

Commit dbd3ebe

Browse files
Merge pull request #63574 from Rajveer100/branch-for-issue-62518
Changed 'protocols' to 'type constraints' for obsoleted protocol composition syntax error
2 parents e80f571 + 8e4fd23 commit dbd3ebe

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

include/swift/AST/DiagnosticsParse.def

+1-1
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ ERROR(expected_rangle_protocol,PointsToFirstBadToken,
889889
"expected '>' to complete protocol-constrained type", ())
890890

891891
ERROR(deprecated_protocol_composition,none,
892-
"'protocol<...>' composition syntax has been removed; join the protocols using '&'", ())
892+
"'protocol<...>' composition syntax has been removed; join the type constraints using '&'", ())
893893
ERROR(deprecated_protocol_composition_single,none,
894894
"'protocol<...>' composition syntax has been removed and is not needed here", ())
895895
ERROR(deprecated_any_composition,none,

test/Parse/swift3_warnings_swift4_errors_version_4.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ protocol P2 {}
1111

1212
let x: protocol<> // expected-error {{'protocol<>' syntax has been removed; use 'Any' instead}}
1313
let y: protocol<P1> // expected-error {{'protocol<...>' composition syntax has been removed and is not needed here}}}
14-
let z: protocol<P1, P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}}
14+
let z: protocol<P1, P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}}
1515

1616
func bar(f: @noescape () -> ()) {} // expected-error {{unknown attribute 'noescape'}}
1717

test/decl/inherit/inherit.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct S4 : P, P { }
4949
// expected-error@-1{{redundant conformance of 'S4' to protocol 'P'}}
5050
// expected-note@-2{{'S4' declares conformance to protocol 'P' here}}
5151
struct S6 : P & { } // expected-error {{expected identifier for type name}}
52-
struct S7 : protocol<P, Q> { } // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}}
52+
struct S7 : protocol<P, Q> { } // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}}
5353
// expected-error @-1 {{non-class type 'S7' cannot conform to class protocol 'Q'}}
5454

5555
class GenericBase<T> {}

test/type/protocol_composition.swift

+19-19
Original file line numberDiff line numberDiff line change
@@ -110,52 +110,52 @@ func testConversion() {
110110
accept_manyPrintable(sp)
111111

112112
// Conversions among existential types.
113-
var x2 : protocol<SuperREPLPrintable, FooProtocol> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{12-53=SuperREPLPrintable & FooProtocol}}
113+
var x2 : protocol<SuperREPLPrintable, FooProtocol> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{12-53=SuperREPLPrintable & FooProtocol}}
114114
x2 = x // expected-error{{value of type 'any FooProtocol & REPLPrintable' does not conform to 'SuperREPLPrintable' in assignment}}
115115
x = x2
116116

117117
// Subtyping
118118
var _ : () -> FooProtocol & SuperREPLPrintable = return_superPrintable
119119

120120
// FIXME: closures make ABI conversions explicit. rdar://problem/19517003
121-
var _ : () -> protocol<FooProtocol, REPLPrintable> = { return_superPrintable() } // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{17-53=FooProtocol & REPLPrintable}}
121+
var _ : () -> protocol<FooProtocol, REPLPrintable> = { return_superPrintable() } // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{17-53=FooProtocol & REPLPrintable}}
122122
}
123123

124124
// Test the parser's splitting of >= into > and =.
125125
var x : protocol<P5>= 17 // expected-error {{'protocol<...>' composition syntax has been removed and is not needed here}} {{9-22=P5=}} expected-error {{'=' must have consistent whitespace on both sides}}
126-
var y : protocol<P5, P7>= 17 // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{9-26=P5 & P7=}} expected-error {{'=' must have consistent whitespace on both sides}}
127-
var z : protocol<P5, P7>?=17 // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{9-27=(P5 & P7)?=}}
126+
var y : protocol<P5, P7>= 17 // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{9-26=P5 & P7=}} expected-error {{'=' must have consistent whitespace on both sides}}
127+
var z : protocol<P5, P7>?=17 // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{9-27=(P5 & P7)?=}}
128128

129129
typealias A1 = protocol<> // expected-error {{'protocol<>' syntax has been removed; use 'Any' instead}} {{16-26=Any}}
130130
typealias A2 = protocol<>? // expected-error {{'protocol<>' syntax has been removed; use 'Any' instead}} {{16-27=Any?}}
131-
typealias B1 = protocol<P1,P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{16-31=P1 & P2}}
132-
typealias B2 = protocol<P1, P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{16-32=P1 & P2}}
133-
typealias B3 = protocol<P1 ,P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{16-32=P1 & P2}}
134-
typealias B4 = protocol<P1 , P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{16-33=P1 & P2}}
135-
typealias C1 = protocol<Any, P1> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{16-33=Any & P1}}
136-
typealias C2 = protocol<P1, Any> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{16-33=P1 & Any}}
131+
typealias B1 = protocol<P1,P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{16-31=P1 & P2}}
132+
typealias B2 = protocol<P1, P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{16-32=P1 & P2}}
133+
typealias B3 = protocol<P1 ,P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{16-32=P1 & P2}}
134+
typealias B4 = protocol<P1 , P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{16-33=P1 & P2}}
135+
typealias C1 = protocol<Any, P1> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{16-33=Any & P1}}
136+
typealias C2 = protocol<P1, Any> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{16-33=P1 & Any}}
137137
typealias D = protocol<P1> // expected-error {{'protocol<...>' composition syntax has been removed and is not needed here}} {{15-27=P1}}
138138
typealias E = protocol<Any> // expected-error {{'protocol<...>' composition syntax has been removed and is not needed here}} {{15-28=Any}}
139-
typealias F = protocol<Any, Any> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{15-33=Any & Any}}
139+
typealias F = protocol<Any, Any> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{15-33=Any & Any}}
140140
typealias G = protocol<P1>.Type // expected-error {{'protocol<...>' composition syntax has been removed and is not needed here}} {{15-27=P1}}
141141
typealias H = protocol<P1>! // expected-error {{'protocol<...>' composition syntax has been removed and is not needed here}} {{15-28=P1!}}
142142
// expected-warning@-1 {{using '!' is not allowed here; treating this as '?' instead}}
143-
typealias J = protocol<P1, P2>.Protocol // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{15-31=(P1 & P2)}}
144-
typealias K = protocol<P1, P2>? // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{15-32=(P1 & P2)?}}
145-
typealias L = protocol<(P1), P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{15-33=(P1) & P2}}
143+
typealias J = protocol<P1, P2>.Protocol // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{15-31=(P1 & P2)}}
144+
typealias K = protocol<P1, P2>? // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{15-32=(P1 & P2)?}}
145+
typealias L = protocol<(P1), P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{15-33=(P1) & P2}}
146146

147147
// Deprecated protocol composition syntax in expression context.
148148
do {
149149
func typesAreEqual<T>(_: T.Type, _: T.Type) {}
150150

151151
typesAreEqual(Optional<P1 & P2>.self,
152152
Optional<protocol<P1, P2>>.self)
153-
// expected-error@-1 {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{26-43=P1 & P2>}}
153+
// expected-error@-1 {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{26-43=P1 & P2>}}
154154

155155
// Test that we parse non-identifier components.
156156
typesAreEqual(Optional<P1 & P2>.self,
157157
Optional<protocol<P1, (P2)>>.self)
158-
// expected-error@-1 {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{26-45=P1 & (P2)>}}
158+
// expected-error@-1 {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{26-45=P1 & (P2)>}}
159159
}
160160

161161
typealias T01 = P1.Protocol & P2 // expected-error {{non-protocol, non-class type '(any P1).Type' cannot be used within a protocol-constrained type}}
@@ -165,7 +165,7 @@ typealias T04 = P1 & P2! // expected-error {{non-protocol, non-class type '(any
165165
// expected-warning@-1 {{using '!' is not allowed here; treating this as '?' instead}}
166166
typealias T05 = P1 & P2 -> P3 // expected-error {{single argument function types require parentheses}} {{17-17=(}} {{24-24=)}}
167167
typealias T06 = P1 -> P2 & P3 // expected-error {{single argument function types require parentheses}} {{17-17=(}} {{19-19=)}}
168-
typealias T07 = P1 & protocol<P2, P3> // expected-error {{protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{22-38=P2 & P3}}
168+
typealias T07 = P1 & protocol<P2, P3> // expected-error {{protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{22-38=P2 & P3}}
169169
func fT07(x: T07) -> P1 & P2 & P3 { return x } // OK, 'P1 & protocol<P2, P3>' is parsed as 'P1 & P2 & P3'.
170170
let _: P1 & P2 & P3 -> P1 & P2 & P3 = fT07 // expected-error {{single argument function types require parentheses}} {{8-8=(}} {{20-20=)}}
171171

@@ -177,8 +177,8 @@ struct S05<T> where T : P5? & P6 {} // expected-error {{non-protocol, non-class
177177

178178
// https://github.com/apple/swift/issues/45712
179179
// Protocol Composition Often Migrated Incorrectly
180-
struct S_45712<T: protocol<P1, P3>> {} // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{19-36=P1 & P3>}}
181-
func f1_45712<U where U: protocol<P1, P3>>(_: U) {} // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{26-43=P1 & P3>}} // expected-error {{'where' clause}}
180+
struct S_45712<T: protocol<P1, P3>> {} // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{19-36=P1 & P3>}}
181+
func f1_45712<U where U: protocol<P1, P3>>(_: U) {} // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{26-43=P1 & P3>}} // expected-error {{'where' clause}}
182182
func f2_45712<U : protocol<P1>>(_: U) {} // expected-error {{'protocol<...>' composition syntax has been removed and is not needed here}} {{19-32=P1>}}
183183

184184
// Make sure we correctly form compositions in expression context

test/type/protocol_types.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ struct Struct2<T : Pub & Bar> { }
5555
struct Struct3<T : Pub & Bar & P3> { } // expected-error {{cannot find type 'P3' in scope}}
5656
struct Struct4<T> where T : Pub & Bar {}
5757

58-
struct Struct5<T : protocol<Pub, Bar>> { } // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}}
59-
struct Struct6<T> where T : protocol<Pub, Bar> {} // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}}
58+
struct Struct5<T : protocol<Pub, Bar>> { } // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}}
59+
struct Struct6<T> where T : protocol<Pub, Bar> {} // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}}
6060

6161
typealias T1 = Pub & Bar
62-
typealias T2 = protocol<Pub , Bar> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}}
62+
typealias T2 = protocol<Pub , Bar> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}}
6363

6464
// rdar://problem/20593294
6565
protocol HasAssoc {

0 commit comments

Comments
 (0)