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
Infer selectors from protocols for property accessors too. (#6634)
Most property accessors have selectors matching their protocols, but
not all. Don't force the user to write '@objc' explicitly on an
accessor, which isn't even possible for stored properties.
More groundwork for rdar://problem/28543037.
Copy file name to clipboardExpand all lines: test/decl/protocol/objc.swift
+89-2Lines changed: 89 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -45,15 +45,15 @@ class C2a : P2 {
45
45
func method(_:Int, class:ObjCClass){}
46
46
47
47
varempty:Bool{
48
-
get{} // expected-error{{Objective-C method 'empty' provided by getter for 'empty' does not match the requirement's selector ('checkIfEmpty')}}
48
+
get{}
49
49
}
50
50
}
51
51
52
52
classC2b:P2{
53
53
@objcfunc method(_:Int, class:ObjCClass){}
54
54
55
55
@objcvarempty:Bool{
56
-
@objcget{} // expected-error{{Objective-C method 'empty' provided by getter for 'empty' does not match the requirement's selector ('checkIfEmpty')}}{{10-10=(checkIfEmpty)}}
56
+
@objcget{}
57
57
}
58
58
}
59
59
@@ -146,3 +146,90 @@ class C4_5a : P4, P5 {
146
146
classC6a:P6{
147
147
func doSomething(sender:AnyObject?){} // expected-error{{method 'doSomething(sender:)' has different argument names from those required by protocol 'P6' ('doSomething')}}{{20-20=_ }}{{none}}
148
148
}
149
+
150
+
151
+
152
+
@objcprotocolP7{
153
+
var prop:Int{
154
+
@objc(getTheProp) get
155
+
@objc(setTheProp:) set
156
+
}
157
+
}
158
+
159
+
classC7:P7{
160
+
varprop:Int{
161
+
get{return0}
162
+
set{}
163
+
}
164
+
}
165
+
166
+
classC7a:P7{
167
+
@objcvarprop:Int{
168
+
get{return0}
169
+
set{}
170
+
}
171
+
}
172
+
173
+
classC7b:P7{
174
+
@objcvarprop:Int{
175
+
@objc(getTheProp)get{return0}
176
+
@objc(setTheProp:)set{}
177
+
}
178
+
}
179
+
180
+
classC7c:P7{
181
+
varprop:Int=0
182
+
}
183
+
184
+
classC7d:P7{
185
+
@objcvarprop:Int=0
186
+
}
187
+
188
+
classC7e:P7{
189
+
// FIXME: This should probably still complain.
190
+
@objc(notProp)varprop:Int{
191
+
get{return0}
192
+
set{}
193
+
}
194
+
}
195
+
196
+
classC7f:P7{
197
+
varprop:Int{
198
+
@objc(getProp)get{return0} // expected-error {{Objective-C method 'getProp' provided by getter for 'prop' does not match the requirement's selector ('getTheProp')}} {{11-18=getTheProp}}
199
+
set{}
200
+
}
201
+
}
202
+
203
+
classC7g:P7{
204
+
varprop:Int{
205
+
get{return0}
206
+
@objc(prop:)set{} // expected-error {{Objective-C method 'prop:' provided by setter for 'prop' does not match the requirement's selector ('setTheProp:')}} {{11-16=setTheProp:}}
207
+
}
208
+
}
209
+
210
+
@objcprotocolP8{
211
+
@objcoptionalvar prop:Int{
212
+
@objc(getTheProp) get
213
+
}
214
+
}
215
+
216
+
classC8Base:P8{}
217
+
classC8Sub:C8Base{
218
+
varprop:Int{return0} // expected-note {{getter for 'prop' declared here}}
219
+
220
+
@objc(getTheProp)func collision(){} // expected-error {{method 'collision()' with Objective-C selector 'getTheProp' conflicts with getter for 'prop' with the same Objective-C selector}}
221
+
}
222
+
classC8SubA:C8Base{
223
+
varprop:Int{
224
+
@objcget{return0} // expected-note {{getter for 'prop' declared here}}
225
+
}
226
+
227
+
@objc(getTheProp)func collision(){} // expected-error {{method 'collision()' with Objective-C selector 'getTheProp' conflicts with getter for 'prop' with the same Objective-C selector}}
0 commit comments