Skip to content

Fix #5482: Empty buffer when not parsing comments #5490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,11 @@ object Scanners {
nextChar()
if (ch == '/') { skipLine(); finishComment() }
else if (ch == '*') { nextChar(); skipComment(); finishComment() }
else false
else {
// This was not a comment, remove the `/` from the buffer
commentBuf.clear()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure you can clear the buffer. This method call itself recursively for nested comment. What about removing the last character or not adding it in the first place if it is not a comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method call itself recursively for nested comment

That's what I thought too, and this is why I initially fixed it outside of def skipComment(). But it does not. There's an inner skipComment, but it will not be called unless we're actually inside a comment.

This function used to just return false to say "that's not a comment". Now it'll empty its buffer and say "that's not a comment". I think that should be safe, because the content of the buffer doesn't matter if we're not inside a comment, and it should actually be empty before we start reading the next comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes right! This is confusing

false
}
}

// Lookahead ---------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ class HoverTest {
|
|**Version**
| - 1.0""".stripMargin))
}

@Test def i5482: Unit = {
code"""object Test {
| def bar: Int = 2 / 1
| /** hello */
| def ${m1}baz${m2}: Int = ???
|}""".withSource
.hover(m1 to m2, hoverContent("Int", "hello"))
}
}