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/godoc: some _ should be shown #7815

Closed
rsc opened this issue Apr 18, 2014 · 2 comments

Comments

@rsc
Copy link
Contributor

commented Apr 18, 2014

Here is a nice trick to write an enum-like type's constant values:

g% cat x.go
package p

type T int

const (
    _ T = iota
    T1
    T2
    T3
    T4
)
g% 

This has two properties I wanted: (1) the values start at 1, so the zero value is not a
defined value, and (2) all the defined values have the same form on the line, so that I
can pipe them through 'sort' without breaking anything. Compare to

const (
    X T = 1 + iota
    Y
    Z
)

Anyway, this _ trick works well for me.

It works less well for godoc:

g% godoc .
PACKAGE DOCUMENTATION

package p
    import "."


CONSTANTS

const (
    T1
    T2
    T3
    T4
)

TYPES

type T int


g% 

It's a bit confusing that you can't see the _ in the godoc output, since the _ is what
defines the type and value of the constants.

Worse, the constants are not attached to the type T like they normally would be:

g% godoc . T
type T int


g% 

If I rename the _ to Dummy, then it works:

g% godoc . T
type T int

const (
    Dummy T = iota
    T1
    T2
    T3
    T4
)


g% 

What's happening here is that _ is treated as unexported and so it filters away.
(Renaming to dummy shows the same behavior as _.)

Perhaps the best fix would be to treat _ as exported for the purposes of godoc filtering
in const lists and possibly also struct fields (where _ is often padding).

I thought about saying that _ should be treated as exported for all filtering, but you
probably don't want to show things like

func _() { ... }
var _ Interface = (*Type)(nil)
@jimmyfrasche

This comment has been minimized.

Copy link
Member

commented Apr 19, 2014

Comment 1:

This appears to be a duplicate of issue #5397
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Apr 20, 2014

Comment 2:

Status changed to Duplicate.

Merged into issue #5397.

@rsc rsc added duplicate labels Apr 20, 2014

@rsc rsc added this to the Go1.4 milestone Apr 14, 2015

@rsc rsc removed the release-go1.4 label Apr 14, 2015

@golang golang locked and limited conversation to collaborators Jun 25, 2016

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants
You can’t perform that action at this time.