mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
32 lines
583 B
Swift
32 lines
583 B
Swift
// RUN: %target-run-simple-swift | %FileCheck %s
|
|
// REQUIRES: executable_test
|
|
|
|
// https://github.com/apple/swift/issues/52070
|
|
|
|
protocol P {
|
|
associatedtype T
|
|
func foo(t: inout T)
|
|
}
|
|
struct S: P {
|
|
func foo(t: inout () -> Void) {
|
|
t()
|
|
t = { print("new") }
|
|
}
|
|
}
|
|
|
|
func doTheFoo<SomeP: P>(_ p: SomeP, _ value: SomeP.T) -> SomeP.T {
|
|
var mutableValue = value
|
|
p.foo(t: &mutableValue)
|
|
return mutableValue
|
|
}
|
|
|
|
print("START")
|
|
let newClosure = doTheFoo(S(), { print("old") })
|
|
newClosure()
|
|
print("DONE")
|
|
|
|
// CHECK: START
|
|
// CHECK-NEXT: old
|
|
// CHECK-NEXT: new
|
|
// CHECK-NEXT: DONE
|