You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's unclear. The NewCommentMap doc doesn't seem to apply to trailing line comments in files:
$ go doc go/ast NewCommentMap
func NewCommentMap(fset *token.FileSet, node Node, comments []*CommentGroup) CommentMap
NewCommentMap creates a new comment map by associating comment groups of the
comments list with the nodes of the AST specified by node.
A comment group g is associated with a node n if:
- g starts on the same line as n ends
- g starts on the line immediately following n, and there is
at least one empty line after g and before the next node
- g starts before n and is not associated to the node before n
via the previous rules
NewCommentMap tries to associate a comment group to the "largest" node
possible: For instance, if the comment is a line comment trailing an
assignment, the comment is associated with the entire assignment rather than
just the last operand in the assignment.
None of those rules seem to apply to the //5 comment. NewCommentMap associates //5 with the int node (see below), even though they don't seem to satisfy any of the 3 rules in the NewCommentMap doc: (1) it doesn't start on the same line as the line on which the int node ends; (2) it doesn't start on the line immediately following the line of the int node; and (3) it doesn't start before int.
Seems too similar to #21755. Closing myself. I'd at least like the existing doc to be updated to fully describe the existing behavior, but I could see an admin arguing that that other issue might already encompass that work.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Test code:
What did you expect to see?
It's unclear. The NewCommentMap doc doesn't seem to apply to trailing line comments in files:
None of those rules seem to apply to the
//5
comment. NewCommentMap associates//5
with theint
node (see below), even though they don't seem to satisfy any of the 3 rules in the NewCommentMap doc: (1) it doesn't start on the same line as the line on which theint
node ends; (2) it doesn't start on the line immediately following the line of theint
node; and (3) it doesn't start beforeint
.What did you see instead?
Test output:
//5
is associated withint
.The text was updated successfully, but these errors were encountered: