Ignoring how defer arguments and receivers are evaluated
Mistake
defer
arguments are evaluated immediately. No matter what status is changed to
it will always be an empty string for these two defer statements. The same holds
true for function receivers.
func f() error {
var status string
defer notify(status)
defer incrementCounter(status)
// ...
}
Fix
Passing a pointer would allow mutations to the status variable to be reflected by defer. Using a pointer receiver would have the same effect.
func f() error {
var status string
defer notify(&status)
defer incrementCounter(&status)
// ...
}