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

Open
mvdan opened this issue Oct 20, 2017 · 2 comments
Open

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

mvdan opened this issue Oct 20, 2017 · 2 comments
Labels
help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mvdan
Copy link
Member

mvdan commented Oct 20, 2017

Working example: https://play.golang.org/p/TlsDxVbGow

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

@griesemer
Copy link
Contributor

Feel free to take a shot at it.

@alindeman
Copy link

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 help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Mar 29, 2018
@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
Labels
help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants