Reputation: 11
Go allows people to do assignment on bound variable in function closures (example: A Tour of Go).
func adder() func(int) int {
sum := 0
return func(x int) int {
sum += x
return sum
}
}
This has led to a few race condition bugs in our codebase. I wonder if there's a way to set up the linter to disallow this assignment operation in function closures (the =
in sum += x
). (E.g. in python you need the nonlocal keyword to do the same thing)
I have searched the internet but couldn't find people with the same problem. Not sure if this problem is unique to our codebase and company.
Upvotes: 0
Views: 26