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

x/tools/cmd/stringer: does not find constants across multiple groups #11582

Closed
josharian opened this issue Jul 3, 2015 · 2 comments
Closed
Milestone

Comments

@josharian
Copy link
Contributor

Given input:

package a

type Num int

// Small numbers
const (
    One Num = iota
    Two
)

// Big numbers
const (
    Fourteen Num = iota
    EleventyOne
)

stringer generates strings only for the first group:

// generated by stringer -type=Num; DO NOT EDIT

package a

import "fmt"

const _Num_name = "OneTwo"

var _Num_index = [...]uint8{0, 3, 6}

func (i Num) String() string {
    if i < 0 || i+1 >= Num(len(_Num_index)) {
        return fmt.Sprintf("Num(%d)", i)
    }
    return _Num_name[_Num_index[i]:_Num_index[i+1]]
}
@josharian josharian added this to the Unreleased milestone Jul 3, 2015
@robpike robpike self-assigned this Jul 6, 2015
@robpike robpike modified the milestones: Go1.6, Unreleased Jul 6, 2015
@robpike
Copy link
Contributor

robpike commented Jul 10, 2015

Not a bug. Also, working as intended.

Stringer turns numbers into names. In your example, One and Fourteen have the same value, Fourteen.String() == "One". There would be no way to disambiguate.

Try changing Fourteen to iota+2 and you'll see stringer is working fine.

Please reopen if I have misunderstood.

@robpike robpike closed this as completed Jul 10, 2015
@josharian
Copy link
Contributor Author

Oh right. I'd blame coffee but I don't drink any.

A warning/failure from stringer seems like it might reasonable in this case, but not urgent; leaving closed.

@golang golang locked and limited conversation to collaborators Jul 11, 2016
@rsc rsc unassigned robpike Jun 23, 2022
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

3 participants