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/printer: AST rewriting and then formatting results in mangled godocs #11775

Open
mdempsky opened this Issue Jul 18, 2015 · 3 comments

Comments

Projects
None yet
4 participants
@mdempsky
Copy link
Member

mdempsky commented Jul 18, 2015

In golang.org/cl/12373, I wrote a cmd/fix rule to rewrite "types.Typ[x]" into "x.Basic()". However, the naive approach causes

package foo

func f() {
    _ = types.Typ[types.Int]
}

// dummy godoc
func g() {
}

to get formatted as

package foo

func f() {
    _ = types.Int.Basic(

    // dummy godoc
    )
}

func g() {
}

I.e., the godoc for g is moved up into the arguments section for the .Basic() invocation. See http://play.golang.org/p/dwq4E8dsMW for a working example. Edit: See http://play.golang.org/p/CP8ylmNjmQ for an updated working example using ast.CommentMap.

As a workaround, I found setting Rparen seems to prevent the issue. I wouldn't expect that to be necessary though.

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Jul 18, 2015

@griesemer

This comment has been minimized.

Copy link
Contributor

griesemer commented Jul 20, 2015

This is a well-known problem: comments are placed based on their original source code positions and thus don't "flow" with the nodes they seem to be attached to (they are not attached). You can use an ast.CommentSet to work around this issue.

Unfortunately this is "working as intended" - and also one of the major reasons why the go/ast could use a major overhaul.

Closing this.

@griesemer griesemer closed this Jul 20, 2015

@mdempsky

This comment has been minimized.

Copy link
Member Author

mdempsky commented Jul 21, 2015

@griesemer I tried following the ast.CommentMap example in the obvious way, but go/printer still mangles the godoc comment: http://play.golang.org/p/CP8ylmNjmQ

Am I misunderstanding/misapplying how to use it here?

@griesemer

This comment has been minimized.

Copy link
Contributor

griesemer commented Jul 21, 2015

@mdempsky Need to investigate.

@mdempsky mdempsky reopened this Jul 21, 2015

@rsc rsc modified the milestones: Unplanned, Go1.6 Nov 5, 2015

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