Skip to content

Commit 87c039e

Browse files
committed
Fix 1375: Infinite loop in interpreter
1 parent 6ca5b9d commit 87c039e

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/dotty/tools/dotc/printing/SyntaxHighlighting.scala

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package printing
44

55
import parsing.Tokens._
66
import scala.annotation.switch
7+
import scala.collection.mutable
78
import scala.collection.mutable.StringBuilder
89

910
/** This object provides functions for syntax highlighting in the REPL */
@@ -38,7 +39,7 @@ object SyntaxHighlighting {
3839
def apply(chars: Iterable[Char]): Vector[Char] = {
3940
var prev: Char = 0
4041
var remaining = chars.toStream
41-
val newBuf = new StringBuilder
42+
val newBuf = new mutable.StringBuilder
4243

4344
@inline def keywordStart =
4445
prev == 0 || prev == ' ' || prev == '{' || prev == '(' || prev == '\n'
@@ -77,10 +78,15 @@ object SyntaxHighlighting {
7778
(n: @switch) match {
7879
case '/' =>
7980
if (remaining.nonEmpty) {
80-
takeChar() match {
81-
case '/' => eolComment()
82-
case '*' => blockComment()
83-
case x => newBuf += '/'; remaining = x #:: remaining
81+
remaining.head match {
82+
case '/' =>
83+
takeChar()
84+
eolComment()
85+
case '*' =>
86+
takeChar()
87+
blockComment()
88+
case x =>
89+
newBuf += '/'
8490
}
8591
} else newBuf += '/'
8692
case '=' =>
@@ -262,4 +268,5 @@ object SyntaxHighlighting {
262268

263269
newBuf.toVector
264270
}
271+
265272
}

0 commit comments

Comments
 (0)