<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">Hi, David. From the docs for SourceRange:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class="">/// SourceRange in swift is a pair of locations.&nbsp; However, note that the end</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class="">/// location is the start of the last token in the range, not the last character</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class="">/// in the range.</div></div><div class=""><br class=""></div><div class="">This is mainly an optimization for single-token expressions, like number literals: they only need to store one location to represent the entire range. So your code is the right way to go, though if you only need the end you can ask for just that:</div><div class=""><br class=""></div><div class="">auto end = Lexer::getLocForEndOfToken(TC.Context.SourceMgr, tuple-&gt;getElement(argIdx)-&gt;getEndLoc());</div><div class=""><br class=""></div><div class="">Hope that helps,</div><div class="">Jordan</div><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jun 30, 2017, at 11:47, David Rönnqvist via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I’m trying to solve SR-4715, which is about improving the fixit for the diagnostic about out-of-order arguments. Currently I’m stuck with an issue where I can’t figure out the end of an argument expression in the TupleExpr that I have.&nbsp;<div class=""><br class=""></div><div class="">It would seem that this should work:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">auto&nbsp;tuple = cast&lt;TupleExpr&gt;(ArgExpr);</div><div class="">auto end = tuple-&gt;getElement(argIdx)-&gt;getEndLoc();</div></blockquote><div class=""><br class=""></div><div class="">but I have one unit test that’s failing because the range of the argument is incorrect. The only difference I can see in that test, compared to the similar ones that are passing is that the argument is a number with more than one digit. Looking at&nbsp;NumberLiteralExpr (the superclass of&nbsp;IntegerLiteralExpr) I can see that&nbsp;getSourceRange() only returns the DigitsLoc source location, not a range with a length.&nbsp;</div><div class=""><br class=""></div><div class="">If I instead get the CharSourceRange for that range, and get the End source location from that, it get’s me the location that I’m after:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">auto end = Lexer::getCharSourceRangeFromSourceRange(</div><div class="">&nbsp; &nbsp; TC.Context.SourceMgr,&nbsp;</div><div class="">&nbsp; &nbsp; tuple-&gt;getElement(argIdx)-&gt;getSourceRange()</div><div class="">).getEnd();&nbsp;</div></blockquote><div class=""><br class=""></div><div class="">Is this the correct way to get the location of the end of a multi digit&nbsp;NumberLiteralExpr or should the first approach have worked?&nbsp;</div><div class=""><br class=""></div><div class="">Perhaps I don’t understand the distinction between SourceRange and CharSourceRange. Is SourceRange the location of the token (where Start and End would be the same) and CharSourceRange the location of the characters?</div><div class=""><br class=""></div><div class="">Kind regards,</div><div class="">David</div></div>_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-dev<br class=""></div></blockquote></div><br class=""></body></html>