-
Notifications
You must be signed in to change notification settings - Fork 570
build: Fix shadowing bug in staleness calculation. #635
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find!!!
That is a really obscure bug and really shows how nasty go variable shadowing can be - I thought |
Sadly not by default: https://golang.org/cmd/vet/#hdr-Shadowed_variables $ go vet -help
usage: vet [-n] [-x] [build flags] [packages]
Vet runs the Go vet command on the packages named by the import paths.
For more about vet, see 'go doc cmd/vet'.
For more about specifying packages, see 'go help packages'.
To run the vet tool with specific options, run 'go tool vet'.
The -n flag prints commands that would be executed.
The -x flag prints commands as they are executed.
For more about build flags, see 'go help build'.
See also: go fmt, go fix. You need to do something like: go list -f '{{.Dir}}' ./... | xargs go tool vet -shadow |
It might be worth running this in our CI script, along with the |
@shurcooL great find! I've just tried this out. For a particular staleness/caching problem I'm seeing this fix unfortunately doesn't help... will continue to investigate. |
@flimzy We already run
It did also spot the
@myitcv If you can make a minimal reproduce sample and report that, I'd be happy to investigate. I didn't expect this fix to necessarily resolve all problems, this was just the first step before others. |
@shurcooL Are those really false positives? I know I've seen bugs (in code @ work) where |
I've never made it a goal for myself to not shadow If I need to use a value of So, I don't know whether they're false positives or not in this codebase, but I expect them to be if other people follow similar practice (and as far as I know, most people do). |
I agree with this, and follow the same rule. But of course the compiler doesn't know or enforce this rule. And I've seen it violated (almost certainly by accident, due to copy-paste errors, or similar, leaving both unchecked, or double-checked |
Ha, there wasn't much peer review on most of the code. Honestly I did not
follow the rule that Dmitri suggested, but I like it now that I hear it.
I'll keep it in mind for the future.
Jonathan Hall <notifications@github.com> schrieb am Fr., 28. Apr. 2017 um
17:35 Uhr:
… For me, if a variable is named err, its value must be consumed on next
immediate line
I agree with this, and follow the same rule. But of course the compiler
doesn't know or enforce this rule. And I've seen it violated (almost
certainly by accident, due to copy-paste errors, or similar, leaving both
unchecked, or double-checked err values). I don't really expect this sort
of problem in a codebase like this one, though, where good coding
practices, including peer review, are routine.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#635 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAA_OMK0X9X5-TtLGW4Hw6ubFSvdtuUuks5r0gdMgaJpZM4NKxD->
.
|
In fact, GopherJS was my first big open source Go project. The first commit
is from 2013. I've learned a lot since then.
Richard Musiol <mail@richard-musiol.de> schrieb am Fr., 28. Apr. 2017 um
17:37 Uhr:
… Ha, there wasn't much peer review on most of the code. Honestly I did not
follow the rule that Dmitri suggested, but I like it now that I hear it.
I'll keep it in mind for the future.
Jonathan Hall ***@***.***> schrieb am Fr., 28. Apr. 2017 um
17:35 Uhr:
> For me, if a variable is named err, its value must be consumed on next
> immediate line
>
> I agree with this, and follow the same rule. But of course the compiler
> doesn't know or enforce this rule. And I've seen it violated (almost
> certainly by accident, due to copy-paste errors, or similar, leaving both
> unchecked, or double-checked err values). I don't really expect this
> sort of problem in a codebase like this one, though, where good coding
> practices, including peer review, are routine.
>
> —
> You are receiving this because you commented.
>
>
> Reply to this email directly, view it on GitHub
> <#635 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAA_OMK0X9X5-TtLGW4Hw6ubFSvdtuUuks5r0gdMgaJpZM4NKxD->
> .
>
|
The parent scope
pkg
variable was inadvertently shadowed in #411. As a result, the value ofimpModeTime
was wrong, and the if statement could never be true, andpkg.SrcModTime
was never updated to a later time.The shadow happened at e3a9838#commitcomment-21940173.
Fixes #559 (possibly other similar issues, but they'll need to be verified).