Skip to content

Commit a93833c

Browse files
committed
Fix index out of bounds
1 parent 253876c commit a93833c

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -653,22 +653,20 @@ object Parsers {
653653
* to ensure an indent region is properly closed by outdentation */
654654
var maximumIndent: Option[IndentWidth] = None
655655

656-
def testChar(idx: Int, p: Char => Boolean): Boolean = {
656+
def testChar(idx: Int, p: Char => Boolean): Boolean =
657657
val txt = source.content
658-
idx < txt.length && p(txt(idx))
659-
}
658+
idx > -1 && idx < txt.length && p(txt(idx))
660659

661-
def testChar(idx: Int, c: Char): Boolean = {
660+
def testChar(idx: Int, c: Char): Boolean =
662661
val txt = source.content
663-
idx < txt.length && txt(idx) == c
664-
}
662+
idx > -1 && idx < txt.length && txt(idx) == c
665663

666664
def testChars(from: Int, str: String): Boolean =
667665
str.isEmpty ||
668666
testChar(from, str.head) && testChars(from + 1, str.tail)
669667

670668
def skipBlanks(idx: Int, step: Int = 1): Int =
671-
if (testChar(idx, c => c == ' ' || c == '\t' || c == Chars.CR)) skipBlanks(idx + step, step)
669+
if testChar(idx, c => c == ' ' || c == '\t' || c == Chars.CR) then skipBlanks(idx + step, step)
672670
else idx
673671

674672
/** Parse indentation region `body` and rewrite it to be in braces instead */

0 commit comments

Comments
 (0)