Skip to content

Commit 5fee131

Browse files
committed
Fix #5482: Empty buffer when not parsing comments
The scanner keeps a buffer `commentBuf` which contains the content of the comment being parsed. When encountering a `/`, we check whether this is the beginning of a comment. Checking this adds the slash to the buffer. If this wasn't a comment, the buffer wasn't emptied, and the slash would still be there and would be prepended to the next comment. This commit fixes this by emptying the buffer when we detect that the slash wasn't the start of a comment. Fixes #5482
1 parent d6e67d4 commit 5fee131

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,11 @@ object Scanners {
631631
nextChar()
632632
if (ch == '/') { skipLine(); finishComment() }
633633
else if (ch == '*') { nextChar(); skipComment(); finishComment() }
634-
else false
634+
else {
635+
// This was not a comment, remove the `/` from the buffer
636+
commentBuf.clear()
637+
false
638+
}
635639
}
636640

637641
// Lookahead ---------------------------------------------------------------

language-server/test/dotty/tools/languageserver/HoverTest.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ class HoverTest {
164164
|
165165
|**Version**
166166
| - 1.0""".stripMargin))
167+
}
167168

169+
@Test def i5482: Unit = {
170+
code"""object Test {
171+
| def bar: Int = 2 / 1
172+
| /** hello */
173+
| def ${m1}baz${m2}: Int = ???
174+
|}""".withSource
175+
.hover(m1 to m2, hoverContent("Int", "hello"))
168176
}
169177
}

0 commit comments

Comments
 (0)