<div dir="ltr">Hmm, not as sure about that one. To my mind it's a clear expression of intent there. You're saying you know what the labels are and you're choosing not to repeat them. I think it should be on you if you express that intent and you're just plain wrong.<div class="gmail_extra"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 9, 2016 at 2:32 AM, Jacob Bandes-Storch <span dir="ltr"><<a href="mailto:jtbandes@gmail.com" target="_blank">jtbandes@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">... and one might also want to require labels when passing values *to* a labeled tuple:<span class=""><div><br></div><div> func foo() -> (left: Int, right: Int) {</div></span><div> return (3, 4) // error: conversion between tuple types '(Int, Int)' and '(left: Int, right: Int)' requires explicit 'as' operator</div><div> }<br><div class="gmail_extra"><br></div><div class="gmail_extra">I've personally been bitten by a typo of this sort (mistakenly swapping the values) before.</div><div class="gmail_extra"><span class="HOEnZb"><font color="#888888"><div><div><div dir="ltr"><div>Jacob<br></div></div></div></div></font></span><div><div class="h5">
<br><div class="gmail_quote">On Mon, May 9, 2016 at 12:23 AM, Xiaodi Wu <span dir="ltr"><<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">A sensible solution, IMO. Error with Fix-It when attempting to convert implicitly between tuples with mismatched labels.<br><br><div class="gmail_quote"><div><div><div dir="ltr">On Mon, May 9, 2016 at 01:47 Jacob Bandes-Storch via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div><div dir="ltr"><div>There was some previous discussion under "<a href="http://thread.gmane.org/gmane.comp.lang.swift.evolution/14910" target="_blank">[Discussion] Enforce argument labels on tuples</a>".</div><div><br></div><div>Halfway through the thread, Haravikk clearly stated the key point:</div><div><br></div><div>On Thu, Apr 21, 2016 at 12:14 AM, Haravikk via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"></div></blockquote><blockquote style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex" class="gmail_quote">I think the important thing to remember is that the <span>label</span> check is intended to prevent cases like this:<br><font face="Monaco"><span style="white-space:pre-wrap">        </span>let a:(left:Int, right:Int) = (1, 2)<br></font><font face="Monaco"><span style="white-space:pre-wrap">        </span>var b:(right:Int, left:Int) = a</font><br>While the two <span>tuples</span> are compatible by type, the meaning of the values may differ due to the different <span>labels</span>; in this case the values are represented in a different order that a developer should have to explicitly reverse to ensure they aren’t making a mistake, or they could represent radically different concepts altogether.</blockquote><div><br></div><div><br></div><div>I agree there's a potential for confusion here, and I suggest we should add an error (or warning) imploring the user to make the conversion explicit, when the source tuple is labeled:</div><div><br></div><div><div> func foo() -> (left: Int, right: Int) { return (3, 4) }</div><div><br></div><div> let (left: a, right: b) = foo() // ok, labels match</div><div><br></div><div> var x = 0, y = 0</div><div> (left: x, right: y) = (1, 3) // ok, source is unlabeled</div><div><br></div><div> let (c, d) = foo()</div><div> // error: conversion between tuple types '(left: Int, right: Int)' and '(Int, Int)' requires explicit 'as' operator</div><div> // suggested fix: "let (c, d) = foo() as (Int, Int)"</div><div><br></div><div> let (right: e, left: f) = foo()</div><div> // error: conversion between tuple types '(left: Int, right: Int)' and '(right: Int, left: Int)' requires explicit 'as' operator</div><div> // suggested fix: "let (right: e, left: f) = foo() as (right: Int, left: Int)"</div></div><div> </div></div><div><br></div>Thoughts?<div><br clear="all"><div><div><div dir="ltr"><div>Jacob<br></div></div></div></div>
</div></div></div></div>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>
</blockquote></div><br></div></div></div></div></div>
</blockquote></div><br></div></div>