You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/type/protocol_composition.swift
+19-19
Original file line number
Diff line number
Diff line change
@@ -110,52 +110,52 @@ func testConversion() {
110
110
accept_manyPrintable(sp)
111
111
112
112
// Conversions among existential types.
113
-
varx2:protocol<SuperREPLPrintable,FooProtocol> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{12-53=SuperREPLPrintable & FooProtocol}}
113
+
varx2:protocol<SuperREPLPrintable,FooProtocol> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{12-53=SuperREPLPrintable & FooProtocol}}
114
114
x2 = x // expected-error{{value of type 'any FooProtocol & REPLPrintable' does not conform to 'SuperREPLPrintable' in assignment}}
115
115
x = x2
116
116
117
117
// Subtyping
118
118
var _ :()->FooProtocol&SuperREPLPrintable= return_superPrintable
119
119
120
120
// 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}}
122
122
}
123
123
124
124
// Test the parser's splitting of >= into > and =.
125
125
varx: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
-
vary: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
-
varz:protocol<P5,P7>?=17 // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{9-27=(P5 & P7)?=}}
126
+
vary: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
+
varz:protocol<P5,P7>?=17 // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{9-27=(P5 & P7)?=}}
128
128
129
129
typealiasA1=protocol<> // expected-error {{'protocol<>' syntax has been removed; use 'Any' instead}} {{16-26=Any}}
130
130
typealiasA2=protocol<>? // expected-error {{'protocol<>' syntax has been removed; use 'Any' instead}} {{16-27=Any?}}
131
-
typealiasB1=protocol<P1,P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{16-31=P1 & P2}}
132
-
typealiasB2=protocol<P1,P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{16-32=P1 & P2}}
133
-
typealiasB3=protocol<P1,P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{16-32=P1 & P2}}
134
-
typealiasB4=protocol<P1,P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{16-33=P1 & P2}}
135
-
typealiasC1=protocol<Any,P1> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{16-33=Any & P1}}
136
-
typealiasC2=protocol<P1,Any> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{16-33=P1 & Any}}
131
+
typealiasB1=protocol<P1,P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{16-31=P1 & P2}}
132
+
typealiasB2=protocol<P1,P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{16-32=P1 & P2}}
133
+
typealiasB3=protocol<P1,P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{16-32=P1 & P2}}
134
+
typealiasB4=protocol<P1,P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{16-33=P1 & P2}}
135
+
typealiasC1=protocol<Any,P1> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{16-33=Any & P1}}
136
+
typealiasC2=protocol<P1,Any> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{16-33=P1 & Any}}
137
137
typealiasD=protocol<P1> // expected-error {{'protocol<...>' composition syntax has been removed and is not needed here}} {{15-27=P1}}
138
138
typealiasE=protocol<Any> // expected-error {{'protocol<...>' composition syntax has been removed and is not needed here}} {{15-28=Any}}
139
-
typealiasF=protocol<Any,Any> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{15-33=Any & Any}}
139
+
typealiasF=protocol<Any,Any> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{15-33=Any & Any}}
140
140
typealiasG=protocol<P1>.Type // expected-error {{'protocol<...>' composition syntax has been removed and is not needed here}} {{15-27=P1}}
141
141
typealiasH=protocol<P1>! // expected-error {{'protocol<...>' composition syntax has been removed and is not needed here}} {{15-28=P1!}}
142
142
// expected-warning@-1 {{using '!' is not allowed here; treating this as '?' instead}}
143
-
typealiasJ=protocol<P1,P2>.Protocol // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{15-31=(P1 & P2)}}
144
-
typealiasK=protocol<P1,P2>? // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{15-32=(P1 & P2)?}}
145
-
typealiasL=protocol<(P1),P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{15-33=(P1) & P2}}
143
+
typealiasJ=protocol<P1,P2>.Protocol // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{15-31=(P1 & P2)}}
144
+
typealiasK=protocol<P1,P2>? // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{15-32=(P1 & P2)?}}
145
+
typealiasL=protocol<(P1),P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{15-33=(P1) & P2}}
146
146
147
147
// Deprecated protocol composition syntax in expression context.
148
148
do{
149
149
func typesAreEqual<T>(_:T.Type, _:T.Type){}
150
150
151
151
typesAreEqual(Optional<P1 & P2>.self,
152
152
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>}}
154
154
155
155
// Test that we parse non-identifier components.
156
156
typesAreEqual(Optional<P1 & P2>.self,
157
157
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)>}}
159
159
}
160
160
161
161
typealiasT01=P1.Protocol&P2 // expected-error {{non-protocol, non-class type '(any P1).Type' cannot be used within a protocol-constrained type}}
typealiasT07=P1&protocol<P2,P3> // expected-error {{protocol<...>' composition syntax has been removed; join the protocols using '&'}} {{22-38=P2 & P3}}
168
+
typealiasT07=P1&protocol<P2,P3> // expected-error {{protocol<...>' composition syntax has been removed; join the type constraints using '&'}} {{22-38=P2 & P3}}
169
169
func fT07(x:T07)->P1&P2&P3{return x } // OK, 'P1 & protocol<P2, P3>' is parsed as 'P1 & P2 & P3'.
170
170
let _:P1&P2&P3->P1&P2&P3= fT07 // expected-error {{single argument function types require parentheses}} {{8-8=(}} {{20-20=)}}
171
171
@@ -177,8 +177,8 @@ struct S05<T> where T : P5? & P6 {} // expected-error {{non-protocol, non-class
// Protocol Composition Often Migrated Incorrectly
180
-
structS_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
+
structS_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}}
182
182
func f2_45712<U :protocol<P1>>(_:U){} // expected-error {{'protocol<...>' composition syntax has been removed and is not needed here}} {{19-32=P1>}}
183
183
184
184
// Make sure we correctly form compositions in expression context
structStruct3<T :Pub&Bar&P3>{} // expected-error {{cannot find type 'P3' in scope}}
56
56
structStruct4<T>where T :Pub&Bar{}
57
57
58
-
structStruct5<T :protocol<Pub,Bar>>{} // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}}
59
-
structStruct6<T>where T :protocol<Pub,Bar>{} // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}}
58
+
structStruct5<T :protocol<Pub,Bar>>{} // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}}
59
+
structStruct6<T>where T :protocol<Pub,Bar>{} // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}}
60
60
61
61
typealiasT1=Pub&Bar
62
-
typealiasT2=protocol<Pub,Bar> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}}
62
+
typealiasT2=protocol<Pub,Bar> // expected-error {{'protocol<...>' composition syntax has been removed; join the type constraints using '&'}}
0 commit comments