|
| 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 : Wrapped, 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 | +public struct MyWrappedType : Wrapped { |
| 53 | + var x: Int = 0 |
| 54 | + |
| 55 | + public init() {} |
| 56 | +} |
| 57 | + |
| 58 | +@propertyWrapper |
| 59 | +public struct PropWrapper<T> { |
| 60 | + typealias Wrapped = T |
| 61 | + |
| 62 | + public var wrappedValue: T { |
| 63 | + get { fatalError() } |
| 64 | + set { value = newValue } |
| 65 | + } |
| 66 | + |
| 67 | + var value: T? |
| 68 | + |
| 69 | + public init() {} |
| 70 | + |
| 71 | + public init(wrappedValue: T) { |
| 72 | + self.value = wrappedValue |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +//--- Client.swift |
| 77 | + |
| 78 | +import PublicModule |
| 79 | + |
| 80 | +final class S : Wrapped { |
| 81 | + @PropWrapper var x: Int |
| 82 | + |
| 83 | + required init() {} |
| 84 | + |
| 85 | + required init(x: Int) { |
| 86 | + self.x = x |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +let s = S() |
| 91 | +_ = s.$storage |
| 92 | + |
| 93 | +_ = MyWrappedType() |
0 commit comments