<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">I just make a clearer example.</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"><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)">"abcdefg"</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=""> str1 = str + </span><span style="color:rgb(209,47,27)">"hijklmn"</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="">..<str1.</span><span style="color:rgb(112,61,170)">endIndex</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)">startIndex</span><span style=""> = 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"><span style=""><br></span></p><p style="margin:0px;line-height:normal"><font face="georgia, serif">It seams that </font><font face="Menlo"><span style="font-size:11px">range.</span></font><span style="font-family:georgia,serif">startIndex internally contains a fault endIndex(str.endIndex, it should be its own endIndex, range.endIndex), which leads the issue.</span></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">Zhaoxin</font></p></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 18, 2016 at 12:02 AM, Dmitri Gribenko <span dir="ltr"><<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Tue, May 17, 2016 at 5:46 AM, zh ao via swift-users<br>
<<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br>
> It seams that I encountered bugs in function advancedBy().<br>
><br>
</span><span class="">> do {<br>
> var str = "abcdefg"<br>
> var range = str.startIndex..<str.endIndex // 0..<7<br>
> str += "hijklmn"<br>
> range.endIndex = str.endIndex // 0..<14<br>
> let index = range.startIndex.advancedBy(10)<br>
> //fatal error: cannot increment endIndex<br>
> }<br>
<br>
</span>Hi,<br>
<br>
Thank you for the report. To me, this issue looks the same as<br>
<a href="https://bugs.swift.org/browse/SR-1487" rel="noreferrer" target="_blank">https://bugs.swift.org/browse/SR-1487</a>.<br>
<span class="HOEnZb"><font color="#888888"><br>
Dmitri<br>
<br>
--<br>
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if<br>
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>>*/<br>
</font></span></blockquote></div><br></div>