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

cmd/doc: strange formatting on inline comment in struct with unexported field #12971

Closed
dsnet opened this issue Oct 17, 2015 · 3 comments
Closed
Milestone

Comments

@dsnet
Copy link
Member

dsnet commented Oct 17, 2015

Using go1.5

Consider this Go package:

package foo

type Reader struct {
    InputOffset  int64 // Total number of bytes read from underlying io.Reader.
    OutputOffset int64 // Total number of bytes emitted from Read.
    hidden       int
}

Currently I see:

$ go doc Reader
type Reader struct {
    InputOffset  int64 // Total number of bytes read from underlying io.Reader.
    OutputOffset int64
                // Total number of bytes emitted from Read.
    // Has unexported fields.
}

I expect to see:

$ go doc Reader
type Reader struct {
    InputOffset  int64 // Total number of bytes read from underlying io.Reader.
    OutputOffset int64 // Total number of bytes emitted from Read.
    // Has unexported fields.
}

On a slightly related note, if you just comment out "hidden", but don't delete it, an extra newline is unnecessarily printed:

$ go doc Reader
type Reader struct {
    InputOffset  int64 // Total number of bytes read from underlying io.Reader.
    OutputOffset int64 // Total number of bytes emitted from Read.

}

@robpike

@rakyll rakyll added this to the Go1.6 milestone Oct 19, 2015
@robpike
Copy link
Contributor

robpike commented Oct 20, 2015

This is how the go/doc package (not cmd/doc) folds lines. The issue is triggered by Output being one byte longer than Input, reaching a threshold.

Working as intended.

@robpike robpike closed this as completed Oct 20, 2015
@dsnet
Copy link
Member Author

dsnet commented Oct 24, 2015

I don't think it has to do with Output being one byte longer. The still occurs with this trivial package:

package foo

type A struct {
    A int // A
    B int // B
    c int
}

Actually, I believe the bug is from the go/doc package. I traced the issue to the fact that the NamePos is not being set. See CL/16286.

@gopherbot
Copy link

CL https://golang.org/cl/16286 mentions this issue.

robpike pushed a commit that referenced this issue Nov 17, 2015
The NamePos value was not being set, and would default to a value
of zero. This would cause the printing logic to get confused as
to where exactly to place the "Has unexported fields" string.

A trivial package changes from

<
type A struct {
	A int // A
	B int
			// B
	// Has unexported fields.
}
>

to

<
type A struct {
	A int // A
	B int // B
	// Has unexported fields.
}
>

Fixes #12971

Change-Id: I53b7799a1f1c0ad7dcaddff83d9aaeb1d6b7823e
Reviewed-on: https://go-review.googlesource.com/16286
Run-TryBot: Joe Tsai <joetsai@digital-static.net>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
@golang golang locked and limited conversation to collaborators Oct 24, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants