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: warn or fail when multiple names have the same value #23592

Closed
ecc1 opened this issue Jan 28, 2018 · 1 comment
Closed

Comments

@ecc1
Copy link

ecc1 commented Jan 28, 2018

When constant values of a type are declared in separate files, it's difficult to detect whether one has assigned the same value to more than one name. The stringer command would be an ideal place to detect this, and issue at least a warning, or even fail (since one could argue that the String method is not well-defined for that value).

@gopherbot gopherbot added this to the Unreleased milestone Jan 28, 2018
@robpike
Copy link
Contributor

robpike commented Jan 28, 2018

It's reasonable to have multiple values for a given constant, as the example in the command documentation states:

For example, given this snippet,

    package painkiller

    type Pill int

    const (
    	Placebo Pill = iota
    	Aspirin
    	Ibuprofen
    	Paracetamol
    	Acetaminophen = Paracetamol
    )

I think it would be a mistake, a category error, to have stringer become a diagnostic and analysis tool. It blurs its purpose, which is just to make it easy to print names of constants, not to check the correctness of your program.

If you want this sort of constant checking, that should be a separate tool that runs independent of stringer.

@robpike robpike closed this as completed Jan 28, 2018
@golang golang locked and limited conversation to collaborators Jan 28, 2019
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