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
func existential<T :EqualComparable, U :EqualComparable>(_ t1:T, t2:T, u:U){
37
-
vareqComp:EqualComparable= t1 // Ok
37
+
vareqComp:EqualComparable= t1 // expected-warning {{protocol 'EqualComparable' as a type must be explicitly marked as 'any'}}
38
38
eqComp = u
39
39
if t1.isEqual(eqComp){} // expected-error{{cannot convert value of type 'EqualComparable' to expected argument type 'T'}}
40
40
if eqComp.isEqual(t2){} // expected-error{{member 'isEqual' cannot be used on value of protocol type 'EqualComparable'; use a generic constraint instead}}
otherEqComp = t1 // expected-error{{value of type 'T' does not conform to 'OtherEqualComparable' in assignment}}
50
50
_ = otherEqComp
51
51
52
-
varotherEqComp2:OtherEqualComparable // Ok
52
+
varotherEqComp2:anyOtherEqualComparable // Ok
53
53
otherEqComp2 = t1 // expected-error{{value of type 'T' does not conform to 'OtherEqualComparable' in assignment}}
54
54
_ = otherEqComp2
55
55
56
-
_ = t1 asEqualComparable&OtherEqualComparable // expected-error{{value of type 'T' does not conform to 'EqualComparable & OtherEqualComparable' in coercion}}
56
+
_ = t1 asanyEqualComparable&OtherEqualComparable // expected-error{{value of type 'T' does not conform to 'EqualComparable & OtherEqualComparable' in coercion}}
Copy file name to clipboardExpand all lines: test/decl/protocol/protocols.swift
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -119,7 +119,7 @@ struct Circle {
119
119
func testCircular(_ circle:Circle){
120
120
// FIXME: It would be nice if this failure were suppressed because the protocols
121
121
// have circular definitions.
122
-
_ = circle asCircleStart // expected-error{{value of type 'Circle' does not conform to 'CircleStart' in coercion}}
122
+
_ = circle asanyCircleStart // expected-error{{value of type 'Circle' does not conform to 'CircleStart' in coercion}}
123
123
}
124
124
125
125
// <rdar://problem/14750346>
@@ -439,18 +439,18 @@ func g<T : C2>(_ x : T) {
439
439
440
440
classC3:P1{} // expected-error{{type 'C3' does not conform to protocol 'P1'}}
441
441
func h<T :C3>(_ x :T){
442
-
_ = x asP1
442
+
_ = x asanyP1
443
443
}
444
444
func i<T :C3>(_ x :T?)->Bool{
445
-
return x is P1
445
+
return x is anyP1
446
446
// FIXME: Bogus diagnostic. See SR-11920.
447
447
// expected-warning@-2 {{checking a value with optional type 'T?' against dynamic type 'P1' succeeds whenever the value is non-nil; did you mean to use '!= nil'?}}
448
448
}
449
449
func j(_ x :C1)->Bool{
450
-
return x is P1
450
+
return x is P1 // expected-warning {{protocol 'P1' as a type must be explicitly marked as 'any'}}
let _:[String:()->(P1,P1)]= arg.covariantSelfComplex(
199
-
{(x:P1)in},
200
-
{(x:P1?)in},
201
-
{(x:Array<P1>)in},
202
-
{(x:Array<Array<P1>?>)in}
198
+
let _:[String:()->(anyP1,anyP1)]= arg.covariantSelfComplex(
199
+
{(x:anyP1)in},
200
+
{(x:(anyP1)?)in},
201
+
{(x:Array<anyP1>)in},
202
+
{(x:Array<Array<anyP1>?>)in}
203
203
) // ok
204
204
arg.covariantAssocSimple // expected-error {{member 'covariantAssocSimple' cannot be used on value of protocol type 'P1'; use a generic constraint instead}}
205
205
arg.covariantAssocComplex({ _ in},{ _ in},{ _ in},{ _ in}) // expected-error {{member 'covariantAssocComplex' cannot be used on value of protocol type 'P1'; use a generic constraint instead}}
206
206
// FIXME: expected-error@-1 {{unable to infer type of a closure parameter '_' in the current context}}
207
207
208
208
_ = arg.covariantSelfPropSimple // ok
209
-
let _:P1= arg.covariantSelfPropSimple // ok
209
+
let _:anyP1= arg.covariantSelfPropSimple // ok
210
210
_ = arg.covariantSelfPropComplex // ok
211
211
let _:(
212
-
_:(P1)->Void,
213
-
_:(P1?)->Void,
214
-
_:(Array<P1>)->Void,
215
-
_:(Array<Array<P1>?>)->Void
216
-
)->[String:()->(P1,P1)]= arg.covariantSelfPropComplex // ok
212
+
_:(anyP1)->Void,
213
+
_:((anyP1)?)->Void,
214
+
_:(Array<anyP1>)->Void,
215
+
_:(Array<Array<anyP1>?>)->Void
216
+
)->[String:()->(anyP1,anyP1)]= arg.covariantSelfPropComplex // ok
217
217
arg.covariantAssocPropSimple // expected-error {{member 'covariantAssocPropSimple' cannot be used on value of protocol type 'P1'; use a generic constraint instead}}
218
218
arg.covariantAssocPropComplex // expected-error {{member 'covariantAssocPropComplex' cannot be used on value of protocol type 'P1'; use a generic constraint instead}}
219
219
220
220
_ =arg[covariantSelfSubscriptSimple:()] // ok
221
-
let _:P1=arg[covariantSelfSubscriptSimple:()] // ok
221
+
let _:anyP1=arg[covariantSelfSubscriptSimple:()] // ok
arg[covariantAssocSubscriptSimple:()] // expected-error {{member 'subscript' cannot be used on value of protocol type 'P1'; use a generic constraint instead}}
230
230
arg[covariantAssocSubscriptComplex:{ _ in},{ _ in},{ _ in},{ _ in}] // expected-error {{member 'subscript' cannot be used on value of protocol type 'P1'; use a generic constraint instead}}
protoMeta.static_invariantSelfMethod() // expected-error {{static member 'static_invariantSelfMethod' cannot be used on protocol metatype 'P1_TypeMemberOnInstanceAndViceVersa.Protocol'}}
452
-
protoMeta.static_invariantSelfProp // expected-error {{static member 'static_invariantSelfProp' cannot be used on protocol metatype 'P1_TypeMemberOnInstanceAndViceVersa.Protocol'}}
453
-
protoMeta[static_invariantSelfSubscript:()] // expected-error {{static member 'subscript' cannot be used on protocol metatype 'P1_TypeMemberOnInstanceAndViceVersa.Protocol'}}
451
+
protoMeta.static_invariantSelfMethod() // expected-error {{static member 'static_invariantSelfMethod' cannot be used on protocol metatype '(P1_TypeMemberOnInstanceAndViceVersa).Protocol'}}
452
+
protoMeta.static_invariantSelfProp // expected-error {{static member 'static_invariantSelfProp' cannot be used on protocol metatype '(P1_TypeMemberOnInstanceAndViceVersa).Protocol'}}
453
+
protoMeta[static_invariantSelfSubscript:()] // expected-error {{static member 'subscript' cannot be used on protocol metatype '(P1_TypeMemberOnInstanceAndViceVersa).Protocol'}}
454
454
_ = protoMeta.covariantSelfMethod // ok
455
-
protoMeta.invariantSelfMethod // expected-error {{member 'invariantSelfMethod' cannot be used on value of protocol type 'P1_TypeMemberOnInstanceAndViceVersa.Protocol'; use a generic constraint instead}}
455
+
protoMeta.invariantSelfMethod // expected-error {{member 'invariantSelfMethod' cannot be used on value of protocol type '(P1_TypeMemberOnInstanceAndViceVersa).Protocol'; use a generic constraint instead}}
456
456
protoMeta.invariantSelfProp // expected-error {{instance member 'invariantSelfProp' cannot be used on type 'P1_TypeMemberOnInstanceAndViceVersa'}}
457
457
protoMeta[invariantSelfSubscript:()] // expected-error {{instance member 'subscript' cannot be used on type 'P1_TypeMemberOnInstanceAndViceVersa'}}
458
458
@@ -481,7 +481,7 @@ protocol P2 {
481
481
482
482
varprop:Self{getset}
483
483
}
484
-
func takesP2(p2:P2){
484
+
func takesP2(p2:anyP2){
485
485
_ =p2[]
486
486
// expected-error@-1{{member 'subscript' cannot be used on value of protocol type 'P2'; use a generic constraint instead}}
487
487
_ = p2.prop
@@ -500,7 +500,7 @@ protocol MiscTestsProto {
500
500
subscript(intToInt _:Int)->Int{get}
501
501
}
502
502
do{
503
-
func miscTests(_ arg:MiscTestsProto){ // ok
503
+
func miscTests(_ arg:anyMiscTestsProto){ // ok
504
504
arg.runce(5)
505
505
506
506
do{
@@ -515,7 +515,7 @@ do {
515
515
_ =arg[intToAssoc:17] // expected-error{{member 'subscript' cannot be used on value of protocol type 'MiscTestsProto'; use a generic constraint instead}}
516
516
}
517
517
518
-
func existentialSequence(_ e:Sequence){
518
+
func existentialSequence(_ e:anySequence){
519
519
varx= e.makeIterator() // expected-error{{member 'makeIterator' cannot be used on value of protocol type 'Sequence'; use a generic constraint instead}}
func aMethod(_ object :AsExistentialAssocTypeAgainA) // expected-warning {{protocol 'AsExistentialAssocTypeAgainA' as a type must be explicitly marked as 'any'}}
Copy file name to clipboardExpand all lines: test/stmt/foreach.swift
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -176,7 +176,7 @@ func testOptionalSequence() {
176
176
}
177
177
178
178
// FIXME: Should this be allowed?
179
-
func testExistentialSequence(s:Sequence){
179
+
func testExistentialSequence(s:anySequence){
180
180
forxin s { // expected-error {{protocol 'Sequence' as a type cannot conform to the protocol itself}} expected-note {{only concrete types such as structs, enums and classes can conform to protocols}}
0 commit comments