Hmm. I&#39;m also having second thoughts about that Fix-It. I wonder if the &quot;fix&quot; that&#39;s automatically provided is little more than &quot;press here to make the red thingy go away and do nothing else.&quot;<br><br>The way I see it, if the error is restricted to mismatched labels, then the presumption is that someone got the order of the labels wrong. So the error is basically: &quot;Hey, we think you accidentally swapped your labels. Do you want us to fix it?&quot; And the default fix, which some people are guaranteed to choose without even reading the error very carefully, shouldn&#39;t be &quot;Leave the labels swapped even though it looks wrong, and just rewrite that line so the error disappears!&quot;<br><div class="gmail_quote"><div dir="ltr">On Mon, May 9, 2016 at 05:09 Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com">xiaodi.wu@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Two more points to be made:<div><br></div><div>First, there are types where current behavior allowing implicit erasure and affixing of labels is a definite win. Consider:</div><div><br></div><div>```</div><div><div>typealias CartesianCoordinate = (x: Int, y: Int)</div><div>let c: CartesianCoordinate = (0, 1)</div><div>print(c.x)</div><div><br></div><div>typealias PolarCoordinate = (r: Double, theta: Double)</div><div>let p: PolarCoordinate = (0.0, M_PI)</div><div>print(p.theta)</div></div><div>```</div><div><br></div><div>Second, your examples involving pattern matching are not correct. Since it&#39;s a tuple *pattern*, you&#39;ll find that `let (right: e, left: f) = (left: 1, right: 2)` has the same effect as writing `let (left: f, right: e) = (left: 1, right: 2)`. Which is to say, left goes with left and right goes with right irrespective of the order of labels on the LHS.</div></div><div dir="ltr"><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 9, 2016 at 4:00 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-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Also--I didn&#39;t read this carefully enough in your initial example--I disagree that either (left: Int, right: Int) to (Int, Int) or vice versa should require explicit casting, and I think previous conversations on the topic showed that at least some on the list felt the same way.<div><br></div><div>Mismatched labels, yes, because IMO it&#39;s alarming without a more explicit indication of intent to assume that a user intends to swap labels going from (left: Int, right: Int) to (right: Int, left: Int). But to work around that restriction, I should be able to erase labels and affix new ones without using &quot;as&quot;, since no unintentional label swapping can occur in either direction.<div><div><div class="gmail_extra"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 9, 2016 at 2:57 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-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Hmm, not as sure about that one. To my mind it&#39;s a clear expression of intent there. You&#39;re saying you know what the labels are and you&#39;re choosing not to repeat them. I think it should be on you if you express that intent and you&#39;re just plain wrong.<div><div><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">&lt;<a href="mailto:jtbandes@gmail.com" target="_blank">jtbandes@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">... and one might also want to require labels when passing values *to* a labeled tuple:<span><div><br></div><div>    func foo() -&gt; (left: Int, right: Int) {</div></span><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"><span><font color="#888888"><div><div><div dir="ltr"><div>Jacob<br></div></div></div></div></font></span><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><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><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></div></div>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br></div></div></div></div></div>
</blockquote></div><br></div></div></blockquote></div>