go/ast: unexpected associations for comments in empty function/loop bodies #39753
Comments that are placed inside empty function or loop bodies are associated with statements after the body, hence statements outside of the scope the comments are in. I would expect them to be associated with the function or loop declaration. This snipped demonstrates the issue:
And here you can find code to reproduce the issue: https://play.golang.org/p/m4j-OTbdi-L
As @griesemer mentioned in #20744, the comment association heuristic is not straight forward to implement. Thus, I am wondering whether the above shown associations are intentional or whether this is a bug. Thanks for the clarification!
$ go version go version go1.14.2 darwin/amd64
The text was updated successfully, but these errors were encountered:
In dst the algorithm to associate comments with decoration attachment points was by no means straightforward. If it finds nothing below the comment it bounces back and searches before the comment. In this example it would attach to the opening brace of the
Fixes golang#39753 Signed-off-by: Eva Charlotte Mayer <firstname.lastname@example.org>
As @dave pointed out, the question is now, with which nodes we want to associate the comments in empty bodies.
I changed the function
Please see here for the full changes that also add an additional unit test: ec-m@7b0f14c
With this fix, comments inside empty function/loop/if bodies are associated to the
Do you think this would be an acceptable way to associate the comments, @griesemer? If so, I will open a pull request with Gerrit.
Thank you for filing, and investigating this bug, @ec-m. I'd say please go for it, please mail that change; @griesemer's plate is heavily stacked, but with your CL up for review, that provides more actionable feedback and brings in more reviewers. It would be awesome to have you as a Go contributor, @ec-m! Happy holidays!
Sort the comment map entries before printing. Makes it easier to use the output for debugging. For #39753. Change-Id: Ic8e7d27dd2df59173e2c3a04a6b71ae966703885 Reviewed-on: https://go-review.googlesource.com/c/go/+/315370 Trust: Robert Griesemer <email@example.com> Reviewed-by: Robert Findley <firstname.lastname@example.org>