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

Comments

@mvdan
Copy link
Member

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

This comment has been minimized.

Copy link
Contributor

commented Oct 20, 2017

Feel free to take a shot at it.

@alindeman

This comment has been minimized.

Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.