@@ -243,14 +243,88 @@ extension DoesNotImposeClassReq_3 where Self: JustAClass1 {
243
243
244
244
var anotherProperty2 : Int {
245
245
get { return someProperty }
246
- set { someProperty = newValue } // Okay
246
+ mutating set { someProperty = newValue } // Okay
247
247
}
248
248
}
249
249
250
250
let justAClass1 = JustAClass1 ( ) // expected-note {{change 'let' to 'var' to make it mutable}}
251
251
justAClass1. anotherProperty1 = 1234 // Okay
252
252
justAClass1. anotherProperty2 = 4321 // expected-error {{cannot assign to property: 'justAClass1' is a 'let' constant}}
253
253
254
+ protocol ImposeClassReq1 : AnyObject {
255
+ var someProperty : Int { get set }
256
+ }
257
+
258
+ class JustAClass2 : ImposeClassReq1 {
259
+ var someProperty = 0
260
+ }
261
+
262
+ extension ImposeClassReq1 where Self: AnyObject {
263
+ var wrappingProperty1 : Int {
264
+ get { return someProperty }
265
+ set { someProperty = newValue }
266
+ }
267
+
268
+ var wrappingProperty2 : Int {
269
+ get { return someProperty }
270
+ mutating set { someProperty = newValue } // expected-error {{'mutating' isn't valid on methods in classes or class-bound protocols}}
271
+ }
272
+
273
+ mutating func foo( ) { // expected-error {{mutating' isn't valid on methods in classes or class-bound protocols}}
274
+ someProperty = 1
275
+ }
276
+
277
+ nonmutating func bar( ) { // expected-error {{'nonmutating' isn't valid on methods in classes or class-bound protocols}}
278
+ someProperty = 2
279
+ }
280
+
281
+ func baz( ) { // Okay
282
+ someProperty = 3
283
+ }
284
+ }
285
+
286
+ extension ImposeClassReq1 {
287
+ var wrappingProperty3 : Int {
288
+ get { return someProperty }
289
+ set { someProperty = newValue }
290
+ }
291
+ }
292
+
293
+ let justAClass2 = JustAClass2 ( ) // expected-note {{change 'let' to 'var' to make it mutable}}
294
+ justAClass2. wrappingProperty1 = 9876 // Okay
295
+ justAClass2. wrappingProperty3 = 0987 // Okay
296
+ justAClass2. foo ( ) // expected-error {{cannot use mutating member on immutable value: 'justAClass2' is a 'let' constant}}
297
+ justAClass2. bar ( ) // Okay as well (complains about explicit nonmutating on decl)
298
+ justAClass2. baz ( ) // Okay
299
+
300
+ protocol ImposeClassReq2 : AnyObject {
301
+ var someProperty : Int { get set }
302
+ }
303
+
304
+ extension ImposeClassReq2 {
305
+ var wrappingProperty1 : Int {
306
+ get { return someProperty }
307
+ set { someProperty = newValue }
308
+ }
309
+
310
+ var wrappingProperty2 : Int {
311
+ get { return someProperty }
312
+ mutating set { someProperty = newValue } // expected-error {{'mutating' isn't valid on methods in classes or class-bound protocols}}
313
+ }
314
+
315
+ mutating func foo( ) { // expected-error {{mutating' isn't valid on methods in classes or class-bound protocols}}
316
+ someProperty = 1
317
+ }
318
+
319
+ nonmutating func bar( ) { // expected-error {{'nonmutating' isn't valid on methods in classes or class-bound protocols}}
320
+ someProperty = 2
321
+ }
322
+
323
+ func baz( ) { // Okay
324
+ someProperty = 3
325
+ }
326
+ }
327
+
254
328
// Reject extension of nominal type via parameterized typealias
255
329
256
330
struct Nest < Egg> { typealias Contents = Egg }
0 commit comments