<div dir="ltr">... and one might also want to require labels when passing values *to* a labeled tuple:<div><br></div><div>    func foo() -&gt; (left: Int, right: Int) {</div><div>        return (3, 4)  // error: conversion between tuple types &#39;(Int, Int)&#39; and &#39;(left: Int, right: Int)&#39; requires explicit &#39;as&#39; operator</div><div>    }<br><div class="gmail_extra"><br></div><div class="gmail_extra">I&#39;ve personally been bitten by a typo of this sort (mistakenly swapping the values) before.</div><div class="gmail_extra"><div><div class="gmail_signature"><div dir="ltr"><div>Jacob<br></div></div></div></div>
<br><div class="gmail_quote">On Mon, May 9, 2016 at 12:23 AM, Xiaodi Wu <span dir="ltr">&lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt;</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 class="h5"><div dir="ltr">On Mon, May 9, 2016 at 01:47 Jacob Bandes-Storch via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; 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 class="h5"><div dir="ltr"><div>There was some previous discussion under &quot;<a href="http://thread.gmane.org/gmane.comp.lang.swift.evolution/14910" target="_blank">[Discussion] Enforce argument labels on tuples</a>&quot;.</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">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</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&#39;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() -&gt; (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 &#39;(left: Int, right: Int)&#39; and &#39;(Int, Int)&#39; requires explicit &#39;as&#39; operator</div><div>    // suggested fix: &quot;let (c, d) = foo() as (Int, Int)&quot;</div><div><br></div><div>    let (right: e, left: f) = foo()</div><div>    // error: conversion between tuple types &#39;(left: Int, right: Int)&#39; and &#39;(right: Int, left: Int)&#39; requires explicit &#39;as&#39; operator</div><div>    // suggested fix: &quot;let (right: e, left: f) = foo() as (right: Int, left: Int)&quot;</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>