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

Open
josharian opened this Issue Jul 3, 2015 · 7 comments

Comments

Projects
None yet
5 participants
@josharian
Copy link
Contributor

josharian commented Jul 3, 2015

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

gopherbot commented Dec 20, 2017

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

@robpike

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment