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 // expected-error{{protocol 'EqualComparable' can only be used as a generic constraint}}
37
+
vareqComp:EqualComparable= t1 // Ok
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 // expected-error{{protocol 'OtherEqualComparable' can only be used as a generic constraint}}
52
+
varotherEqComp2:OtherEqualComparable // 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}} expected-error{{protocol 'OtherEqualComparable' can only be used as a generic constraint}} expected-error{{protocol 'EqualComparable' can only be used as a generic constraint}}
56
+
_ = t1 asEqualComparable&OtherEqualComparable // expected-error{{value of type 'T' does not conform to 'EqualComparable & OtherEqualComparable' in coercion}}
57
57
}
58
58
59
59
protocolRuncible{
60
60
func runce<A>(_ x:A)
61
61
func spoon(_ x:Self)
62
62
}
63
63
64
-
func testRuncible(_ x:Runcible){ // expected-error{{protocol 'Runcible' can only be used as a generic constraint}}
Copy file name to clipboardExpand all lines: test/Sema/existential_nested_type.swift
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ enum MyError : Error {
15
15
16
16
func checkIt(_ js:Any)throws{
17
17
switch js {
18
-
caseletdbl as HasAssoc: // expected-error {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
func existentialSequence(_ e:Sequence){ // expected-error{{has Self or associated type requirements}}
270
+
func existentialSequence(_ e:Sequence){
271
271
varx= e.makeIterator() // expected-error{{member 'makeIterator' cannot be used on value of protocol type 'Sequence'; use a generic constraint instead}}
varx= h.getR() // expected-error{{member 'getR' cannot be used on value of protocol type 'HasSequenceAndStream'; use a generic constraint instead}}
284
284
x.makeIterator()
@@ -307,7 +307,7 @@ struct DictionaryIntInt {
307
307
}
308
308
}
309
309
310
-
func testSubscripting(_ iis:IntIntSubscriptable, i_s:IntSubscriptable){ // expected-error{{has Self or associated type requirements}}
310
+
func testSubscripting(_ iis:IntIntSubscriptable, i_s:IntSubscriptable){ // Ok
311
311
vari:Int=iis[17]
312
312
vari2=i_s[17] // expected-error{{member 'subscript' cannot be used on value of protocol type 'IntSubscriptable'; use a generic constraint instead}}
313
313
}
@@ -488,18 +488,18 @@ func g<T : C2>(_ x : T) {
488
488
489
489
classC3:P1{} // expected-error{{type 'C3' does not conform to protocol 'P1'}}
490
490
func h<T :C3>(_ x :T){
491
-
_ = x asP1 // expected-error{{protocol 'P1' can only be used as a generic constraint because it has Self or associated type requirements}}
491
+
_ = x asP1
492
492
}
493
493
func i<T :C3>(_ x :T?)->Bool{
494
-
return x is P1 // expected-error{{protocol 'P1' can only be used as a generic constraint because it has Self or associated type requirements}}
494
+
return x is P1
495
495
// FIXME: Bogus diagnostic. See SR-11920.
496
496
// 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'?}}
497
497
}
498
498
func j(_ x :C1)->Bool{
499
-
return x is P1 // expected-error{{protocol 'P1' can only be used as a generic constraint because it has Self or associated type requirements}}
499
+
return x is P1
500
500
}
501
501
func k(_ x :C1?)->Bool{
502
-
return x is P1 // expected-error{{protocol 'P1' can only be used as a generic constraint because it has Self or associated type requirements}}
Copy file name to clipboardExpand all lines: test/decl/protocol/recursive_requirement.swift
+2-4Lines changed: 2 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -91,7 +91,7 @@ protocol AsExistentialB {
91
91
}
92
92
93
93
protocolAsExistentialAssocTypeA{
94
-
vardelegate:AsExistentialAssocTypeB?{get} // expected-error {{protocol 'AsExistentialAssocTypeB' can only be used as a generic constraint because it has Self or associated type requirements}}
func aMethod(_ object :AsExistentialAssocTypeAgainA) // expected-error {{protocol 'AsExistentialAssocTypeAgainA' can only be used as a generic constraint because it has Self or associated type requirements}}
Copy file name to clipboardExpand all lines: test/stmt/foreach.swift
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -175,8 +175,8 @@ func testOptionalSequence() {
175
175
}
176
176
}
177
177
178
-
// Crash with (invalid) for each over an existential
179
-
func testExistentialSequence(s:Sequence){ // expected-error {{protocol 'Sequence' can only be used as a generic constraint because it has Self or associated type requirements}}
178
+
// FIXME: Should this be allowed?
179
+
func testExistentialSequence(s:Sequence){
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