0

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).

Community
  • 1
  • 1
Evgenii
  • 36,389
  • 27
  • 134
  • 170
  • 1
    AFAIK Xcode 7 Beta 5 has several (new) bugs in it. There's already a (official) workaround for El Capitan to get it running. Can't take long until the next release. – Fabio Poloni Aug 07 '15 at 07:24

1 Answers1

1

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]

Marcus
  • 839
  • 8
  • 14
  • Interesting, the `append` function mutates an existing array while your workaround creates a new one. It looks like the bug only shows when you mutate the array of callbacks. – Evgenii Aug 12 '15 at 06:00
  • 1
    This is fixed in Beta 6, I was able to change my code back to using append and it compiles fine. – Marcus Aug 31 '15 at 18:14