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
The below code will print nothing since f() returns a function, you need to use defer f()() if you want it to actually run it. I think it would be useful to add a linter for this, since you practically never not want to run the returned function.
The Go compiler already refuses to compile just defer f, so perhaps it might be better to expand that check instead of adding one to staticcheck?
The compiler can't refuse to compile this code. f might do other meaningful work, and the language specification doesn't forbid defers of functions that return functions.
The below code will print nothing since f() returns a function, you need to use
defer f()()
if you want it to actually run it. I think it would be useful to add a linter for this, since you practically never not want to run the returned function.The Go compiler already refuses to compile just
defer f
, so perhaps it might be better to expand that check instead of adding one to staticcheck?The text was updated successfully, but these errors were encountered: