Skip to content

Commit 396087d

Browse files
theblixguyAnthonyLatsis
authored andcommitted
[Test] Update existing tests
1 parent 4cc1506 commit 396087d

11 files changed

+42
-95
lines changed

test/Constraints/static_members_on_protocol_in_generic_context.swift

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -265,24 +265,6 @@ test_combo(.genericWithReqs([42]))
265265
test_combo(.genericWithReqs(()))
266266
// expected-error@-1 {{contextual member reference to static method 'genericWithReqs' requires 'Self' constraint in the protocol extension}}
267267

268-
protocol Z {
269-
associatedtype T = Int
270-
271-
static var prop: T { get }
272-
}
273-
274-
extension Z {
275-
static func method() -> T { fatalError() }
276-
}
277-
278-
_ = Z.prop
279-
// expected-error@-1 {{member 'prop' cannot be used on value of protocol type 'Z.Protocol'; use a generic constraint instead}}
280-
// expected-error@-2 {{protocol 'Z' can only be used as a generic constraint because it has Self or associated type requirements}}
281-
282-
_ = Z.method()
283-
// expected-error@-1 {{member 'method' cannot be used on value of protocol type 'Z.Protocol'; use a generic constraint instead}}
284-
// expected-error@-2 {{protocol 'Z' can only be used as a generic constraint because it has Self or associated type requirements}}
285-
286268
protocol TestWithAssoc {
287269
associatedtype U
288270
}

test/Generics/function_defs.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func min<T : MethodLessComparable>(_ x: T, y: T) -> T {
3434
//===----------------------------------------------------------------------===//
3535

3636
func existential<T : EqualComparable, U : EqualComparable>(_ t1: T, t2: T, u: U) {
37-
var eqComp : EqualComparable = t1 // expected-error{{protocol 'EqualComparable' can only be used as a generic constraint}}
37+
var eqComp : EqualComparable = t1 // Ok
3838
eqComp = u
3939
if t1.isEqual(eqComp) {} // expected-error{{cannot convert value of type 'EqualComparable' to expected argument type 'T'}}
4040
if eqComp.isEqual(t2) {} // expected-error{{member 'isEqual' cannot be used on value of protocol type 'EqualComparable'; use a generic constraint instead}}
@@ -49,19 +49,19 @@ func otherExistential<T : EqualComparable>(_ t1: T) {
4949
otherEqComp = t1 // expected-error{{value of type 'T' does not conform to 'OtherEqualComparable' in assignment}}
5050
_ = otherEqComp
5151

52-
var otherEqComp2 : OtherEqualComparable // expected-error{{protocol 'OtherEqualComparable' can only be used as a generic constraint}}
52+
var otherEqComp2 : OtherEqualComparable // Ok
5353
otherEqComp2 = t1 // expected-error{{value of type 'T' does not conform to 'OtherEqualComparable' in assignment}}
5454
_ = otherEqComp2
5555

56-
_ = t1 as EqualComparable & 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 as EqualComparable & OtherEqualComparable // expected-error{{value of type 'T' does not conform to 'EqualComparable & OtherEqualComparable' in coercion}}
5757
}
5858

5959
protocol Runcible {
6060
func runce<A>(_ x: A)
6161
func spoon(_ x: Self)
6262
}
6363

64-
func testRuncible(_ x: Runcible) { // expected-error{{protocol 'Runcible' can only be used as a generic constraint}}
64+
func testRuncible(_ x: Runcible) { // Ok
6565
x.runce(5)
6666
}
6767

test/Sema/existential_nested_type.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ enum MyError : Error {
1515

1616
func checkIt(_ js: Any) throws {
1717
switch js {
18-
case let dbl as HasAssoc: // expected-error {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
18+
case let dbl as HasAssoc: // Ok
1919
throw MyError.bad(dbl)
2020

2121
default:

test/decl/nested/protocol.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ protocol OuterProtocol {
3131
struct ConformsToOuterProtocol : OuterProtocol {
3232
typealias Hen = Int
3333

34-
func f() { let _ = InnerProtocol.self }
35-
// expected-error@-1 {{protocol 'InnerProtocol' can only be used as a generic constraint because it has Self or associated type requirements}}
34+
func f() { let _ = InnerProtocol.self } // Ok
3635
}
3736

3837
protocol Racoon {

test/decl/nested/type_in_function.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ func freeFunction() {
144144
struct ConformingType : ProtoWithAssocType {
145145
typealias T = Int
146146

147-
func method() -> ProtoWithAssocType {}
148-
// expected-error@-1 {{can only be used as a generic constraint because it has Self or associated type requirements}}
147+
func method() -> ProtoWithAssocType {} // Ok
149148
}
150149
}
151150

test/decl/protocol/conforms/inherited.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ class B : A {
167167
}
168168

169169
func testB(_ b: B) {
170-
var _: P1 = b // expected-error{{has Self or associated type requirements}}
171-
var _: P4 = b // expected-error{{has Self or associated type requirements}}
170+
var _: P1 = b
171+
var _: P4 = b
172172
var _: P5 = b
173173
var _: P6 = b
174-
var _: P7 = b // expected-error{{has Self or associated type requirements}}
175-
var _: P8 = b // okay
176-
var _: P9 = b // expected-error{{has Self or associated type requirements}}
174+
var _: P7 = b
175+
var _: P8 = b
176+
var _: P9 = b
177177
}
178178

179179
// Class A5 conforms to P5 in an inheritable manner.

test/decl/protocol/protocols.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ struct DoesNotConform : Up {
102102
// Circular protocols
103103

104104
protocol CircleMiddle : CircleStart { func circle_middle() } // expected-error {{protocol 'CircleMiddle' refines itself}}
105-
// expected-note@-1 2 {{protocol 'CircleMiddle' declared here}}
106-
protocol CircleStart : CircleEnd { func circle_start() } // expected-error 2 {{protocol 'CircleStart' refines itself}}
105+
// expected-note@-1 {{protocol 'CircleMiddle' declared here}}
106+
protocol CircleStart : CircleEnd { func circle_start() } // expected-error {{protocol 'CircleStart' refines itself}}
107107
// expected-note@-1 {{protocol 'CircleStart' declared here}}
108-
protocol CircleEnd : CircleMiddle { func circle_end()} // expected-note 3 {{protocol 'CircleEnd' declared here}}
108+
protocol CircleEnd : CircleMiddle { func circle_end()} // expected-note 2 {{protocol 'CircleEnd' declared here}}
109109

110110
protocol CircleEntry : CircleTrivial { }
111111
protocol CircleTrivial : CircleTrivial { } // expected-error {{protocol 'CircleTrivial' refines itself}}
@@ -267,7 +267,7 @@ struct WrongIsEqual : IsEqualComparable { // expected-error{{type 'WrongIsEqual'
267267
// Using values of existential type.
268268
//===----------------------------------------------------------------------===//
269269

270-
func existentialSequence(_ e: Sequence) { // expected-error{{has Self or associated type requirements}}
270+
func existentialSequence(_ e: Sequence) {
271271
var x = e.makeIterator() // expected-error{{member 'makeIterator' cannot be used on value of protocol type 'Sequence'; use a generic constraint instead}}
272272
x.next()
273273
x.nonexistent()
@@ -278,7 +278,7 @@ protocol HasSequenceAndStream {
278278
func getR() -> R
279279
}
280280

281-
func existentialSequenceAndStreamType(_ h: HasSequenceAndStream) { // expected-error{{has Self or associated type requirements}}
281+
func existentialSequenceAndStreamType(_ h: HasSequenceAndStream) {
282282
// FIXME: Crummy diagnostics.
283283
var x = h.getR() // expected-error{{member 'getR' cannot be used on value of protocol type 'HasSequenceAndStream'; use a generic constraint instead}}
284284
x.makeIterator()
@@ -307,7 +307,7 @@ struct DictionaryIntInt {
307307
}
308308
}
309309

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
311311
var i: Int = iis[17]
312312
var i2 = i_s[17] // expected-error{{member 'subscript' cannot be used on value of protocol type 'IntSubscriptable'; use a generic constraint instead}}
313313
}
@@ -488,18 +488,18 @@ func g<T : C2>(_ x : T) {
488488

489489
class C3 : P1 {} // expected-error{{type 'C3' does not conform to protocol 'P1'}}
490490
func h<T : C3>(_ x : T) {
491-
_ = x as P1 // expected-error{{protocol 'P1' can only be used as a generic constraint because it has Self or associated type requirements}}
491+
_ = x as P1
492492
}
493493
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
495495
// FIXME: Bogus diagnostic. See SR-11920.
496496
// 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'?}}
497497
}
498498
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
500500
}
501501
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}}
502+
return x is P1
503503
}
504504

505505

test/decl/protocol/recursive_requirement.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protocol AsExistentialB {
9191
}
9292

9393
protocol AsExistentialAssocTypeA {
94-
var delegate : AsExistentialAssocTypeB? { get } // expected-error {{protocol 'AsExistentialAssocTypeB' can only be used as a generic constraint because it has Self or associated type requirements}}
94+
var delegate : AsExistentialAssocTypeB? { get }
9595
}
9696
protocol AsExistentialAssocTypeB {
9797
func aMethod(_ object : AsExistentialAssocTypeA)
@@ -103,7 +103,7 @@ protocol AsExistentialAssocTypeAgainA {
103103
associatedtype Bar
104104
}
105105
protocol AsExistentialAssocTypeAgainB {
106-
func aMethod(_ object : AsExistentialAssocTypeAgainA) // expected-error {{protocol 'AsExistentialAssocTypeAgainA' can only be used as a generic constraint because it has Self or associated type requirements}}
106+
func aMethod(_ object : AsExistentialAssocTypeAgainA)
107107
}
108108

109109
// SR-547
@@ -124,5 +124,3 @@ protocol B {
124124

125125
func observeChangeOfProperty(_ property: BC, observable: BA)
126126
}
127-
128-

test/decl/protocol/req/dynamic_self.swift

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,8 @@ enum EError : P { // expected-error{{type 'EError' does not conform to protocol
8787
func f() -> Int { 0 } // expected-note{{candidate has non-matching type '() -> Int'}}
8888
}
8989

90-
91-
// Settable storage declaration requirements with a 'Self' result type may not
92-
// be used with an existential base.
93-
protocol P2 {
94-
subscript() -> Self { get set }
95-
}
96-
protocol P3 {
97-
var prop: Self { get set }
98-
}
99-
protocol P4 {
100-
subscript<T: Sequence>() -> T where T.Element == Self { get set }
101-
}
102-
func takesP2P3P4(p2: P2, p3: P3, p4: P4) { }
103-
// expected-error@-1{{protocol 'P2' can only be used as a generic constraint because it has Self or associated type requirements}}
104-
// expected-error@-2{{protocol 'P3' can only be used as a generic constraint because it has Self or associated type requirements}}
105-
90+
// Settable storage members with a 'Self' result type may not be used with an
91+
// existential base.
10692
protocol P5 {
10793
}
10894
extension P5 {

test/stmt/foreach.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ func testOptionalSequence() {
175175
}
176176
}
177177

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) {
180180
for x in 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}}
181181
_ = x
182182
}

test/type/protocol_types.swift

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
protocol HasSelfRequirements {
44
func foo(_ x: Self)
55

6-
func returnsOwnProtocol() -> HasSelfRequirements // expected-error{{protocol 'HasSelfRequirements' can only be used as a generic constraint because it has Self or associated type requirements}} {{educational-notes=associated-type-requirements}}
6+
func returnsOwnProtocol() -> HasSelfRequirements
77
}
88
protocol Bar {
99
// init() methods should not prevent use as an existential.
@@ -36,10 +36,10 @@ func useCompoAsWhereRequirement<T>(_ x: T) where T: HasSelfRequirements & Bar {}
3636
func useCompoAliasAsWhereRequirement<T>(_ x: T) where T: Compo {}
3737
func useNestedCompoAliasAsWhereRequirement<T>(_ x: T) where T: CompoAssocType.Compo {}
3838

39-
func useAsType(_ x: HasSelfRequirements) { } // expected-error{{protocol 'HasSelfRequirements' can only be used as a generic constraint}}
40-
func useCompoAsType(_ x: HasSelfRequirements & Bar) { } // expected-error{{protocol 'HasSelfRequirements' can only be used as a generic constraint}}
41-
func useCompoAliasAsType(_ x: Compo) { } // expected-error{{protocol 'HasSelfRequirements' can only be used as a generic constraint}}
42-
func useNestedCompoAliasAsType(_ x: CompoAssocType.Compo) { } // expected-error{{protocol 'HasSelfRequirements' can only be used as a generic constraint}}
39+
func useAsType(_: HasSelfRequirements,
40+
_: HasSelfRequirements & Bar,
41+
_: Compo,
42+
_: CompoAssocType.Compo) { }
4343

4444
struct TypeRequirement<T: HasSelfRequirements> {}
4545
struct CompoTypeRequirement<T: HasSelfRequirements & Bar> {}
@@ -67,29 +67,20 @@ protocol HasAssoc {
6767
func foo()
6868
}
6969

70-
func testHasAssoc(_ x: Any) {
71-
if let p = x as? HasAssoc { // expected-error {{protocol 'HasAssoc' can only be used as a generic constraint}} {{educational-notes=associated-type-requirements}}
70+
func testHasAssoc(_ x: Any, _: HasAssoc) {
71+
if let p = x as? HasAssoc {
7272
p.foo() // don't crash here.
7373
}
7474
}
7575

76-
// rdar://problem/16803384
77-
protocol InheritsAssoc : HasAssoc {
78-
func silverSpoon()
79-
}
80-
81-
func testInheritsAssoc(_ x: InheritsAssoc) { // expected-error {{protocol 'InheritsAssoc' can only be used as a generic constraint}}
82-
x.silverSpoon()
83-
}
84-
8576
// SR-38
86-
var b: HasAssoc // expected-error {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
77+
var b: HasAssoc
8778

8879
// Further generic constraint error testing - typealias used inside statements
8980
protocol P {}
9081
typealias MoreHasAssoc = HasAssoc & P
9182
func testHasMoreAssoc(_ x: Any) {
92-
if let p = x as? MoreHasAssoc { // expected-error {{protocol 'HasAssoc' can only be used as a generic constraint}}
83+
if let p = x as? MoreHasAssoc {
9384
p.foo() // don't crash here.
9485
}
9586
}
@@ -103,43 +94,35 @@ struct Outer {
10394
typealias X = Struct1<Pub & Bar>
10495
_ = Struct1<Pub & Bar>.self
10596

106-
typealias BadAlias<T> = T
97+
typealias AliasWhere<T> = T
10798
where T : HasAssoc, T.Assoc == HasAssoc
108-
// expected-error@-1 {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
10999

110-
struct BadStruct<T>
100+
struct StructWhere<T>
111101
where T : HasAssoc,
112102
T.Assoc == HasAssoc {}
113-
// expected-error@-1 {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
114103

115-
protocol BadProtocol where T == HasAssoc {
116-
// expected-error@-1 {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
104+
protocol ProtocolWhere where T == HasAssoc {
117105
associatedtype T
118106

119107
associatedtype U : HasAssoc
120108
where U.Assoc == HasAssoc
121-
// expected-error@-1 {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
122109
}
123110

124111
extension HasAssoc where Assoc == HasAssoc {}
125-
// expected-error@-1 {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
126112

127-
func badFunction<T>(_: T)
113+
func FunctionWhere<T>(_: T)
128114
where T : HasAssoc,
129115
T.Assoc == HasAssoc {}
130-
// expected-error@-1 {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
131116

132-
struct BadSubscript {
117+
struct SubscriptWhere {
133118
subscript<T>(_: T) -> Int
134119
where T : HasAssoc,
135120
T.Assoc == HasAssoc {
136-
// expected-error@-1 {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
137121
get {}
138122
set {}
139123
}
140124
}
141125

142126
struct OuterGeneric<T> {
143127
func contextuallyGenericMethod() where T == HasAssoc {}
144-
// expected-error@-1 {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
145128
}

0 commit comments

Comments
 (0)