Recently I have updated my project to support Swift 4.1, and I found an incompatible issue, caused a crash.
The previous version code looks like this:
public enum XMLSubscriptResult {
/// some other implementation ....
public var xmlList:[XML]? {
do {
return try getXMLList()
} catch {
return nil
}
}
public func getXMLList() throws -> [XML] {
switch self {
case .null(let error):
throw XMLError.subscriptFailue(error)
case .string(_, let path):
throw XMLError.subscriptFailue("can not get list from attribute, from keyChain: \(path)")
case .xml(let xml, _): return [xml]
case .array(let xmls, _): return xmls
}
}
}
the reason caused the crash is because in attribute getter called a method that throws an error. After I change the attribute getter as below:
public var xmlList:[XML]? {
switch self {
case .null(_):
return nil
case .string(_, _):
return nil
case .xml(let xml, _): return [xml]
case .array(let xmls, _): return xmls
}
}
the error is gone ~
tkrajacic
(Thomas Krajacic)
2
How did this ever work before? 
I would think having a do/try inside a computed property would be fine.
jrose
(Jordan Rose)
4
I see nothing wrong with your original code. Please file a bug report at https://bugs.swift.org with a self-contained project.
tkrajacic
(Thomas Krajacic)
5
Hilariously my eyes saw a get {…} set {…} on the property. Wow, I need some sleep 
BTW return try? getXMLList() would be a nice obfuscating one liner 
griotspeak
(TJ Usiyan)
7
Does this still cause a crash for anyone? The code doesn't compile anymore, but Xcode doesn't crash for me in current versions.