You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to propose a check for modifying return variables within a deferred function or statement. In the case of errors, they end up getting swallowed, so this can be quite an interesting foot-gun.
Here is a small program that should trigger this proposed lint:
package main
import"fmt"functest() int {
varresintdeferfunc() {
res+=1
}()
returnres
}
funcmain() {
fmt.Printf("%d", test())
}
This should not be triggered by setting named returns.
This should also work in the unholy cases of redeclaring the return variables in the deferred functions or with nested deferred functions.
The text was updated successfully, but these errors were encountered:
This seems like a more general case of #590 and it is non-trivial to implement correctly, especially with our current representation of closures and defer statements, which considers all variables that are closed over as escaping to the heap, which means we can't rely on SSA for tracking their def-use chains.
I'd like to propose a check for modifying return variables within a deferred function or statement. In the case of errors, they end up getting swallowed, so this can be quite an interesting foot-gun.
Here is a small program that should trigger this proposed lint:
This should not be triggered by setting named returns.
This should also work in the unholy cases of redeclaring the return variables in the deferred functions or with nested deferred functions.
The text was updated successfully, but these errors were encountered: