1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
|
// RUN: %target-typecheck-verify-swift \
// RUN: -verify-additional-prefix enabled- \
// RUN: -enable-experimental-feature CoroutineAccessors \
// RUN: -debug-diagnostic-names
// RUN: %target-typecheck-verify-swift \
// RUN: -verify-additional-prefix disabled- \
// RUN: -debug-diagnostic-names
// REQUIRES: swift_feature_CoroutineAccessors
var _i: Int = 0
// Order of accessor kinds:
// readers:
// - get
// - unsafeAddress
// - _read
// - read
// writers:
// - set
// - unsafeMutableAddress
// - _modify
// - modify
// =============================================================================
// Two reads
// =============================================================================
// enabled: conflicting accessors
// disabled: implicit getter.
var ir_r: Int {
read { // expected-disabled-error{{cannot_find_in_scope}}
// expected-enabled-error@-1{{variable cannot provide both a 'read' accessor and a '_read' accessor}}
fatalError()
}
_read { // expected-disabled-error{{cannot_find_in_scope}}
// expected-enabled-note@-1{{previous_accessor}}
fatalError()
}
}
// enabled: conflicting accessors
var igr: Int {
get {
1
}
read { // expected-error{{variable cannot provide both a 'read' accessor and a getter}}
// expected-note@-4{{previous_accessor}}
// expected-disabled-error@-2{{'read' accessor is only valid when experimental feature coroutine accessors is enabled}}
yield _i
}
}
// =============================================================================
// One read, one write.
// =============================================================================
// enabled: ok
// disabled: bad keyword
var igm: Int {
get {
0
}
modify { // expected-disabled-error{{'modify' accessor is only valid when experimental feature coroutine accessors is enabled}}
yield &_i
}
}
// enabled: ok
// disabled: implicit getter
var img: Int {
modify { // expected-disabled-error{{cannot_find_in_scope}}
fatalError()
}
get { // expected-disabled-error{{cannot_find_in_scope}}
0
}
}
// enabled: ok
// disabled: bad keyword
var iuam: Int {
unsafeAddress {
UnsafePointer<Int>(bitPattern: 0x0)!
}
modify { // expected-disabled-error{{'modify' accessor is only valid when experimental feature coroutine accessors is enabled}}
yield &_i
}
}
// enabled: ok
// disabled: bad keyword
var imua: Int {
modify { // expected-disabled-error{{cannot_find_in_scope}}
fatalError()
}
unsafeAddress { // expected-disabled-error{{cannot_find_in_scope}}
UnsafePointer<Int>(bitPattern: 0x0)!
}
}
// enabled: ok
// disabled: bad keyword
var i_rm: Int {
_read {
yield _i
}
modify { // expected-disabled-error{{'modify' accessor is only valid when experimental feature coroutine accessors is enabled}}
yield &_i
}
}
// enabled: ok
// disabled: implicit getter.
var im_r: Int {
modify { // expected-disabled-error{{cannot_find_in_scope}}
fatalError()
}
_read { // expected-disabled-error{{cannot_find_in_scope}}
fatalError()
}
}
// enabled: ok
// disabled: implicit getter
var irm: Int {
read { // expected-disabled-error{{cannot_find_in_scope}}
fatalError()
}
modify { // expected-disabled-error{{cannot_find_in_scope}}
fatalError()
}
}
// enabled: ok
// disabled: implicit getter.
var imr: Int {
modify { // expected-disabled-error{{cannot_find_in_scope}}
fatalError()
}
read { // expected-disabled-error{{cannot_find_in_scope}}
fatalError()
}
}
// enabled: ok
// disabled: implicit getter
var irs: Int {
read { // expected-disabled-error{{cannot_find_in_scope}}
fatalError()
}
set { // expected-disabled-error{{cannot_find_in_scope}}
}
}
// enabled: ok
// disabled: bad keyword
var isr: Int {
set {
}
read { // expected-disabled-error{{'read' accessor is only valid when experimental feature coroutine accessors is enabled}}
fatalError()
}
}
// enabled: ok
// disabled: implicit getter.
var iruma: Int {
read { // expected-disabled-error{{cannot_find_in_scope}}
fatalError()
}
unsafeMutableAddress { // expected-disabled-error{{cannot_find_in_scope}}
UnsafeMutablePointer<Int>(bitPattern: 0x0)!
}
}
// enabled: ok
// disabled: implicit getter.
var iumar: Int {
read { // expected-disabled-error{{cannot_find_in_scope}}
fatalError()
}
unsafeMutableAddress { // expected-disabled-error{{cannot_find_in_scope}}
UnsafeMutablePointer<Int>(bitPattern: 0x0)!
}
}
// enabled: ok
// disabled: implicit getter
var ir_m: Int {
read { // expected-disabled-error{{cannot_find_in_scope}}
fatalError()
}
_modify { // expected-disabled-error{{cannot_find_in_scope}}
fatalError()
}
}
// enabled: ok
// disabled: bad keyword
var i_mr: Int {
_modify {
fatalError()
}
read { // expected-disabled-error{{'read' accessor is only valid when experimental feature coroutine accessors is enabled}}
fatalError()
}
}
// =============================================================================
// Multiple mutating only.
// =============================================================================
// enabled: need a reader.
// disabled: implicit getter.
var ims: Int {
modify { // expected-disabled-error{{cannot_find_in_scope}}
fatalError()
}
set { // expected-enabled-error{{variable with a setter must also have a getter, addressor, or 'read' accessor}}
// expected-disabled-error@-1{{cannot_find_in_scope}}
}
}
// enabled: need a reader
// disabled: bad keyword
var ism: Int {
set { // expected-error{{variable with a setter must also have a getter, addressor, or 'read' accessor}}
fatalError()
}
modify {// expected-disabled-error{{'modify' accessor is only valid when experimental feature coroutine accessors is enabled}}
fatalError()
}
}
// enabled: need a reader.
// disabled: implicit getter.
var imuma: Int {
modify { // expected-enabled-error{{variable with a 'modify' accessor must also have a getter, addressor, or 'read' accessor}}
// expected-disabled-error@-1{{cannot_find_in_scope}}
fatalError()
}
unsafeMutableAddress { // expected-disabled-error{{cannot_find_in_scope}}
UnsafeMutablePointer<Int>(bitPattern: 0x0)!
}
}
// enabled: need a reader
// disabled: bad keyword
var iumam: Int {
unsafeMutableAddress {
fatalError()
}
modify { // expected-error{{variable with a 'modify' accessor must also have a getter, addressor, or 'read' accessor}}
// expected-disabled-error@-1{{'modify' accessor is only valid when experimental feature coroutine accessors is enabled}}
fatalError()
}
}
// enabled: conflicting accessors. need a reader.
// disabled: implicit getter.
var im_m: Int {
modify { // expected-disabled-error{{cannot_find_in_scope}}
// expected-enabled-error@-1{{variable cannot provide both a 'modify' accessor and a '_modify' accessor}}
fatalError()
}
_modify { // expected-enabled-error{{variable with a '_modify' accessor must also have a getter, addressor, or 'read' accessor}}
// expected-disabled-error@-1{{cannot_find_in_scope}}
// expected-enabled-note@-2{{previous_accessor}}
fatalError()
}
}
// enabled: need a reader.
// disabled: implicit getter.
var i_mm: Int {
_modify { // expected-enabled-error{{variable with a '_modify' accessor must also have a getter, addressor, or 'read' accessor}}
// expected-disabled-error@-1{{variable with a 'modify' accessor must also have a getter, addressor, or 'read' accessor}}
// expected-note@-2{{previous_accessor}}
fatalError()
}
modify { // expected-disabled-error{{'modify' accessor is only valid when experimental feature coroutine accessors is enabled}}
// expected-error@-1{{variable cannot provide both a 'modify' accessor and a '_modify' accessor}}
fatalError()
}
}
// enabled: need a reader.
// disabled: implicit getter.
var imm: Int {
modify { // expected-enabled-error{{variable with a 'modify' accessor must also have a getter, addressor, or 'read' accessor}}
// expected-disabled-error@-1{{cannot_find_in_scope}}
fatalError()
}
modify { // expected-enabled-error{{variable already has a 'modify' accessor}}
// expected-enabled-note@-5{{previous_accessor}}
// expected-disabled-error@-2{{cannot_find_in_scope}}
fatalError()
}
}
// =============================================================================
// Multiple
// =============================================================================
// enabled: ok
// disabled: bad keyword
var i_rm_m: Int {
_read {
yield _i
}
modify { // expected-disabled-error{{'modify' accessor is only valid when experimental feature coroutine accessors is enabled}}
// expected-error@-1{{variable cannot provide both a 'modify' accessor and a '_modify' accessor}}
yield &_i
}
_modify { // expected-note{{previous_accessor}}
yield &_i
}
}
// enabled: ok
// disabled: implicit getter
var ir_rm_m: Int {
read { // expected-disabled-error{{cannot_find_in_scope}}
// expected-enabled-error@-1{{variable cannot provide both a 'read' accessor and a '_read' accessor}}
fatalError()
}
_read { // expected-disabled-error{{cannot_find_in_scope}}
// expected-enabled-note@-1{{previous_accessor}}
fatalError()
}
modify { // expected-disabled-error{{cannot_find_in_scope}}
// expected-enabled-error@-1{{variable cannot provide both a 'modify' accessor and a '_modify' accessor}}
fatalError()
}
_modify { // expected-disabled-error{{cannot_find_in_scope}}
// expected-enabled-note@-1{{previous_accessor}}
fatalError()
}
}
// =============================================================================
// Protocol Requirements
// =============================================================================
protocol P {
var goodP: Int { read set } //expected-disabled-error{{property in protocol must have explicit { get } or { get set } specifier}}
//expected-disabled-error@-1{{expected get or set in a protocol property}}
var badP: Int { read modify } //expected-enabled-error{{expected get, read, or set in a protocol property}}
//expected-disabled-error@-1{{property in protocol must have explicit { get } or { get set } specifier}}
//expected-disabled-error@-2{{expected get or set in a protocol property}}
subscript(goodS goodS: Int) -> Int { read set } //expected-disabled-error{{expected get or set in a protocol property}}
subscript(badS badS: Int) -> Int { read modify } //expected-enabled-error{{expected get, read, or set in a protocol property}}
//expected-disabled-error@-1{{expected get or set in a protocol property}}
}
|