-
Notifications
You must be signed in to change notification settings - Fork 17.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/go/internal/generate: stop premature variable substitution in com…
…mands go:generate commands passed no arguments are currently subject to premature variable substitution due to mistakenly assuming append guarantees a copy. The change fixes this by forcing a slice copy at each invocation of a command. The previous code assumed that append would always generate a copy of its inputs. However, append wouldn't create a copy if there was no need to increase capacity and it would just return the original input slice. This resulted in premature variable substitutions in the "master word list" of generate commands, thus yielding incorrect results across multiple invocations of the same command when the body contained substitutions e.g. environment variables, moreover these can change during the lifetime of go:generate processing a file. Note that this behavior would not manifest itself if any arguments were passed to the command, because append would make a copy of the slice as it needed to increase its capacity. The "hacky" work-around was to always pass at least one argument to any command, even if the command ignores it. e.g., //go:generate MyNoArgsCmd ' ' This CL fixes that issue and removes the need for the hack mentioned above. Fixes #31608 Change-Id: I782ac2234bd7035a37f61c101ee4aee38ed8d29f GitHub-Last-Rev: 796d343 GitHub-Pull-Request: #31527 Reviewed-on: https://go-review.googlesource.com/c/go/+/172580 Run-TryBot: Jay Conrod <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
- Loading branch information
Showing
2 changed files
with
204 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters