Skip to content

Commit

Permalink
internal/lsp: fix variable reuse bug in code actions
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
suzmue committed Jul 13, 2021
1 parent d36a54b commit ae0deb7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/lsp/code_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ae0deb7

Please sign in to comment.