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

Conversation

Duhemm
Copy link
Contributor

@Duhemm Duhemm commented Nov 22, 2018

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

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 scala#5482
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

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.

Oh yes right! This is confusing

@allanrenucci allanrenucci merged commit 6153905 into scala:master Nov 23, 2018
@allanrenucci allanrenucci deleted the fix/5482 branch November 23, 2018 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IDE: Documentation on hover doesn't show correctly after /
2 participants