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: tool generates unnecessary index variables #23014

Closed
henryas opened this Issue Dec 6, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@henryas
Copy link

henryas commented Dec 6, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

Go 1.9.2

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

windows 10 home, windows/amd64

What did you do?

Given the following data:

type Lifespan uint64

const (
	NonDepreciable Lifespan = 0
	MonthLifespan Lifespan = 30
	YearLifespan Lifespan = 365
)

then run stringer on it (in this case, via go generate: //go:generate stringer -type=Lifespan)

What did you expect to see?

// Code generated by "stringer -type=Lifespan"; DO NOT EDIT.

package components

import "strconv"

const (
	_Lifespan_name_0 = "NonDepreciable"
	_Lifespan_name_1 = "MonthLifespan"
	_Lifespan_name_2 = "YearLifespan"
)

func (i Lifespan) String() string {
	switch {
	case i == 0:
		return _Lifespan_name_0
	case i == 30:
		return _Lifespan_name_1
	case i == 365:
		return _Lifespan_name_2
	default:
		return "Lifespan(" + strconv.FormatInt(int64(i), 10) + ")"
	}
}

What did you see instead?

// Code generated by "stringer -type=Lifespan"; DO NOT EDIT.

package components

import "strconv"

const (
	_Lifespan_name_0 = "NonDepreciable"
	_Lifespan_name_1 = "MonthLifespan"
	_Lifespan_name_2 = "YearLifespan"
)

var (
	_Lifespan_index_0 = [...]uint8{0, 14}
	_Lifespan_index_1 = [...]uint8{0, 13}
	_Lifespan_index_2 = [...]uint8{0, 12}
)

func (i Lifespan) String() string {
	switch {
	case i == 0:
		return _Lifespan_name_0
	case i == 30:
		return _Lifespan_name_1
	case i == 365:
		return _Lifespan_name_2
	default:
		return "Lifespan(" + strconv.FormatInt(int64(i), 10) + ")"
	}
}

The Lifespan indexes are not necessary.

I have fixed the bug, but I am not sure how to submit the file for review.

Thanks.

Henry

@ALTree ALTree changed the title Stringer Minor Bug x/tools/cmd/stringer: tool generates unnecessary index variables Dec 6, 2017

@gopherbot gopherbot added this to the Unreleased milestone Dec 6, 2017

@mvdan

This comment has been minimized.

Copy link
Member

mvdan commented Dec 6, 2017

You can follow the instructions here to use Gerrit: https://golang.org/doc/contribute.html

@henryas henryas closed this Dec 6, 2017

@henryas henryas reopened this Dec 6, 2017

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Dec 6, 2017

Change https://golang.org/cl/82215 mentions this issue: stringer: fix unnecessary variables created by stringer tool.

@henryas

This comment has been minimized.

Copy link

henryas commented Dec 6, 2017

@mvdan Thanks.

SOF3 pushed a commit to SOF3/go-stringer-inverse that referenced this issue Aug 23, 2018

stringer: don't emit unnecessary variables
Fixes golang/go#23014

Change-Id: I159f83bae0ed632b0b3c00f8ab02f5701acbc4cc
Reviewed-on: https://go-review.googlesource.com/82215
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>

SOF3 pushed a commit to SOF3/go-stringer-inverse that referenced this issue Aug 23, 2018

stringer: don't emit unnecessary variables
Fixes golang/go#23014

Change-Id: I159f83bae0ed632b0b3c00f8ab02f5701acbc4cc
Reviewed-on: https://go-review.googlesource.com/82215
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>

@golang golang locked and limited conversation to collaborators Dec 7, 2018

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