Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go: Fix shadowed variable in RunListWithEnv #16454

Merged
merged 2 commits into from
May 8, 2024
Merged

Conversation

mbg
Copy link
Member

@mbg mbg commented May 8, 2024

This PR does two things and there is a commit for each item:

  • Some Go toolchain related functions from util.go are moved to toolchain.go which is a better fit for them. This commit does not change any behaviour.
  • In the process of doing this, I noticed that there was a variable being shadowed in RunListWithEnv and fixed this

@mbg mbg self-assigned this May 8, 2024
@mbg mbg requested a review from a team as a code owner May 8, 2024 12:32
@github-actions github-actions bot added the Go label May 8, 2024
Copy link
Contributor

@owen-mc owen-mc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the shadowing was probably deliberate, since it's the same value but with a different type, but I have no problem with changing it.

@mbg
Copy link
Member Author

mbg commented May 8, 2024

@owen-mc to be clear, the shadowing caused an issue in the else branch that got flagged by the Go compiler because the err in scope there was the err that shadows the outer err. And that's a nil value in the else branch. By renaming the inner err, the outer err is no longer shadowed in the else branch and therefore, if we hit that branch, the error message is printed there as expected rather than a nil value.

@owen-mc
Copy link
Contributor

owen-mc commented May 8, 2024

Ah yes, that is a problem.

@mbg mbg merged commit 8cba06a into main May 8, 2024
13 checks passed
@mbg mbg deleted the mbg/go/fix/shadowed-variable branch May 8, 2024 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants