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: infers the wrong type from unexported value #22427

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

go/doc: infers the wrong type from unexported value #22427

dsnet opened this issue Oct 24, 2017 · 2 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

Related to #22426

Consider the following snippet:

const code = `package foo
const (
	_ int = iota
	X = ""
)`

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 (
	X int = ""
)

I expect this to print:

const (
	X = ""
)

Package foo contains 2 constants, where the second constant is of type string, but doc incorrectly infers that it is an int, by hoisting the type from the previous value spec.

\cc @griesemer

@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
@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
@dsnet
Copy link
Member Author

dsnet commented Feb 17, 2018

Fixed on Go1.10 by https://golang.org/cl/68730

@dsnet dsnet closed this as completed Feb 17, 2018
@golang golang locked and limited conversation to collaborators Feb 17, 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

2 participants