<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 19, 2016, at 20:35 , John McCall via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; 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;" class=""><blockquote type="cite" class=""><div class="">On Jan 19, 2016, at 7:20 PM, Paul Cantrell via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Surprisingly, this code does not compile:<div class=""><br class=""></div><div class=""><div class=""><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal;"><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(50, 62, 125);">func</span><span class="Apple-converted-space">&nbsp;</span>foo(val:<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(88, 126, 168);">Int</span>) { }</div><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal; min-height: 12px;"><br class=""></div><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(50, 62, 125);">func</span><span class="Apple-converted-space">&nbsp;</span>bar(closure: (<span class="" style="color: rgb(88, 126, 168);">Int</span>,<span class="" style="color: rgb(88, 126, 168);">Int</span>) -&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(88, 126, 168);">Void</span>) {</div><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal;">&nbsp; &nbsp; &nbsp; &nbsp; closure(<span class="" style="color: rgb(50, 62, 125);">0</span>,<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(50, 62, 125);">1</span>)</div><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal;">&nbsp; &nbsp; }</div><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal; min-height: 12px;"><br class=""></div><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(88, 126, 168);">bar</span><span class="Apple-converted-space">&nbsp;</span>{<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(88, 126, 168);">foo</span>($0) } &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(102, 139, 73);">// compiler error</span></div><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(88, 126, 168);">bar</span><span class="Apple-converted-space">&nbsp;</span>{<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(88, 126, 168);">foo</span>($1) } &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(102, 139, 73);">// just dandy</span></div><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(88, 126, 168);">bar</span><span class="Apple-converted-space">&nbsp;</span>{<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(88, 126, 168);">foo</span>($0 + $1) }&nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(102, 139, 73);">// also works</span></div><div class=""><span class="" style="color: rgb(102, 139, 73);"><br class=""></span></div></div></div></div><div class="">The compiler error is:</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; Cannot convert value of type (Int, Int) to expected argument type Int</div></div><div class=""><br class=""></div><div class="">It appears that the meaning of&nbsp;<span class="" style="font-family: Menlo; font-size: 11px;">$0</span>&nbsp;is overloaded: it can refer either to the tuple of all arguments, or to just the first argument. The presence of another placeholder variable (<span class="" style="font-family: Menlo; font-size: 11px;">$1</span>&nbsp;in the third example) seems to trigger the latter behavior.</div></div></div></blockquote><div class=""><br class=""></div>It’s dumber than that. &nbsp;The type-checker assumes that the closure has a tuple of arguments ($0, $1, …, $N), where $N is the largest N seen in the closure. &nbsp;Thus, a two-argument closure falls down if you ignore the second argument. &nbsp;It’s dumb, and we’ve known about it for a long time; and yet it’s been remarkably annoying to fix, and so we haven’t yet.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; 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;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; 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;" class="">Anyway, it’s a bug and doesn’t need to go through evolution.</div></div></blockquote><br class=""></div><div>I wouldn't go as far as to say it's a bug. It's known and occasionally useful for forwarding arguments. (For a while I had it as a fix-it for doing function representation conversions.)</div><div><br class=""></div><div>I agree that having it always be the first argument is less surprising and probably more generally useful, though.</div><div><br class=""></div><div>Jordan</div><br class=""></body></html>