Search code examples
xcodeswiftxcode7-beta5

Compilation error in Release in Xcode 7 beta 5 in Swift code


I have the following code.

class MyClass {
  private var callbacks: [()->()] = []

  func doIt(callback: (()->())?) {
    if let callback = callback {
      callbacks.append(callback)
    }

    // ... other code here
  }
}

When I build the project in Release it shows the following error:

Command failed due to signal: Abort trap: 6

Assertion failed: (PAI2->use_empty() && "Should not have any uses"), function foldInverseReabstractionThunks, file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.0.52.2/src/swift/lib/SILPasses/SILCombinerVisitors.cpp, line 549.

While running SILFunctionTransform "SIL Combine" on SILFunction "@TFC11AddCallback7MyClass4doItfS0_FGSqFT_T__T".

Note that the error appears only in Release and only in Xcode 7 beta 5. The code worked in Xcode 7 beta 4.

Demo: https://github.com/exchangegroup/add-callback-demo-ios

Looks like a bug in Swift? Submitted a bug report to Apple.

Update

The issue has been resolved in Xcode 7.0 beta 6 (7A192o).


Solution

  • I was having this same problem (beta 5 only).

    It was where I was trying to append a closure to an array of closures, it looks to be the same for yours where you have an addCallback method in your MyClass class.

    As silly as it is, I got mine to build on release from changing this code:

    callbacks.append(newCallback)

    to this

    callbacks = callbacks + [newCallback]