I have some Swift code that was written in Swift 3.2, and I just attempted to use the automatic syntax converter in Xcode 9.0 to update to Swift 4.0.
It actually found nothing that needed to be converted, but during the code analysis when the compiler compiles the project, the compiler crashes with a segmentation fault. I can't share the full source code, so I created a simple example which demonstrates the same issue, and confirmed that this also produces a crash in a newly-created Swift project.
The compiler crash only appears when joining values together using string interpolation. To reproduce:
- Create a new Xcode project, and set Swift version to 3.2
- Create a new Swift class
Paste the following code into the new class:
public class SomeClass: NSObject { static let defaultStringPrefix = "abc" var a: String = "" var b: String = "" var c: String = "" lazy var concatStr: String = { let str = "\(defaultStringPrefix)/\(self.a)/\(self.b)/\(self.c)/somepage.html" return str }() }
Attempt to perform the Swift 3.2 to Swift 4.0 conversion -> This will fail and a segfault will appear with the following error:
Command failed due to Segmentation fault: 11
Stack dump:
0....(a huge load of arguments to the swift compiler)
1. While type-checking getter for concatStr at /Users/craigrouse/mobiledev/test/test/SomeClass.swift:17:14
2. While type-checking declaration 0x7ff292a86400 in module 'test'
3. While type-checking expression at [/Users/craigrouse/mobiledev/test/test/SomeClass.swift:17:34 - line:20:7] RangeText="{
let str = "\(a)/\(b)/\(c)/somepage.html"
return str
}()"
I've tried various versions of this, and if I remove the string interpolation, the problem goes away. Obviously I could avoid using the auto conversion, and set the Swift version to 4 manually in the project settings, but I'm sure others will encounter this mysterious error, and I'd like to find out what's causing it. Is there a problem with my syntax?
Thanks.