Skip to content

Commit 36008a1

Browse files
committed
[NFC][Property Wrappers] Start to add Sema tests for SE-0293.
1 parent 522eedc commit 36008a1

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
struct Projection<T> {
4+
var value: T
5+
}
6+
7+
@propertyWrapper
8+
struct Wrapper<T> {
9+
var wrappedValue: T
10+
11+
init(wrappedValue: T) {
12+
self.wrappedValue = wrappedValue
13+
}
14+
15+
var projectedValue: Projection<T> {
16+
Projection(value: wrappedValue)
17+
}
18+
19+
init(projectedValue: Projection<T>) {
20+
self.wrappedValue = projectedValue.value
21+
}
22+
}
23+
24+
func globalFunc(@Wrapper arg: Int) {
25+
let _: Int = arg
26+
let _: Projection<Int> = $arg
27+
let _: Wrapper<Int> = _arg
28+
}
29+
30+
func testGloablFunc(value: Int, projection: Projection<Int>) {
31+
globalFunc(arg: value)
32+
globalFunc($arg: projection)
33+
34+
let _: (Int) -> Void = globalFunc
35+
let _: (Int) -> Void = globalFunc(arg:)
36+
let _: (Projection<Int>) -> Void = globalFunc($arg:)
37+
}
38+
39+
40+
struct S<Value> {
41+
func method(@Wrapper arg: Value) {
42+
let _: Value = arg
43+
let _: Projection<Value> = $arg
44+
let _: Wrapper<Value> = _arg
45+
}
46+
47+
static func staticMethod(@Wrapper arg: Value) {
48+
let _: Value = arg
49+
let _: Projection<Value> = $arg
50+
let _: Wrapper<Value> = _arg
51+
}
52+
}
53+
54+
func testMethods(instance: S<String>, Metatype: S<String>.Type,
55+
@Wrapper value: String) {
56+
Metatype.staticMethod(arg: value)
57+
Metatype.staticMethod($arg: $value)
58+
59+
instance.method(arg: value)
60+
instance.method($arg: $value)
61+
62+
let _: (String) -> Void = Metatype.staticMethod
63+
let _: (String) -> Void = Metatype.staticMethod(arg:)
64+
let _: (Projection<String>) -> Void = Metatype.staticMethod($arg:)
65+
66+
let _: (String) -> Void = instance.method
67+
let _: (String) -> Void = instance.method(arg:)
68+
let _: (Projection<String>) -> Void = instance.method($arg:)
69+
70+
let _: (String) -> Void = instance.method
71+
let _: (String) -> Void = instance.method(arg:)
72+
let _: (Projection<String>) -> Void = instance.method($arg:)
73+
74+
let _: (S) -> (String) -> Void = Metatype.method
75+
let _: (S) -> (String) -> Void = Metatype.method(arg:)
76+
let _: (S) -> (Projection<String>) -> Void = Metatype.method($arg:)
77+
}
78+
79+
func testClosures() {
80+
let _: (Int) -> Wrapper<Int> = { (@Wrapper value) in
81+
_value
82+
}
83+
84+
let _: (Projection<Int>) -> Wrapper<Int> = { (@Wrapper $value) in
85+
_value
86+
}
87+
}

0 commit comments

Comments
 (0)