Skip to content

Commit e418403

Browse files
committed
[test] eff. prop + class inheritance & overrides
1 parent 47ea602 commit e418403

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency
2+
3+
// REQUIRES: concurrency
4+
5+
enum E : Error {
6+
case NotAvailable
7+
}
8+
9+
class GolfCourse {
10+
var yards : Int {
11+
get throws { throw E.NotAvailable }
12+
}
13+
var holes : Int {
14+
get { 18 }
15+
}
16+
17+
var par : Int {
18+
get async throws { 71 }
19+
}
20+
21+
subscript(_ i : Int) -> Int {
22+
get throws { throw E.NotAvailable }
23+
}
24+
}
25+
26+
class Presidio : GolfCourse {
27+
private var yardsFromBackTees = 6481
28+
override var yards : Int { // removes effect & makes it mutable
29+
get {
30+
do {
31+
return try super.yards
32+
} catch {
33+
return yardsFromBackTees
34+
}
35+
}
36+
set { yardsFromBackTees = newValue }
37+
}
38+
39+
override var holes : Int { // expected-error {{cannot override non-'async' property with 'async' property}}
40+
get async { 18 }
41+
}
42+
43+
override var par : Int {
44+
get async { 72 } // removes the 'throws' effect
45+
}
46+
47+
override subscript(_ i : Int) -> Int { // removes effects
48+
get { (try? super[i]) ?? 3 }
49+
}
50+
}
51+
52+
class PresidioBackNine : Presidio {
53+
override var par : Int { // expected-error{{cannot override non-'throws' property with 'throws' property}}
54+
get throws { 36 } // attempts to put the 'throws' effect back
55+
}
56+
57+
override subscript(_ i : Int) -> Int { // expected-error{{cannot override non-'async' subscript with 'async' subscript}}
58+
get async throws { 0 }
59+
}
60+
}
61+
62+
func timeToPlay(gc : Presidio) async {
63+
_ = gc.yards
64+
_ = (gc as GolfCourse).yards // expected-error{{property access can throw, but it is not marked with 'try' and the error is not handled}}
65+
_ = try? (gc as GolfCourse).yards
66+
67+
// expected-error@+2 {{property access can throw, but it is not marked with 'try' and the error is not handled}}
68+
// expected-error@+1 {{property access is 'async' but is not marked with 'await'}}
69+
_ = (gc as GolfCourse).par
70+
_ = try? await (gc as GolfCourse).par
71+
72+
_ = await gc.par
73+
74+
_ = gc[2]
75+
_ = (gc as GolfCourse)[2] // expected-error{{subscript access can throw, but it is not marked with 'try' and the error is not handled}}
76+
_ = try? (gc as GolfCourse)[2]
77+
}
78+
79+
class AcceptableDynamic {
80+
dynamic var par : Int {
81+
get async throws { 60 }
82+
}
83+
84+
dynamic subscript(_ i : Int) -> Int {
85+
get throws { throw E.NotAvailable }
86+
}
87+
}
88+
89+
// mainly just some sanity checks
90+
class Misc {
91+
// expected-error@+2 {{'lazy' cannot be used on a computed property}}
92+
// expected-error@+1 {{lazy properties must have an initializer}}
93+
lazy var someProp : Int {
94+
get throws { 0 }
95+
}
96+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency
2+
3+
// REQUIRES: concurrency
4+
// REQUIRES: objc_interop
5+
6+
enum E : Error {
7+
case NotAvailable
8+
}
9+
10+
class ProblematicObjC {
11+
@objc var par : Int { // expected-error{{property with 'throws' or 'async' is not representable in Objective-C}}
12+
get async throws { 60 }
13+
}
14+
15+
@objc subscript(_ i : Int) -> Int { // expected-error{{subscript with 'throws' or 'async' is not representable in Objective-C}}
16+
get throws { throw E.NotAvailable }
17+
}
18+
}

0 commit comments

Comments
 (0)