I am getting this compiler error in my code and I can't figure out why:
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: swift frontend command failed due to signal (use -v to see invocation)
Command /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 254
The error is showing up somewhere in the following code segment:
var animalViewToSwap: AnimalView = animalViewMatrix.objectAtRow(0, andColumn: 0) as AnimalView
var currentRow = 0
var currentColumn = 0
var animalToSwapWith = true
var currentLocation = animalViewMatrix.findLocationOfObject(animalView)
currentRow = Int(currentLocation.row) - 1
currentColumn = Int(currentLocation.column) - 1
var rowDisplacement = 0
var columnDisplacement = 0
switch inDirection{
case "left":
columnDisplacement = withDistance * -1
if (Int(animalViewMatrix.columns) > currentColumn + columnDisplacement)&&(currentColumn + columnDisplacement >= 0)&&(animalViewMatrix.objectAtRow(CInt(currentRow), andColumn: CInt(currentColumn + columnDisplacement)) is AnimalView)
{
animalToSwapWith = true;
}
else { animalToSwapWith = false }
default:
println("error")
animalToSwapWith = false
break
}
(I have more cases that are very similar and am leaving them out for simplicity - the bug isn't in them)
First Error
One bug is in the line: animalToSwapWith = false
and if I set it to true and comment all the rest out besides the variable initialization lines the error goes away. Also if I comment all of it out but instantiate animalToSwapWith to false the error occurs even though it doesn't when it is instantiated to true.
Second Error
There is a second error in the line:if (Int(animalViewMatrix.columns) > currentColumn + columnDisplacement)&&(currentColumn + columnDisplacement >= 0)&&(animalViewMatrix.objectAtRow(CInt(currentRow), andColumn: CInt(currentColumn + columnDisplacement)) is AnimalView)
In this line all of these methods have been called earlier in the file with variables of the same types above so knowledge of the methods shouldn't matter.
Conclusion
Is there a reason why these two errors are occurring or is it because swift and Xcode-6 are still in beta testing and it is a bug in Xcode? Also note that when commenting the two errors out from each other one at a time the error message is the same.
This is a Swift compiler bug, apparently testing for two or more implicitly unwrapped optionals causes the compiler to crash under some/many circumstances. Use Apple's Bugreporter to file this issue, mark it as duplicate of rdar://17212295.
Example
Here's a minimal example that crashes with the same error:
Compile on command line as follows and witness the same crash:
I had this error and the bug was solved in Beta 7 available online today.
For the sake of providing other possible causes and how to fix them; I was trying to set the region of a map view within in dispatch block. If I commented out the setting of the region, the error goes away.
I am getting this same error when I try to extend
NSArray
to have aforeach
method:It would appear that extending NSArray with func that takes a function argument will cause the same problems. I worked around the issue by defining a
forEachInArray
function that takes theNSArray
as an argument:I was getting the same error and I tracked it down to this: I was extending
NSError
and in the extension was defining anenum
. Moving theenum
definition out of the extension fixed the error.I'm getting the same error when adopt NSTextViewDelegate protocol for my class. If I remove that protocol, compilation goes fine. Strange indeed.