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 recognize X = T(iota) #11581

Closed
josharian opened this issue Jul 3, 2015 · 9 comments
Closed

x/tools/cmd/stringer: does not recognize X = T(iota) #11581

josharian opened this issue Jul 3, 2015 · 9 comments
Labels
FrozenDueToAge Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@josharian
Copy link
Contributor

Given

package a

type Num int

const (
    One = Num(iota)
    Two
)

stringer fails:

$ stringer -type=Num
stringer: no values defined for type Num
@josharian josharian added this to the Unreleased milestone Jul 3, 2015
@mvdan
Copy link
Member

mvdan commented Dec 20, 2017

I encountered this too. Should be easy enough to teach it to recognise type conversions; will give it a go.

@mvdan mvdan self-assigned this Dec 20, 2017
@gopherbot
Copy link

Change https://golang.org/cl/85015 mentions this issue: cmd/stringer: support X = T(iota)

@robpike
Copy link
Contributor

robpike commented Dec 20, 2017

Instead, just write

const (
   One Num = iota
   Two
)

Stringer doesn't need to support the full language.

@mvdan
Copy link
Member

mvdan commented Dec 23, 2017

I initially thought it would be better for stringer to be more lax in what it accepts, since in a user's code both X T = iota and X = T(iota) make sense. And, limiting ourselves to this case, the added code to stringer is not much.

However, I do see that this can lead to a certain slippery slope. And I struggle to think of a reason why rewriting to the simpler (AST-wise) X T = iota would ever be a problem. It could certainly confuse users such as @josharian and myself, but perhaps then we just need to clarify the docs or give a better error message.

@mvdan
Copy link
Member

mvdan commented Jan 26, 2018

I'm convinced now that we shouldn't do this. If anyone feels like there is a compelling reason to support this form, feel free to reopen this discussion at a later time.

@dsymonds
Copy link
Contributor

dsymonds commented Nov 1, 2018

I think this can be addressed for simple cases (e.g. a plain type conversion) with less code than https://golang.org/cl/85015 was proposing. I'm going to send an alternate change.

@dsymonds dsymonds reopened this Nov 1, 2018
@dsymonds
Copy link
Contributor

dsymonds commented Nov 1, 2018

Note that while X T = iota and X = T(iota) are equivalent and both easy, if you aren't using iota then it becomes a lot messier when the value you are using is a constant of a different type.

@dsymonds dsymonds self-assigned this Nov 1, 2018
@mvdan mvdan removed their assignment Nov 16, 2018
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Sep 12, 2019
@ZekeLu
Copy link
Contributor

ZekeLu commented May 11, 2022

https://go-review.googlesource.com/c/146577 has been merged and I think this issue can be closed. (the referenced issue in the Fixes line is Fixes #11581).

@mvdan
Copy link
Member

mvdan commented May 11, 2022

Good point, closing.

@mvdan mvdan closed this as completed May 11, 2022
@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

6 participants