-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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
The scanner keeps a buffer
commentBuf
which contains the content ofthe comment being parsed. When encountering a
/
, we check whether thisis 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