mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Instead of passing in a DeclContext, which we don't have when emitting a keypath accessor, pass in a ModuleDecl and ResilienceExpansion. Keypaths now work well enough in inlinable contexts that we can check in an end-to-end resilience test.
38 lines
610 B
Swift
38 lines
610 B
Swift
|
|
#if BEFORE
|
|
|
|
public struct ResilientStruct {
|
|
public init() {}
|
|
|
|
public var value: Int = 0
|
|
|
|
public mutating func change(_ keyPath: WritableKeyPath<ResilientStruct, Int> = \.value) -> Int {
|
|
self[keyPath: keyPath] = 10
|
|
return value
|
|
}
|
|
}
|
|
|
|
#else
|
|
|
|
public struct ResilientStruct {
|
|
public init() {}
|
|
|
|
private var _value: Int = 0
|
|
|
|
public var value: Int {
|
|
get {
|
|
return -_value
|
|
}
|
|
set {
|
|
_value = -newValue
|
|
}
|
|
}
|
|
|
|
public mutating func change(_ keyPath: WritableKeyPath<ResilientStruct, Int> = \.value) -> Int {
|
|
self[keyPath: keyPath] = 10
|
|
return value
|
|
}
|
|
}
|
|
|
|
#endif
|