<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hello,<div class=""><br class=""></div><div class="">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:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Menlo" class="">> </font><span style="font-family: Menlo;" class="">Welcome to Apple Swift version 4.0 (swiftlang-900.0.45.6 clang-900.0.26).</span></div><div class=""><font face="Menlo" class="">> let foo: (Void) -> () = {}</font></div></blockquote><div class=""><br class=""></div><div class="">Trying to call foo without parameters fails, of course:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Menlo" class="">> foo()</font></div><div class=""><font face="Menlo" class="">error: missing argument for parameter #1 in call</font></div><div class=""><font face="Menlo" class="">foo()</font></div><div class=""><font face="Menlo" class=""> ^</font></div><div class=""><font face="Menlo" class=""> <#Void#></font></div></blockquote><div class=""><font face="Menlo" class=""><br class=""></font></div><div class="">However, the fix-it doesn’t seem to work:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Menlo" class="">> foo(Void) // or even: foo(Void())</font></div><div class=""><div class=""><font face="Menlo" class="">error: argument passed to call that takes no arguments</font></div></div><div class=""><div class=""><font face="Menlo" class="">foo(Void)</font></div></div><div class=""><div class=""><font face="Menlo" class=""> ^~~~~~</font></div></div></blockquote><div class=""><br class=""></div><div class="">while</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Menlo" class="">> foo(()) // Executes with no errors</font></div></blockquote><div class=""><br class=""></div><div class="">works. Since Void is a typealias for () this should work, shouldn’t it? Just wanted to confirm that I’m not going crazy here.</div><div class=""><br class=""></div><div class="">Regards,<br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Saagar Jha</div>
</div>
<br class=""></div></body></html>