Skip to content
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

go/ast: trailing func comments mishandled in CommentMap #22371

mvdan opened this issue Oct 20, 2017 · 2 comments

go/ast: trailing func comments mishandled in CommentMap #22371

mvdan opened this issue Oct 20, 2017 · 2 comments


Copy link

@mvdan mvdan commented Oct 20, 2017

Working example:

Prints: g: "trailing comment in f\n"

Seems like the correct output should either be nothing (if it is associated with _ = x), or f: "trailing comment in f\n".

What's currently happening is that the "_ = x" in func f is the most recent "important" node when we encounter the comment. Since the comment isn't on the line immediately following "_ = x", it doesn't
get associated with it. We don't look further up the "important nodes" stack to notice that it's within the bounds of f. Instead, we just give up and associate it with g.

/cc @griesemer

Copy link

@griesemer griesemer commented Oct 20, 2017

Feel free to take a shot at it.

Copy link

@alindeman alindeman commented Oct 23, 2017

Is there a way to have it associated with _ = x or f while still following the three current rules? Or would a new rule need to be added?

- g starts on the same line as n ends

Not applicable in this circumstance. This is the foo := bar // baz case, as I understand it.

- g starts on the line immediately following n, and there is
  at least one empty line after g and before the next node

The line break between _ = x and the comment prevents this one from applying.

- g starts before n and is not associated to the node before n
  via the previous rules

At this point, g can only be attached to a node after its appearance.

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Mar 29, 2018
sauterp added a commit to sauterp/go that referenced this issue May 9, 2021
Change-Id: Ic250826fa2effa7920825271195e6d55b481a999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants