Skip to content

Commit b732344

Browse files
theblixguyjrose-apple
authored andcommitted
[Test] Add test cases where a protocol extension is constrained to a class and the protocol does not impose a class requirement (#26696)
1 parent 0b3c210 commit b732344

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/decl/ext/extensions.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,32 @@ struct WrapperContext {
124124
static let propUsingMember = originalValue
125125
}
126126
}
127+
128+
// Class-constrained extension where protocol does not impose class requirement
129+
130+
protocol DoesNotImposeClassReq_1 {}
131+
132+
class JustAClass: DoesNotImposeClassReq_1 {
133+
var property: String = ""
134+
}
135+
136+
extension DoesNotImposeClassReq_1 where Self: JustAClass {
137+
var wrappingProperty: String {
138+
get { return property }
139+
set { property = newValue }
140+
}
141+
}
142+
143+
let instanceOfJustAClass = JustAClass() // expected-note {{change 'let' to 'var' to make it mutable}}
144+
instanceOfJustAClass.wrappingProperty = "" // expected-error {{cannot assign to property: 'instanceOfJustAClass' is a 'let' constant}}
145+
146+
protocol DoesNotImposeClassReq_2 {
147+
var property: String { get set }
148+
}
149+
150+
extension DoesNotImposeClassReq_2 where Self : AnyObject {
151+
var wrappingProperty: String {
152+
get { property }
153+
set { property = newValue } // Okay
154+
}
155+
}

0 commit comments

Comments
 (0)