From ae0deb7a4c9d16406b4c2a32fd9442bc3faf079b Mon Sep 17 00:00:00 2001 From: Suzy Mueller Date: Thu, 24 Jun 2021 11:53:41 -0400 Subject: [PATCH] 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 Run-TryBot: Suzy Mueller gopls-CI: kokoro TryBot-Result: Go Bot Reviewed-by: Rebecca Stambler --- internal/lsp/code_action.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/lsp/code_action.go b/internal/lsp/code_action.go index ac22bc072d..1c5ad4d636 100644 --- a/internal/lsp/code_action.go +++ b/internal/lsp/code_action.go @@ -312,11 +312,11 @@ func extractionFixes(ctx context.Context, snapshot source.Snapshot, pkg source.P 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