Hmm. I'm also having second thoughts about that Fix-It. I wonder if the "fix" that's automatically provided is little more than "press here to make the red thingy go away and do nothing else."<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: "Hey, we think you accidentally swapped your labels. Do you want us to fix it?" And the default fix, which some people are guaranteed to choose without even reading the error very carefully, shouldn't be "Leave the labels swapped even though it looks wrong, and just rewrite that line so the error disappears!"<br><div class="gmail_quote"><div dir="ltr">On Mon, May 9, 2016 at 05:09 Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com">xiaodi.wu@gmail.com</a>> 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's a tuple *pattern*, you'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"><<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-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Also--I didn'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'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 "as", 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"><<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-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'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><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"><<a href="mailto:jtbandes@gmail.com" target="_blank">jtbandes@gmail.com</a>></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() -> (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><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"><<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></div></div>
</blockquote></div><br></div></div></div></div></div>
</blockquote></div><br></div></div></blockquote></div>