Hey there,
When I run the following 50 lines of code in release
mode, or turn Optimization on in Build-Settings Swift Compiler - Code Generation
I will get the following crash.
Anyone any idea why that happens? (Xcode 13.4.1, happens on Device as well as simulator on iOS 15.5 and 15.6)
Example Project: https://github.com/Bersaelor/ResourceCrashMinimalDemo
#0 0x000000010265dd58 in assignWithCopy for Resource ()
#1 0x000000010265d73c in outlined init with copy of Resource<VoidPayload, String> ()
#2 0x000000010265d5dc in specialized Resource<>.init(url:method:query:authToken:headers:) [inlined] at /Users/konradfeiler/Source/ResourceCrashMinimalDemo/ResourceCrashMinimalDemo/ContentView.swift:51
#3 0x000000010265d584 in specialized ContentView.crash() at /Users/konradfeiler/Source/ResourceCrashMinimalDemo/ResourceCrashMinimalDemo/ContentView.swift:18
Code needed:
import SwiftUI
struct ContentView: View {
var body: some View {
Button(action: { crash() }, label: { Text("Create Resouce") })
}
/// crashes in `outlined init with copy of Resource<VoidPayload, String>`
func crash() {
let testURL = URL(string: "https://www.google.com")!
let r = Resource<VoidPayload, String>(url: testURL, method: .get, authToken: nil)
print("r: \(r)")
}
}
struct VoidPayload {}
enum HTTPMethod<Payload> {
case get
case post(Payload)
case patch(Payload)
}
struct Resource<Payload, Response> {
let url: URL
let method: HTTPMethod<Payload>
let query: [(String, String)]
let authToken: String?
let parse: (Data) throws -> Response
}
extension Resource where Response: Decodable {
init(
url: URL,
method: HTTPMethod<Payload>,
query: [(String, String)] = [],
authToken: String?,
headers: [String: String] = [:]
) {
self.url = url
self.method = method
self.query = query
self.authToken = authToken
self.parse = {
return try JSONDecoder().decode(Response.self, from: $0)
}
}
}