Represent empty position ranges as single character ranges when giving them to the user
Summary:
In the typechecker, we represent position ranges as [start, end) (that is, inclusive, exclusive). But when we want to go print them out to the user, we give them [start, end] (inclusive both sides). This makes it so that IDE behavior is correct, since they use inclusive character ranges.
But sometimes, the FFP will want to represent the empty character range. This is especially common with error messages that say "expected semicolon here", where we want to highlight the ending trivia after a token, but the token has no ending trivia. Then the expected range becomes an empty range.
This is all correct and dandy, *except* it has issues when we print it to the user. We calculate the inclusive range by essentially subtracting one from the end column number; this results in really bizarre error messages for empty ranges, where you would get characters 28-27 or characters 0--1.
To fix this, when we call Pos.info_pos on a character range that is empty, we instead highlight a single character rather than the empty range. This is preferable in all error messages rather than just an empty range, although it has the downside of sometimes looking a bit strange if it highlights only the first character of a token rather than the entire next token.
I could go in and try to make the parser much smarter about reading the next token in the case of empty trivia, but I think that this is a simpler change that still conveys decent error messages to the user.
Reviewed By: vassilmladenov
Differential Revision:
D9137731
fbshipit-source-id:
c141c007340b360fb4b8fe48e1a34a168d151060