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 <suzmue@golang.org> Run-TryBot: Suzy Mueller <suzmue@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/internal/lsp/code_action.go b/internal/lsp/code_action.go index ac22bc0..1c5ad4d 100644 --- a/internal/lsp/code_action.go +++ b/internal/lsp/code_action.go
@@ -312,11 +312,11 @@ commands = append(commands, cmd) } var actions []protocol.CodeAction - for _, cmd := range commands { + for i := range commands { actions = append(actions, protocol.CodeAction{ - Title: cmd.Title, + Title: commands[i].Title, Kind: protocol.RefactorExtract, - Command: &cmd, + Command: &commands[i], }) } return actions, nil