<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>I think the fix-it is hinting that you need a value of type Void,
not literally Void itself. It's a bit confusing since () is both a
type and a value, while Void is only a type since it's declared as
a typealias. Typealiases aren't processed like macros are, it
would seem.<br>
</p>
<p>I think the convention for function types is to only use Void
after the arrow (if at all) to avoid this confusion:</p>
<p>let foo: () -> Void = {} // or just () -> (), takes no
params<br>
</p>
<p>let bar: (()) -> () // clear(er) that it takes one param of
type ()<br>
</p>
<div class="moz-cite-prefix">On 7/9/2017 8:43 PM, Saagar Jha via
swift-users wrote:<br>
</div>
<blockquote type="cite"
cite="mid:303F5549-D0D2-49CA-9C4D-6D64B6AB7210@saagarjha.com">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
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 class="" face="Menlo">> </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 class="" face="Menlo">> 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 class="" face="Menlo">> foo()</font></div>
<div class=""><font class="" face="Menlo">error: missing
argument for parameter #1 in call</font></div>
<div class=""><font class="" face="Menlo">foo()</font></div>
<div class=""><font class="" face="Menlo"> ^</font></div>
<div class=""><font class="" face="Menlo"> <#Void#></font></div>
</blockquote>
<div class=""><font class="" face="Menlo"><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 class="" face="Menlo">> foo(Void) // or
even: foo(Void())</font></div>
<div class="">
<div class=""><font class="" face="Menlo">error: argument
passed to call that takes no arguments</font></div>
</div>
<div class="">
<div class=""><font class="" face="Menlo">foo(Void)</font></div>
</div>
<div class="">
<div class=""><font class="" face="Menlo"> ^~~~~~</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 class="" face="Menlo">> 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>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
swift-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:swift-users@swift.org">swift-users@swift.org</a>
<a class="moz-txt-link-freetext" href="https://lists.swift.org/mailman/listinfo/swift-users">https://lists.swift.org/mailman/listinfo/swift-users</a>
</pre>
</blockquote>
<br>
</body>
</html>