Merge pull request #76743 from swiftlang/coro-pa-context

Fix partial apply forwarder emission for coroutines that are methods of structs with type parameters
This commit is contained in:
Dario Rexin
2024-11-21 03:05:25 -08:00
committed by GitHub
2 changed files with 59 additions and 52 deletions

View File

@@ -42,5 +42,39 @@ ModifyAccessorTests.test("SimpleModifyAccessor") {
expectEqual((100, 20), valueWithGradient(at: 10, of: modify_struct))
}
ModifyAccessorTests.test("GenericModifyAccessor") {
struct S<T : Differentiable & SignedNumeric & Comparable>: Differentiable {
private var _x : T
func _endMutation() {}
var x: T {
get{_x}
set(newValue) { _x = newValue }
_modify {
defer { _endMutation() }
if (x > -x) {
yield &_x
} else {
yield &_x
}
}
}
init(_ x : T) {
self._x = x
}
}
func modify_struct(_ x : Float) -> Float {
var s = S<Float>(x)
s.x *= s.x
return s.x
}
expectEqual((100, 20), valueWithGradient(at: 10, of: modify_struct))
}
runAllTests()