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/doc: fails to strip RHS values from associated unexported identifier #22426

Closed
dsnet opened this issue Oct 24, 2017 · 4 comments
Closed

go/doc: fails to strip RHS values from associated unexported identifier #22426

dsnet opened this issue Oct 24, 2017 · 4 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dsnet
Copy link
Member

dsnet commented Oct 24, 2017

Consider the following snippet:

const code = `package foo
const (
	c1, C2, c3 = 1, 2, 3
	C4, c5, C6 = 4, 5, 6
	c7, C8, c9 = 7, 8, 9
)`

fset := token.NewFileSet()
pkgFiles := make(map[string]*ast.File)
astFile, _ := parser.ParseFile(fset, "", code, parser.ParseComments)
pkgFiles[""] = astFile
astPkg, _ := ast.NewPackage(fset, pkgFiles, nil, nil)
docPkg := doc.New(astPkg, "foo", 0)
format.Node(os.Stdout, fset, docPkg.Consts[0].Decl)

This currently prints:

const (
	C2     = 1, 2, 3
	C4, C6 = 4, 5, 6
	C8     = 7, 8, 9
)

I expect this to print:

const (
	C2     = 2
	C4, C6 = 4, 6
	C8     = 8
)

Package foo contains 3 constants, only 1 of which is exported. When creating a doc.Package, the doc package fails to strip the values from the right hand side of the value, leading to a strange declaration.

\cc @griesemer

@dsnet dsnet changed the title go/doc: go/doc: fails to strip RHS values from associated unexported identifier Oct 24, 2017
@dsnet dsnet self-assigned this Oct 24, 2017
@dsnet dsnet added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 24, 2017
@dsnet dsnet added this to the Go1.10 milestone Oct 24, 2017
@griesemer
Copy link
Contributor

Nice. An extra thing to consider when fixing this is the situation

var a, B, c = F()

where F returns three values (https://play.golang.org/p/qKhvm3E9rp). How do you want to handle that case? Maybe

var _, B, _ = F()

?

@dsnet
Copy link
Member Author

dsnet commented Oct 24, 2017

How do you want to handle that case? Maybe var _, B, _ = F()

That looks entirely reasonable.

@dsnet
Copy link
Member Author

dsnet commented Nov 13, 2017

Pushing to Go1.11 since this bug has been present for a while.

@dsnet dsnet modified the milestones: Go1.10, Go1.11 Nov 13, 2017
@gopherbot
Copy link

Change https://golang.org/cl/94877 mentions this issue: go/doc: replace unexported values with underscore if necessary

@golang golang locked and limited conversation to collaborators Feb 27, 2019
@rsc rsc unassigned dsnet Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants