Skip to content

Commit 2a4c036

Browse files
committed
[test] parsing for effectful properties
1 parent 7825e37 commit 2a4c036

File tree

1 file changed

+177
-0
lines changed

1 file changed

+177
-0
lines changed

test/Parse/effectful_properties.swift

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency
2+
// REQUIRES: concurrency
3+
4+
struct MyProps {
5+
var prop1 : Int {
6+
get async { }
7+
}
8+
9+
var prop2 : Int {
10+
get throws { }
11+
}
12+
13+
var prop3 : Int {
14+
get async throws { }
15+
}
16+
17+
var prop1mut : Int {
18+
mutating get async { }
19+
}
20+
21+
var prop2mut : Int {
22+
mutating get throws { }
23+
}
24+
25+
var prop3mut : Int {
26+
mutating get async throws { }
27+
}
28+
}
29+
30+
struct X1 {
31+
subscript(_ i : Int) -> Int {
32+
get async {}
33+
}
34+
}
35+
36+
class X2 {
37+
subscript(_ i : Int) -> Int {
38+
get throws {}
39+
}
40+
}
41+
42+
struct X3 {
43+
subscript(_ i : Int) -> Int {
44+
get async throws {}
45+
}
46+
}
47+
48+
struct BadSubscript1 {
49+
subscript(_ i : Int) -> Int {
50+
get async throws {}
51+
set {} // expected-error {{'set' accessor is not allowed on property with 'get' accessor that is 'async' or 'throws'}}
52+
}
53+
}
54+
55+
struct BadSubscript2 {
56+
subscript(_ i : Int) -> Int {
57+
get throws {}
58+
59+
// expected-error@+2 {{'set' accessor is not allowed on property with 'get' accessor that is 'async' or 'throws'}}
60+
// expected-error@+1 {{'set' accessor cannot have specifier 'throws'}}
61+
set throws {}
62+
}
63+
}
64+
65+
struct S {
66+
var prop2 : Int {
67+
mutating get async throws { 0 }
68+
nonmutating set {} // expected-error {{'set' accessor is not allowed on property with 'get' accessor that is 'async' or 'throws'}}
69+
}
70+
}
71+
72+
var prop3 : Bool {
73+
// expected-error@+2 {{'_read' accessor is not allowed on property with 'get' accessor that is 'async' or 'throws'}}
74+
// expected-error@+1 {{variable cannot provide both a 'read' accessor and a getter}}
75+
_read { yield prop3 }
76+
77+
// expected-note@+2 {{getter defined here}}
78+
// expected-note@+1 2 {{previous definition of getter here}}
79+
get throws { false }
80+
get async { true } // expected-error{{variable already has a getter}}
81+
82+
get {} // expected-error{{variable already has a getter}}
83+
}
84+
85+
enum E {
86+
private(set) var prop4 : Double {
87+
set {} // expected-error {{'set' accessor is not allowed on property with 'get' accessor that is 'async' or 'throws'}}
88+
get async throws { 1.1 }
89+
_modify { yield &prop4 } // expected-error {{'_modify' accessor is not allowed on property with 'get' accessor that is 'async' or 'throws'}}
90+
}
91+
}
92+
93+
protocol P {
94+
associatedtype T
95+
var prop1 : T { get async throws }
96+
var prop2 : T { get async throws set } // expected-error {{'set' accessor is not allowed on property with 'get' accessor that is 'async' or 'throws'}}
97+
var prop3 : T { get throws set } // expected-error {{'set' accessor is not allowed on property with 'get' accessor that is 'async' or 'throws'}}
98+
var prop4 : T { get async }
99+
var prop5 : T { mutating get async throws }
100+
var prop6 : T { mutating get throws }
101+
var prop7 : T { mutating get async nonmutating set } // expected-error {{'set' accessor is not allowed on property with 'get' accessor that is 'async' or 'throws'}}
102+
}
103+
104+
///////////////////
105+
// invalid syntax
106+
107+
var bad1 : Int {
108+
get rethrows { 0 } // expected-error{{only function declarations may be marked 'rethrows'; did you mean 'throws'?}}
109+
110+
// expected-error@+1 {{'set' accessor is not allowed on property with 'get' accessor that is 'async' or 'throws'}}
111+
set rethrows { } // expected-error{{'set' accessor cannot have specifier 'rethrows'}}
112+
}
113+
114+
var bad2 : Int {
115+
get reasync { 0 } // expected-error{{only function declarations may be marked 'reasync'; did you mean 'async'?}}
116+
117+
// expected-error@+1 {{'set' accessor is not allowed on property with 'get' accessor that is 'async' or 'throws'}}
118+
set reasync { } // expected-error{{'set' accessor cannot have specifier 'reasync'}}
119+
}
120+
121+
var bad3 : Int {
122+
_read async { yield 0 } // expected-error{{'_read' accessor cannot have specifier 'async'}}
123+
set(theValue) async { } // expected-error{{'set' accessor cannot have specifier 'async'}}
124+
}
125+
126+
127+
var bad4 : Int = 0 {
128+
// expected-error@+4 {{'willSet' accessor cannot have specifier 'throws'}}
129+
// expected-error@+3 {{'willSet' accessor cannot have specifier 'async'}}
130+
// expected-error@+2 {{'willSet' accessor cannot have specifier 'rethrows'}}
131+
// expected-error@+1 {{'willSet' accessor cannot have specifier 'reasync'}}
132+
willSet(theValue) reasync rethrows async throws {}
133+
134+
// expected-error@+2 {{expected '{' to start 'didSet' definition}}
135+
// expected-error@+1 {{'didSet' accessor cannot have specifier 'throws'}}
136+
didSet throws bogus {}
137+
}
138+
139+
var bad5 : Int {
140+
get bogus rethrows {} // expected-error{{expected '{' to start getter definition}}
141+
}
142+
143+
var bad6 : Int {
144+
// expected-error@+2{{expected '{' to start getter definition}}
145+
// expected-error@+1 {{only function declarations may be marked 'rethrows'; did you mean 'throws'?}}
146+
get rethrows -> Int { 0 }
147+
}
148+
149+
var bad7 : Double {
150+
get throws async { 3.14 } // expected-error {{'async' must precede 'throws'}}
151+
}
152+
153+
var bad8 : Double {
154+
get {}
155+
// expected-error@+2 {{'_modify' accessor cannot have specifier 'async'}}
156+
// expected-error@+1 {{'_modify' accessor cannot have specifier 'throws'}}
157+
_modify throws async { yield &bad8 }
158+
}
159+
160+
protocol BadP {
161+
// expected-error@+3 {{'set' accessor is not allowed on property with 'get' accessor that is 'async' or 'throws'}}
162+
// expected-error@+2 {{only function declarations may be marked 'rethrows'; did you mean 'throws'?}}
163+
// expected-error@+1 {{only function declarations may be marked 'reasync'; did you mean 'async'?}}
164+
var prop1 : Int { get reasync rethrows set }
165+
166+
var prop2 : Int { get bogus rethrows set } // expected-error{{expected get or set in a protocol property}}
167+
168+
// expected-error@+2 {{only function declarations may be marked 'rethrows'; did you mean 'throws'?}}
169+
// expected-error@+1 {{expected get or set in a protocol property}}
170+
var prop3 : Int { get rethrows bogus set }
171+
172+
// expected-error@+2 {{only function declarations may be marked 'reasync'; did you mean 'async'?}}
173+
// expected-error@+1 {{expected get or set in a protocol property}}
174+
var prop4 : Int { get reasync bogus set }
175+
176+
var prop5 : Int { get throws async } // expected-error {{'async' must precede 'throws'}}
177+
}

0 commit comments

Comments
 (0)