<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>