Skip to content

Commit f99ea05

Browse files
committed
[Tests] TypeWrappers/NFC: Add a tests to round-trip type wrappers in swift interfaces
1 parent 38e7ba0 commit f99ea05

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// RUN: %empty-directory(%t/src)
2+
// RUN: %empty-directory(%t/sdk)
3+
// RUN: split-file %s %t/src
4+
5+
/// Build the library.
6+
// RUN: %target-swift-frontend -emit-module %t/src/PublicModule.swift \
7+
// RUN: -module-name PublicModule -swift-version 5 -enable-library-evolution \
8+
// RUN: -emit-module-path %t/PublicModule.swiftmodule \
9+
// RUN: -emit-module-interface-path %t/PublicModule.swiftinterface \
10+
// RUN: -emit-private-module-interface-path %t/PublicModule.private.swiftinterface \
11+
// RUN: -enable-experimental-feature TypeWrappers
12+
13+
/// Verify swiftinterfaces.
14+
// RUN: %target-swift-typecheck-module-from-interface(%t/PublicModule.swiftinterface) -module-name PublicModule
15+
// RUN: %target-swift-typecheck-module-from-interface(%t/PublicModule.private.swiftinterface) -module-name PublicModule
16+
17+
/// Test the client against the binary swiftmodule.
18+
// RUN: %target-swift-frontend -typecheck %t/src/Client.swift \
19+
// RUN: -enable-experimental-feature TypeWrappers \
20+
// RUN: -module-name Client -I %t
21+
22+
/// Test the client against the private swiftinterface.
23+
// RUN: rm %t/PublicModule.swiftmodule
24+
// RUN: %target-swift-frontend -typecheck %t/src/Client.swift \
25+
// RUN: -module-name Client -I %t \
26+
// RUN: -enable-experimental-feature TypeWrappers
27+
28+
/// Test the client against the public swiftinterface.
29+
// RUN: rm %t/PublicModule.private.swiftinterface
30+
// RUN: %target-swift-frontend -typecheck %t/src/Client.swift \
31+
// RUN: -module-name Client -I %t \
32+
// RUN: -enable-experimental-feature TypeWrappers
33+
34+
//--- PublicModule.swift
35+
@typeWrapper
36+
public struct Wrapper<W, S> {
37+
public init(for: W.Type, storage: S) {}
38+
39+
public subscript<V>(propertyKeyPath _: KeyPath<W, V>, storageKeyPath path: KeyPath<S, V>) -> V {
40+
get { fatalError() }
41+
}
42+
43+
public subscript<V>(propertyKeyPath _: KeyPath<W, V>, storageKeyPath path: WritableKeyPath<S, V>) -> V {
44+
get { fatalError() }
45+
set { }
46+
}
47+
}
48+
49+
@Wrapper
50+
public protocol Wrapped {}
51+
52+
@Wrapper
53+
public struct MyWrappedType {
54+
var x: Int = 0
55+
56+
public init() {}
57+
}
58+
59+
@propertyWrapper
60+
public struct PropWrapper<T> {
61+
typealias Wrapped = T
62+
63+
public var wrappedValue: T {
64+
get { fatalError() }
65+
set { value = newValue }
66+
}
67+
68+
var value: T?
69+
70+
public init() {}
71+
72+
public init(wrappedValue: T) {
73+
self.value = wrappedValue
74+
}
75+
}
76+
77+
//--- Client.swift
78+
79+
import PublicModule
80+
81+
@Wrapper
82+
final class S {
83+
@PropWrapper var x: Int
84+
85+
required init() {}
86+
87+
required init(x: Int) {
88+
self.x = x
89+
}
90+
}
91+
92+
let s = S()
93+
_ = s.$storage
94+
95+
_ = MyWrappedType()

0 commit comments

Comments
 (0)