Skip to content

x/tools/gopls/internal/analysis/stditerators: avoid introducing redundant variables #76241

@adonovan

Description

@adonovan

Consider this stditerators modernization observed in CL 718504, a not uncommon pattern:

			for i := 0; i < T.NumFields(); i++ {
				if prev := T.Field(i); prev.Name() == r.to {

=>

			for field0 := range T.Fields() {
				if prev := field0; prev.Name() == r.to {

(Ignore the choice of name field0, as this is the topic of #76240.)

The assignment prev := field0 is redundant. The analyzer should recognize this pattern and choose the name prev in this case, deleting the IfStmt.Init statement.

Metadata

Metadata

Assignees

Labels

FeatureRequestIssues asking for a new feature that does not need a proposal.RefactoringIssues related to refactoring toolsgoplsIssues related to the Go language server, gopls.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions