|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: split-file %s %t |
| 3 | + |
| 4 | +// RUN: %target-swift-frontend -typecheck -verify \ |
| 5 | +// RUN: %t/View.swift %t/Modifier.swift %t/MyStorage.swift %t/Storage.swift %t/WrappedStorage.swift |
| 6 | + |
| 7 | +//--- Storage.swift |
| 8 | + |
| 9 | +protocol Representable { |
| 10 | + associatedtype Outputs |
| 11 | + typealias Context = RepresentableContext<Self> |
| 12 | +} |
| 13 | + |
| 14 | +struct RepresentableContext<R: Representable> {} |
| 15 | + |
| 16 | +struct Inputs<Outputs> { |
| 17 | +} |
| 18 | + |
| 19 | +protocol Storage<Value> { |
| 20 | + associatedtype Value |
| 21 | + associatedtype R: Representable |
| 22 | + |
| 23 | + func body(content: Content) -> Value |
| 24 | + |
| 25 | + typealias Content = Inputs<R.Outputs> |
| 26 | +} |
| 27 | + |
| 28 | +//--- WrappedStorage.swift |
| 29 | +private struct WrappedStorage<Base: Storage>: Storage where Base.Value == MyStorage.Value { |
| 30 | + typealias R = Base.R |
| 31 | + |
| 32 | + init(base: Base, body: @escaping (Base.Value) -> Void) { |
| 33 | + } |
| 34 | + |
| 35 | + func body(content: Content) -> Base.Value { fatalError() } |
| 36 | +} |
| 37 | + |
| 38 | +extension Storage where Value == MyStorage.Value { |
| 39 | + func withStorage(body: @escaping (Value) -> Void) -> some Storage<Value> { |
| 40 | + WrappedStorage(base: self, body: body) |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +//--- MyStorage.swift |
| 45 | +struct MyRepresentable: Representable { |
| 46 | + struct Outputs {} |
| 47 | +} |
| 48 | + |
| 49 | +struct MyStorage: Storage { |
| 50 | + typealias R = MyRepresentable |
| 51 | + |
| 52 | + struct Value: Equatable {} |
| 53 | + |
| 54 | + func body(content: Content) -> Value { |
| 55 | + fatalError() |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +//--- Modifier.swift |
| 60 | +extension P { |
| 61 | + func storage(_: some Storage) -> some P { Test() } |
| 62 | +} |
| 63 | + |
| 64 | +//--- View.swift |
| 65 | +protocol P { |
| 66 | +} |
| 67 | + |
| 68 | +struct Test: P { |
| 69 | +} |
| 70 | + |
| 71 | +func test() -> some P { |
| 72 | + let storage = MyStorage().withStorage { value in } |
| 73 | + return Test().storage(storage) |
| 74 | +} |
0 commit comments