ios – Crash with message “outlined init with take of any protocol”



I have the following very simple code:

protocol Delegate<T> {
    associatedtype T
    func f(t: T)

class ConcreteClass: Delegate {
    func f(t: Int) { }

class A<T> {

    private let delegate: any Delegate<T>
    init(delegate: any Delegate<T>) {
        self.delegate = delegate

let a = A(delegate: ConcreteClass())

If it runs in Debug mode and everything is fine. However if run in release or Optimization Level of Swift Compiler - Code Generation is Optimize for Speed [-O] then it crashes with the following:

#0  0x0000000100003b49 in outlined init with take of any Delegate<Self.Delegate.T == Int> ()
#1  0x0000000100003ac4 in specialized A.init(delegate:) [inlined] at /Users/plamen/Projects/Tests/TestCrash2/TestCrash2/main.swift:25
#2  0x0000000100003ab7 in specialized A.__allocating_init(delegate:) [inlined] at /Users/plamen/Projects/Tests/TestCrash2/TestCrash2/main.swift:24
#3  0x0000000100003a96 in main at /Users/plamen/Projects/Tests/TestCrash2/TestCrash2/main.swift:29
#4  0x000000010001952e in start ()


Any ideas why? Is it bug in the optimiser?