Skip to content

Commit e548c70

Browse files
adonovangopherbot
authored andcommitted
gopls/internal/analysis/modernize: fix bad edit in var ( ... ) decl
The TextEdit.End offset was wrong in the case where the var decl has an explicit close paren. + test Fixes golang/go#75318 Change-Id: I5caa20dbc81a0a239bcdab354949e184135b11ad Reviewed-on: https://go-review.googlesource.com/c/tools/+/701780 Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 08a6323 commit e548c70

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

gopls/internal/analysis/modernize/stringsbuilder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ nextcand:
179179
// delete "= expr"
180180
edits = append(edits, analysis.TextEdit{
181181
Pos: init,
182-
End: decl.End(),
182+
End: spec.End(),
183183
})
184184
}
185185

gopls/internal/analysis/modernize/testdata/src/stringsbuilder/stringsbuilder.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,14 @@ func _(x string) string {
8888
}
8989
return s
9090
}
91+
92+
// Regression test for bug in a GenDecl with parens.
93+
func issue75318(slice []string) string {
94+
var (
95+
msg string
96+
)
97+
for _, s := range slice {
98+
msg += s // want "using string \\+= string in a loop is inefficient"
99+
}
100+
return msg
101+
}

gopls/internal/analysis/modernize/testdata/src/stringsbuilder/stringsbuilder.go.golden

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,14 @@ func _(x string) string {
9393
}
9494
return s
9595
}
96+
97+
// Regression test for bug in a GenDecl with parens.
98+
func issue75318(slice []string) string {
99+
var (
100+
msg strings.Builder
101+
)
102+
for _, s := range slice {
103+
msg.WriteString(s) // want "using string \\+= string in a loop is inefficient"
104+
}
105+
return msg.String()
106+
}

0 commit comments

Comments
 (0)