Skip to content

Commit ae0deb7

Browse files
committed
internal/lsp: fix variable reuse bug in code actions
Taking the address of the variables defined by range in a for loop is not safe since they are reused. Get the address from the original slice. Change-Id: If7fbf3fdbfeeaf329f36e416642582002895bbce Reviewed-on: https://go-review.googlesource.com/c/tools/+/330649 Trust: Suzy Mueller <[email protected]> Run-TryBot: Suzy Mueller <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent d36a54b commit ae0deb7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

internal/lsp/code_action.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,11 @@ func extractionFixes(ctx context.Context, snapshot source.Snapshot, pkg source.P
312312
commands = append(commands, cmd)
313313
}
314314
var actions []protocol.CodeAction
315-
for _, cmd := range commands {
315+
for i := range commands {
316316
actions = append(actions, protocol.CodeAction{
317-
Title: cmd.Title,
317+
Title: commands[i].Title,
318318
Kind: protocol.RefactorExtract,
319-
Command: &cmd,
319+
Command: &commands[i],
320320
})
321321
}
322322
return actions, nil

0 commit comments

Comments
 (0)