File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -279,11 +279,14 @@ extension PartialCaseKeyPath {
279
279
/// type, the operation will fail.
280
280
/// - Returns: An enum for the case of this key path that holds the given value, or `nil`.
281
281
@_disfavoredOverload
282
- public func callAsFunction< Enum: CasePathable , AnyAssociatedValue > (
283
- _ value: AnyAssociatedValue
282
+ public func callAsFunction< Enum: CasePathable > (
283
+ _ value: Any
284
284
) -> Enum ?
285
285
where Root == Case < Enum > {
286
- ( Case < Enum > ( ) [ keyPath: self ] as? Case < AnyAssociatedValue > ) ? . embed ( value) as? Enum
286
+ func open< AnyAssociatedValue> ( _ value: AnyAssociatedValue ) -> Enum ? {
287
+ ( Case < Enum > ( ) [ keyPath: self ] as? Case < AnyAssociatedValue > ) ? . embed ( value) as? Enum
288
+ }
289
+ return _openExistential ( value, do: open)
287
290
}
288
291
}
289
292
Original file line number Diff line number Diff line change @@ -164,10 +164,30 @@ final class CasePathsTests: XCTestCase {
164
164
XCTAssertEqual ( . int( 42 ) , Foo . bar ( . int( 42 ) ) [ case: partialPath] as? Bar )
165
165
XCTAssertNil ( Foo . baz ( . string( " Hello " ) ) [ case: partialPath] )
166
166
}
167
+
168
+ func testExistentials( ) {
169
+ let caseA : PartialCaseKeyPath < A > = \. a
170
+ let caseB : PartialCaseKeyPath < B > = \. b
171
+
172
+ let a = A . a ( " Hello " )
173
+ guard let valueA = a [ case: caseA] else { return XCTFail ( ) }
174
+ guard let b = caseB ( valueA) else { return XCTFail ( ) }
175
+ XCTAssertEqual ( b, . b( " Hello " ) )
176
+ }
167
177
#endif
168
178
}
169
179
170
180
#if swift(>=5.9)
181
+ @CasePathable
182
+ enum A : Equatable {
183
+ case a( String )
184
+ }
185
+
186
+ @CasePathable
187
+ enum B : Equatable {
188
+ case b( String )
189
+ }
190
+
171
191
@CasePathable @dynamicMemberLookup enum Foo : Equatable {
172
192
case bar( Bar )
173
193
case baz( Baz )
You can’t perform that action at this time.
0 commit comments