<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Very cool!<div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: rgb(172, 172, 172);" class="">func</span> foo() -> <span style="color: rgb(112, 61, 170);" class="">Int</span> { <span style="color: rgb(172, 172, 172);" class="">return</span> <span style="color: rgb(39, 42, 216);" class="">17</span> }</div></div><div class=""><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div></div><div class=""><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #acacac" class="">func</span> bug1() -> <span style="color: #703daa" class="">Int</span> {</div></div><div class=""><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Menlo; color: rgb(172, 172, 172); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""> </span>return</div></div><div class=""><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""> </span><span style="text-decoration: underline ; color: #31595d" class="">f</span><span style="color: #31595d" class="">oo</span><span style="color: #000000" class="">() </span>// Compiler says: Expression following ‘return'</div><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""> // is treated as an argument of the 'return'.</div></div><div class=""><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div></div><div class=""><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div></div><div class=""><div class=""><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: rgb(172, 172, 172);" class="">var</span> x = <span style="color: rgb(39, 42, 216);" class="">0</span></div></div><div class=""><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div></div><div class=""><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: rgb(172, 172, 172);" class="">func</span> bug2() {</div></div><div class=""><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: rgb(0, 0, 0);" class=""> </span><span style="color: rgb(172, 172, 172);" class="">return</span><span style="color: rgb(0, 0, 0);" class=""> </span><span style="color: rgb(79, 129, 135);" class="">x</span><span style="color: rgb(0, 0, 0);" class=""> = </span><span style="color: rgb(39, 42, 216);" class="">4</span><span style="color: rgb(0, 0, 0);" class=""> </span>// not even a warning – should be an error</div></div><div class=""><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div></div><div class=""><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div></div><div class=""></div><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93); background-color: rgb(255, 255, 255);" class=""><span style="color: rgb(62, 30, 129);" class="">print</span><span style="color: rgb(0, 0, 0);" class="">(</span>bug1<span style="color: rgb(0, 0, 0);" class="">()) </span><span style="color: rgb(0, 132, 0);" class="">// prints 17</span></div></div><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93); background-color: rgb(255, 255, 255);" class=""><div style="color: rgb(0, 0, 0); font-family: Optima; font-size: 13px;" class=""><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class="">bug2<span style="color: rgb(0, 0, 0);" class="">()</span></div></div><div style="color: rgb(0, 0, 0); font-family: Optima; font-size: 13px;" class=""></div></div></blockquote><div class=""><div class=""><br class=""></div><div class="">
<div id="signature" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); font-family: Optima; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Dave</div><div style="color: rgb(0, 0, 0); font-family: Optima; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div></div></div></div><div class=""><font color="#3e1e81" face="Menlo" size="1" class="">bug1()</font> suggests that <span style="font-family: Menlo; font-size: 10px; background-color: rgb(255, 255, 255);" class="">return</span> be one of perhaps a set of special cases where line wrap is illegal.</div><div class=""><br class=""></div><div class=""><font color="#3e1e81" face="Menlo" size="1" class="">bug2()</font> is a compiler bug IMO.</div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On 2017-10-15, at 8:32 AM, Mike Kluev via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class="">on Date: Fri, 13 Oct 2017 20:21:22 -0700 Chris Lattner <<a href="mailto:clattner@nondot.org" class="">clattner@nondot.org</a>> wrote:</div><div class=""><br class=""></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">
We already have whitespace sensitive rules to handle this. There is no fundamental implementation difference that I see between separating the elements of lists (which are expressions) and the elements of statements (which can be expressions):<br class="">
<br class="">
func foo() -> Int { … }<br class="">
<br class="">
func statements() {<br class="">
foo()<br class="">
foo()<br class="">
}<br class="">
<br class="">
let list = [<br class="">
foo()<br class="">
foo()<br class="">
]<br class=""></blockquote><div class=""><br class=""></div><div class="">i was beaten by these optional semicolons...</div><div class=""><br class=""></div><div class="">override func viewDidLoad() {</div><div class=""><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>super.viewDidLoad()</div><div class=""><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>return<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>// put it ad-hoc to temporarily circumvent the rest of the code</div><div class=""><span class="gmail-Apple-tab-span" style="white-space:pre">                </span></div><div class=""><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>someView = SomeView(frame: view.bounds)<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>// *</div><div class=""><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>view.addSubview(someView)<span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>// **</div><div class=""><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>...</div><div class="">}</div><div class=""><span class="gmail-Apple-tab-span" style="white-space:pre">        </span></div><div class="">so i put that ad-hoc return statement to circumvent the rest of the code temporarily. of course i didn't put a semicolon after "return" as that skill was long lost. to my surprise the app crashed, and nowhere else but in the code that i thought was disabled...</div><div class=""><br class=""></div><div class="">further investigation showed that in this case compiler was treating the statement after return which happened to have the matching type “Void” as part of return statement.</div><div class=""><br class=""></div><div class="">should the function return type was, say, Int - that wouldn’t happen. or should the next statement was of a different type - that wouldn’t happen. in this case i was just “lucky”. here semantic information (matching vs non matching types) is clearly "aiding" syntax parsing and sometimes it leads to a surprising results.</div><div class=""><br class=""></div><div class="">there was a warning on the * line:</div><div class="">“warning: expression following 'return' is treated as an argument of the 'return’”</div><div class=""><br class=""></div><div class="">and another warning on the ** line:</div><div class="">“warning: code after 'return' will never be executed”</div><div class=""><br class=""></div><div class="">as i was prepared to get the warning about the code being unused in the first place, i didn’t pay too much attention to the exact wording of that warning... and was beaten by it.</div><div class=""><br class=""></div><div class="">Mike</div><div class=""><br class=""></div></div></div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>