> main.swift:18:30: Cannot convert value of type '() -> Void' to expected argument type '(() -> Void)?'
My guess is that the type checker thinks that `(() -> Void)?` is interpreted as a tuple type. But the parens are only necessary to make the closure optional. Interestingly this only happens with function types. `(String)?` e.g. type checks correctly.
The following snippet works as expected:
functakes(anOptionalClosure: (() ->Void)?) {
iflet aClosure = anOptionalClosure {
aClosure()
}
}
// Hint: Added two surrounding parens to the argument typefunctakes(aClosure: (() ->Void)) {
takes(anOptionalClosure: aClosure)
}
The text was updated successfully, but these errors were encountered:
Note I added a comment to SR-2444 which is marked resolved because I assume it is considered a duplicate of this issue. What is described in SR-2444 is problematic still in Xcode 8 GM.
Environment
OSX 10.11.6 (15G31)
MacBook Pro (Retina, Mid 2012)
Version 8.0 beta 5 (8S193k)
Toolchain: Swift Development Snapshot 2016-08-07 (a)
Additional Detail from JIRA
md5: ab4ee203bb7d77d3976562cd10a4342c
is duplicated by:
Issue Description:
The following code snippet doesn't work anymore in the current Swift 3 snapshot:
> main.swift:18:30: Cannot convert value of type '() -> Void' to expected argument type '(() -> Void)?'
My guess is that the type checker thinks that `(() -> Void)?` is interpreted as a tuple type. But the parens are only necessary to make the closure optional. Interestingly this only happens with function types. `(String)?` e.g. type checks correctly.
The following snippet works as expected:
The text was updated successfully, but these errors were encountered: