-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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
proposal: cmd/vet: reject unary min and max calls #66179
Comments
CC @golang/tools-team |
Maybe I don't have relevant contextual information, why is the max function allowed to accept a parameter, and what is its actual meaning? Is there any real scenario where only one parameter needs to be passed? |
the function signature is |
At least, package main
func foo(k int) int {
f := func() int {
k++
return k
}
return k + f()
}
func bar(k int) int {
f := func() int {
k++
return k
}
return min(k) + f()
}
func main() {
println(foo(1), bar(1))
} :D Similarly, |
This seems closely analogous to #60448, which added a similar vet check for append. (Too bad we called it |
This was raised during discussion #59488 (comment) and there was no obvious reason to prohibit it #59488 (comment) |
Proposal Details
A unary
min
andmax
call is an identity function and its presence suggests a bug.I had code that was doing the following:
where the intent is to clamp
blockSize
within a certain range.However, due to a single misplaced
)
, this does not work.It should have been:
I propose that
go vet
flag any unary calls tomin
ormax
, which would have caught my bug where I had 3 arguments passed tomax
, but only 1 argument passed tomin
.The text was updated successfully, but these errors were encountered: