<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">It seams that I encountered bugs in function advancedBy().</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default"><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,132,0)"><span style="">//: Playground - noun: a place where people can play</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span style=""></span><br></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="color:rgb(187,44,162)">import</span><span style=""> Foundation</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span style=""></span><br></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="color:rgb(187,44,162)">do</span><span style=""> {</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">    </span><span style="color:rgb(187,44,162)">var</span><span style=""> str = </span><span style="color:rgb(209,47,27)">&quot;abcdefg&quot;</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">    </span><span style="color:rgb(187,44,162)">var</span><span style=""> range = str.</span><span style="color:rgb(112,61,170)">startIndex</span><span style="">..&lt;str.</span><span style="color:rgb(112,61,170)">endIndex</span><span style=""> </span><span style="color:rgb(0,132,0)">// 0..&lt;7</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">    str += </span><span style="color:rgb(209,47,27)">&quot;hijklmn&quot;</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">    range.</span><span style="color:rgb(112,61,170)">endIndex</span><span style=""> = str.</span><span style="color:rgb(112,61,170)">endIndex</span><span style=""> </span><span style="color:rgb(0,132,0)">// 0..&lt;14</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">    </span><span style="color:rgb(187,44,162)">let</span><span style=""> index = range.</span><span style="color:rgb(112,61,170)">startIndex</span><span style="">.</span><span style="color:rgb(61,29,129)">advancedBy</span><span style="">(</span><span style="color:rgb(39,42,216)">10</span><span style="">)</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span><span style="">//fatal error: cannot increment endIndex</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">}</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span style=""></span><br></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="color:rgb(187,44,162)">do</span><span style=""> {</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">    </span><span style="color:rgb(187,44,162)">var</span><span style=""> str = </span><span style="color:rgb(209,47,27)">&quot;abcdefg&quot;</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">    str += </span><span style="color:rgb(209,47,27)">&quot;hijklmn&quot;</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span style="">    </span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">    </span><span style="color:rgb(187,44,162)">var</span><span style=""> range = str.</span><span style="color:rgb(112,61,170)">startIndex</span><span style="">..&lt;str.</span><span style="color:rgb(112,61,170)">endIndex</span><span style=""> </span><span style="color:rgb(0,132,0)">// 0..&lt;14</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">    </span><span style="color:rgb(187,44,162)">let</span><span style=""> index = range.</span><span style="color:rgb(112,61,170)">startIndex</span><span style="">.</span><span style="color:rgb(61,29,129)">advancedBy</span><span style="">(</span><span style="color:rgb(39,42,216)">10</span><span style="">)</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">    range </span><span style="color:rgb(0,132,0)">// 0..&lt;14</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">}</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span style=""></span><br></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="color:rgb(187,44,162)">do</span><span style=""> {</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">    </span><span style="color:rgb(187,44,162)">var</span><span style=""> range = </span><span style="color:rgb(39,42,216)">0</span><span style="">..&lt;</span><span style="color:rgb(39,42,216)">7</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">    </span><span style="color:rgb(187,44,162)">let</span><span style=""> index = range.</span><span style="color:rgb(112,61,170)">startIndex</span><span style="">.</span><span style="color:rgb(61,29,129)">advancedBy</span><span style="">(</span><span style="color:rgb(39,42,216)">10</span><span style="">)</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">    range </span><span style="color:rgb(0,132,0)">// 0..&lt;7</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,132,0)">

























</p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">}</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style=""><br></span></p><p style="margin:0px;line-height:normal"><font face="georgia, serif">There are three do blocks. All codes are similar.</font></p><p style="margin:0px;line-height:normal"><font face="georgia, serif"><br></font></p><p style="margin:0px;line-height:normal"><font face="georgia, serif">First block and second block is the almost same. But I encounter an error in the first block, saying &quot;fatal error: cannot increment endIndex</font><span style="font-family:georgia,serif">&quot;. It shouldn&#39;t appear as the endIndex of range is 14 instead 7.</span></p><p style="margin:0px;line-height:normal"><span style="font-family:georgia,serif"><br></span></p><p style="margin:0px;line-height:normal"><span style="font-family:georgia,serif">Second block and third block both used function advancedBy, however, in the second block, the method is from </span><font face="georgia, serif">BidirectionalIndexType, </font></p><p style="margin:0px;line-height:normal"><font face="georgia, serif"><br></font></p></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_default"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)"><span style="color:rgb(187,44,162)">extension</span><span style="color:rgb(0,0,0)"> </span><span style="">BidirectionalIndexType</span><span style="color:rgb(0,0,0)"> {</span></p></div><div class="gmail_default"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="color:rgb(0,0,0)">    </span><span style="">@warn_unused_result</span></p></div><div class="gmail_default"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">    </span><span style="color:rgb(187,44,162)">public</span><span style=""> </span><span style="color:rgb(187,44,162)">func</span><span style=""> advancedBy(n: </span><span style="color:rgb(112,61,170)">Self</span><span style="">.</span><span style="color:rgb(112,61,170)">Distance</span><span style="">) -&gt; </span><span style="color:rgb(112,61,170)">Self</span></p></div><div class="gmail_default"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="color:rgb(0,0,0)">    </span><span style="">@warn_unused_result</span></p></div><div class="gmail_default"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">    </span><span style="color:rgb(187,44,162)">public</span><span style=""> </span><span style="color:rgb(187,44,162)">func</span><span style=""> advancedBy(n: </span><span style="color:rgb(112,61,170)">Self</span><span style="">.</span><span style="color:rgb(112,61,170)">Distance</span><span style="">, limit: </span><span style="color:rgb(112,61,170)">Self</span><span style="">) -&gt; </span><span style="color:rgb(112,61,170)">Self</span></p></div><div class="gmail_default"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">}</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""><br></span></p></div></blockquote><div class="gmail_default" style="display:inline"><font face="georgia, serif">​in the ​third block, it is RandomAccessIndexType,</font></div><br><div class="gmail_default"><p style="margin:0px;line-height:normal">




</p></div><div><div class="gmail_default" style="display:inline"><font face="georgia, serif"><br></font></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)"><span style="color:rgb(187,44,162)">extension</span><span style="color:rgb(0,0,0)"> </span><span style="">Int</span><span style="color:rgb(0,0,0)"> : </span><span style="">RandomAccessIndexType</span><span style="color:rgb(0,0,0)"> {</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span><span style="">/// Returns the next consecutive value after `self`.</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">    </span><span style="color:rgb(0,132,0)">///</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span><span style="">/// - Requires: The next value is representable.</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">    </span><span style="color:rgb(187,44,162)">public</span><span style=""> </span><span style="color:rgb(187,44,162)">func</span><span style=""> successor() -&gt; </span><span style="color:rgb(112,61,170)">Int</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span><span style="">/// Returns the previous consecutive value before `self`.</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">    </span><span style="color:rgb(0,132,0)">///</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span><span style="">/// - Requires: The previous value is representable.</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">    </span><span style="color:rgb(187,44,162)">public</span><span style=""> </span><span style="color:rgb(187,44,162)">func</span><span style=""> predecessor() -&gt; </span><span style="color:rgb(112,61,170)">Int</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">    </span><span style="color:rgb(187,44,162)">public</span><span style=""> </span><span style="color:rgb(187,44,162)">func</span><span style=""> distanceTo(other: </span><span style="color:rgb(112,61,170)">Int</span><span style="">) -&gt; </span><span style="color:rgb(112,61,170)">Distance</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">    </span><span style="color:rgb(187,44,162)">public</span><span style=""> </span><span style="color:rgb(187,44,162)">func</span><span style=""> advancedBy(n: </span><span style="color:rgb(112,61,170)">Distance</span><span style="">) -&gt; </span><span style="color:rgb(112,61,170)">Int</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">}</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""><br></span></p></div></div></blockquote><font face="Menlo"><div class="gmail_default" style="font-family:georgia,serif;display:inline">​So the range in the third block after advancedBy is unchanged. It makes sense here. But I think people may feel strange as one is a mutating function and the other is not.</div></font><div><font face="Menlo"><div class="gmail_default" style="font-family:georgia,serif;display:inline"><br></div></font></div><div><div class="gmail_default" style="font-family:georgia,serif">​Zh​aoxin</div><br></div></div>