Stringer: no values for constant Spade

My code:

//go:generate stringer -type=Suit

package deck

import "fmt"

// Suit represents card's category.
type Suit uint8

const (
	Spade Suit = iota
	Diamond
	Club
	Heart
	Joker
)

This, when issuing go generate, should generate some file. Instead, But I am getting this:

$ go generate
stringer: no value for constant Spade
main.go:1: running "stringer": exit status 1

Perhaps something in changed in stringer package?

/cc @joncalhoun.

I just copied your code to my clipboard and ran the following commands:

go get golang.org/x/tools/cmd/stringer
cat > ./deck.go
# middle click to paste, then Ctrl+D
go generate

And did not get that error. deck.Suit.String was generated correctly. Can you try removing your golang.org/x/tools/cmd/stringer package and re-go get it and try again?

Oh, it worked after removing and go getting again.

Not sure what made it fail before.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.