mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Swiftify] Fix return value transformation being applied last
Casting the return value to Span must be done outside withUnsafeBufferPointer, to prevent returning a ~Escapable type from a function without lifetime info. To do this we sort the transformations so that the return value transformation is performed last. There was a bug in the comparison, so the sorting was not always done correctly. rdar://147934170
This commit is contained in:
@@ -1142,7 +1142,13 @@ public struct SwiftifyImportMacro: PeerMacro {
|
||||
parsedArgs.sort { a, b in
|
||||
// make sure return value cast to Span happens last so that withUnsafeBufferPointer
|
||||
// doesn't return a ~Escapable type
|
||||
(a.pointerIndex != .return && b.pointerIndex == .return) || paramOrReturnIndex(a.pointerIndex) < paramOrReturnIndex(b.pointerIndex)
|
||||
if a.pointerIndex != .return && b.pointerIndex == .return {
|
||||
return true
|
||||
}
|
||||
if a.pointerIndex == .return && b.pointerIndex != .return {
|
||||
return false
|
||||
}
|
||||
return paramOrReturnIndex(a.pointerIndex) < paramOrReturnIndex(b.pointerIndex)
|
||||
}
|
||||
let baseBuilder = FunctionCallBuilder(funcDecl)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user