diff --git a/src/dotty/tools/dotc/parsing/Scanners.scala b/src/dotty/tools/dotc/parsing/Scanners.scala index 46274bcc99b8..489038f1e264 100644 --- a/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/src/dotty/tools/dotc/parsing/Scanners.scala @@ -539,21 +539,21 @@ object Scanners { if ((ch != CR) && (ch != LF) && (ch != SU)) skipLine() } @tailrec - def skipBlock(openComments: Int): Unit = { - val last = ch - nextChar() + def skipComment(): Unit = { if (ch == '/') { nextChar() - if (last == '*') { - if (openComments > 0) skipBlock(openComments - 1) - } else { - if (ch == '*') { nextChar(); skipBlock(openComments + 1) } - else skipBlock(openComments) - } + if (ch == '*') nestedComment() + skipComment() + } + else if (ch == '*') { + do nextChar() while (ch == '*') + if (ch == '/') nextChar() + else skipComment() } else if (ch == SU) incompleteInputError("unclosed comment") - else skipBlock(openComments) + else { nextChar(); skipComment() } } + def nestedComment() = { nextChar(); skipComment() } val start = lastCharOffset def finishComment(): Boolean = { if (keepComments) { @@ -565,7 +565,7 @@ object Scanners { } nextChar() if (ch == '/') { skipLine(); finishComment() } - else if (ch == '*') { nextChar(); skipBlock(0); finishComment() } + else if (ch == '*') { nextChar(); skipComment(); finishComment() } else false } diff --git a/tests/pos/i1052.scala b/tests/pos/i1052.scala new file mode 100644 index 000000000000..4ad62189d741 --- /dev/null +++ b/tests/pos/i1052.scala @@ -0,0 +1,10 @@ +package hello + +object world extends App { + println("hello dotty!") + /*/* one + */ + two + */ + println("foo") +}