[swift-users] Calling (Void) -> () with Void

Saagar Jha saagar at saagarjha.com
Sun Jul 9 19:43:33 CDT 2017


Hello,

I’m having some odd results with closures that take Void as a parameter, and was wondering if this was expected behavior or a bug. Specifically, I have the following closure:

> Welcome to Apple Swift version 4.0 (swiftlang-900.0.45.6 clang-900.0.26).
> let foo: (Void) -> () = {}

Trying to call foo without parameters fails, of course:

> foo()
error: missing argument for parameter #1 in call
foo()
    ^
    <#Void#>

However, the fix-it doesn’t seem to work:

> foo(Void) // or even: foo(Void())
error: argument passed to call that takes no arguments
foo(Void)
   ^~~~~~

while

> foo(()) // Executes with no errors

works. Since Void is a typealias for () this should work, shouldn’t it? Just wanted to confirm that I’m not going crazy here.

Regards,
Saagar Jha

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170709/c3b1747e/attachment.html>


More information about the swift-users mailing list