Skip to content

Commit 494a689

Browse files
committed
[test] coverage for key paths to effectful prop/subscript
1 parent e418403 commit 494a689

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency
2+
3+
// REQUIRES: concurrency
4+
// REQUIRES: objc_interop
5+
6+
enum E : Error {
7+
case DoesNotExist
8+
}
9+
10+
class Vertex {
11+
var marked : Bool = false
12+
13+
// FIXME: we should suppress this note about adding @objc, since that's not allowed!
14+
15+
// expected-note@+2 {{add '@objc' to expose this property to Objective-C}}
16+
// expected-note@+1 5 {{property declared here}}
17+
var parent : Vertex {
18+
get throws { throw E.DoesNotExist }
19+
}
20+
21+
// expected-note@+1 2 {{subscript declared here}}
22+
subscript(_ i : Int) -> Vertex? {
23+
get async throws {
24+
if i == 0 {
25+
return try? parent
26+
}
27+
return Vertex()
28+
}
29+
}
30+
}
31+
32+
func asFunction(_ f : (Vertex) -> Bool) {}
33+
34+
let _ = \Vertex.parent.parent.parent // expected-error 3 {{cannot form key path to property with 'throws' or 'async'}}
35+
let _ = \Vertex.[3]?.marked // expected-error {{cannot form key path to subscript with 'throws' or 'async'}}
36+
37+
asFunction(\Vertex.[0]!.marked) // expected-error {{cannot form key path to subscript with 'throws' or 'async'}}
38+
asFunction(\Vertex.parent.marked) // expected-error {{cannot form key path to property with 'throws' or 'async'}}
39+
40+
// expected-error@+2 {{argument of '#keyPath' refers to non-'@objc' property 'parent'}}
41+
// expected-error@+1 {{cannot form key path to property with 'throws' or 'async'}}
42+
let _ = #keyPath(Vertex.parent)
43+

0 commit comments

Comments
 (0)