Skip to content

Commit 2033201

Browse files
committed
[Test] Add more test cases
1 parent 952a561 commit 2033201

File tree

1 file changed

+75
-1
lines changed

1 file changed

+75
-1
lines changed

test/decl/ext/extensions.swift

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,88 @@ extension DoesNotImposeClassReq_3 where Self: JustAClass1 {
243243

244244
var anotherProperty2: Int {
245245
get { return someProperty }
246-
set { someProperty = newValue } // Okay
246+
mutating set { someProperty = newValue } // Okay
247247
}
248248
}
249249

250250
let justAClass1 = JustAClass1() // expected-note {{change 'let' to 'var' to make it mutable}}
251251
justAClass1.anotherProperty1 = 1234 // Okay
252252
justAClass1.anotherProperty2 = 4321 // expected-error {{cannot assign to property: 'justAClass1' is a 'let' constant}}
253253

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+
254328
// Reject extension of nominal type via parameterized typealias
255329

256330
struct Nest<Egg> { typealias Contents = Egg }

0 commit comments

Comments
 (0)