inout parameter in closure crashes the Swift compiler

我们两清 提交于 2019-12-04 00:29:51

Just tested it in Swift 1.2 shipped with Xcode 6.3 beta, and it compiled successfully. So it was definitely a bug on the compiler that they solved in the last release

@Bartek Chlebek. In the code you posted, there's one ambiguous thing (goes in bold): "let bar: (inout baz: String) -> ()". When defining your function like that, you tell the compiler that you are going to return an empty tuple. It seems like the earlier versions of the compiler didn't distinguish (must be a bug in the type inferring engine) the Void type and the "empty tuple type" (which is denoted with "()"). Here is a couple of word about the syntax of tuples: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/doc/uid/TP40014097-CH31-ID448

Possible solution: explicitly specify the return value type (which is "Void" in your case). Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!