Skip to content

Commit 7684731

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 7684731

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,8 @@ object Scanners {
447447
if (skipComment()) {
448448
fetchToken()
449449
} else {
450+
// This was not a comment, remove chars that may have been added by `skipComment()`
451+
commentBuf.clear()
450452
putChar('/')
451453
getOperatorRest()
452454
}

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)