mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
KeyPaths: Support instantiating generic property descriptors from concrete contexts.
This is a bit easier than the fully general case where both the external descriptor and local pattern have captured arguments (because of generics or subscript indices) since we don't have to combine the two argument files in one component.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// -- Test with resilience enabled
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-build-swift -force-single-frontend-invocation -Xfrontend -enable-key-path-resilience -Xfrontend -enable-resilience -module-name KeyPathMultiModule_b -c -o %t/KeyPathMultiModule_b.o -emit-module-path %t/KeyPathMultiModule_b.swiftmodule -parse-as-library %S/Inputs/KeyPathMultiModule_b.swift
|
||||
// RUN: %target-build-swift -Xfrontend -enable-key-path-resilience %t/KeyPathMultiModule_b.o -I %t %s -o %t/a.out.resilient
|
||||
// RUN: %target-build-swift -g -Xfrontend -enable-key-path-resilience %t/KeyPathMultiModule_b.o -I %t %s -o %t/a.out.resilient
|
||||
// RUN: %target-run %t/a.out.resilient
|
||||
|
||||
// -- Test again with resilience disabled, which changes the circumstances under
|
||||
@@ -26,6 +26,12 @@ keyPathMultiModule.test("identity across multiple modules") {
|
||||
expectEqual(A_subscript_withGeneric_butt_keypath(),
|
||||
\A.[withGeneric: "pomeranian's big butt"])
|
||||
|
||||
expectEqual(B_x_keypath(Double.self), \B<Double>.x)
|
||||
expectEqual(B_Int_x_keypath(), \B<Int>.x)
|
||||
expectEqual(B_y_keypath(Double.self), \B<Double>.y)
|
||||
expectEqual(B_Int_y_keypath(), \B<Int>.y)
|
||||
expectEqual(B_z_keypath(Double.self), \B<Double>.z)
|
||||
expectEqual(B_Int_z_keypath(), \B<Int>.z)
|
||||
expectEqual(B_subscript_withInt_keypath(Double.self, index: 1738),
|
||||
\B<Double>.[withInt: 1738])
|
||||
expectEqual(B_subscript_withInt_keypath(Double.self, index: 679),
|
||||
@@ -42,6 +48,26 @@ keyPathMultiModule.test("identity across multiple modules") {
|
||||
expectEqual(A_storedB_keypath(), \A.storedB)
|
||||
expectEqual(B_storedA_keypath(Double.self), \B<Double>.storedA)
|
||||
expectEqual(B_storedB_keypath(Double.self), \B<Double>.storedB)
|
||||
expectEqual(B_Int_storedA_keypath(), \B<Int>.storedA)
|
||||
expectEqual(B_Int_storedB_keypath(), \B<Int>.storedB)
|
||||
|
||||
func testInGenericContext<X, Y: Hashable>(x: X, y: Y) {
|
||||
expectEqual(A_subscript_withGeneric_keypath(index: y), \A.[withGeneric: y])
|
||||
|
||||
expectEqual(B_x_keypath(X.self), \B<X>.x)
|
||||
//TODO expectEqual(B_y_keypath(X.self), \B<X>.y)
|
||||
//TODO expectEqual(B_z_keypath(X.self), \B<X>.z)
|
||||
expectEqual(B_subscript_withInt_keypath(X.self, index: 0),
|
||||
\B<X>.[withInt: 0])
|
||||
expectEqual(B_subscript_withGeneric_keypath(X.self, index: y),
|
||||
\B<X>.[withGeneric: y])
|
||||
|
||||
expectEqual(B_storedA_keypath(X.self), \B<X>.storedA)
|
||||
expectEqual(B_storedB_keypath(X.self), \B<X>.storedB)
|
||||
}
|
||||
|
||||
testInGenericContext(x: 0.0, y: 42)
|
||||
testInGenericContext(x: "pomeranian", y: "big butt")
|
||||
}
|
||||
|
||||
runAllTests()
|
||||
|
||||
Reference in New Issue
Block a user