@@ -127,31 +127,101 @@ struct WrapperContext {
127
127
128
128
// Class-constrained extension where protocol does not impose class requirement
129
129
// SR-11298
130
+
130
131
protocol DoesNotImposeClassReq_1 { }
131
-
132
+
132
133
class JustAClass : DoesNotImposeClassReq_1 {
133
134
var property : String = " "
134
135
}
135
136
136
137
extension DoesNotImposeClassReq_1 where Self: JustAClass {
137
- var wrappingProperty : String {
138
+ var wrappingProperty1 : String {
138
139
get { return property }
139
- set { property = newValue }
140
+ set { property = newValue } // Okay
141
+ }
142
+
143
+ var wrappingProperty2 : String {
144
+ get { return property }
145
+ nonmutating set { property = newValue } // Okay
146
+ }
147
+
148
+ var wrappingProperty3 : String {
149
+ get { return property }
150
+ mutating set { property = newValue } // Okay
151
+ }
152
+
153
+ mutating func foo( ) {
154
+ property = " " // Okay
155
+ wrappingProperty1 = " " // Okay
156
+ wrappingProperty2 = " " // Okay
157
+ wrappingProperty3 = " " // Okay
158
+ }
159
+
160
+ func bar( ) { // expected-note {{mark method 'mutating' to make 'self' mutable}}{{2-2=mutating }}
161
+ property = " " // Okay
162
+ wrappingProperty1 = " " // Okay
163
+ wrappingProperty2 = " " // Okay
164
+ wrappingProperty3 = " " // expected-error {{cannot assign to property: 'self' is immutable}}
165
+ }
166
+
167
+ nonmutating func baz( ) { // expected-note {{mark method 'mutating' to make 'self' mutable}}
168
+ property = " " // Okay
169
+ wrappingProperty1 = " " // Okay
170
+ wrappingProperty2 = " " // Okay
171
+ wrappingProperty3 = " " // expected-error {{cannot assign to property: 'self' is immutable}}
140
172
}
141
173
}
142
-
143
- let instanceOfJustAClass = JustAClass ( )
144
- instanceOfJustAClass. wrappingProperty = " " // Okay
174
+
175
+ let instanceOfJustAClass1 = JustAClass ( ) // expected-note 2{{change 'let' to 'var' to make it mutable}}
176
+ instanceOfJustAClass1. wrappingProperty1 = " " // Okay
177
+ instanceOfJustAClass1. wrappingProperty2 = " " // Okay
178
+ instanceOfJustAClass1. wrappingProperty3 = " " // expected-error {{cannot assign to property: 'instanceOfJustAClass1' is a 'let' constant}}
179
+ instanceOfJustAClass1. foo ( ) // expected-error {{cannot use mutating member on immutable value: 'instanceOfJustAClass1' is a 'let' constant}}
180
+ instanceOfJustAClass1. bar ( ) // Okay
181
+
182
+ var instanceOfJustAClass2 = JustAClass ( )
183
+ instanceOfJustAClass2. foo ( ) // Okay
145
184
146
185
protocol DoesNotImposeClassReq_2 {
147
186
var property : String { get set }
148
187
}
149
188
150
189
extension DoesNotImposeClassReq_2 where Self : AnyObject {
151
- var wrappingProperty : String {
190
+ var wrappingProperty1 : String {
152
191
get { property }
153
192
set { property = newValue } // expected-error {{cannot assign to property: 'self' is immutable}}
154
193
}
194
+
195
+ var wrappingProperty2 : String {
196
+ get { property }
197
+ nonmutating set { property = newValue } // expected-error {{cannot assign to property: 'self' is immutable}}
198
+ }
199
+
200
+ var wrappingProperty3 : String {
201
+ get { property }
202
+ mutating set { property = newValue } // Okay
203
+ }
204
+
205
+ mutating func foo( ) {
206
+ property = " " // Okay
207
+ wrappingProperty1 = " " // Okay
208
+ wrappingProperty2 = " " // Okay
209
+ wrappingProperty3 = " " // Okay
210
+ }
211
+
212
+ func bar( ) { // expected-note 2{{mark method 'mutating' to make 'self' mutable}}{{2-2=mutating }}
213
+ property = " " // expected-error {{cannot assign to property: 'self' is immutable}}
214
+ wrappingProperty1 = " " // Okay
215
+ wrappingProperty2 = " " // Okay
216
+ wrappingProperty3 = " " // expected-error {{cannot assign to property: 'self' is immutable}}
217
+ }
218
+
219
+ nonmutating func baz( ) { // expected-note 2{{mark method 'mutating' to make 'self' mutable}}
220
+ property = " " // expected-error {{cannot assign to property: 'self' is immutable}}
221
+ wrappingProperty1 = " " // Okay
222
+ wrappingProperty2 = " " // Okay
223
+ wrappingProperty3 = " " // expected-error {{cannot assign to property: 'self' is immutable}}
224
+ }
155
225
}
156
226
157
227
// Reject extension of nominal type via parameterized typealias
0 commit comments