Immediate Argument Evaluation in defer in Golang #6269
Unanswered
novahe
asked this question in
Linter Ideas
Replies: 1 comment
-
|
The $ golangci-lint run --enable-only govet
issue6268/main.go:16:67: defers: call to time.Since is not deferred (govet)
defer fmt.Println("❌ Incorrect Value (Immediate Evaluation):", time.Since(start))
^
1 issues:
* govet: 1 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Welcome
How did you install golangci-lint?
N/A
Your feature request related to a problem? Please describe
I'm not sure if golangci-lint can catch this, thanks in advance.
in Go, arguments to deferred function calls are evaluated immediately
when the defer statement is executed, not when the deferred function
runs. This caused SinceInSeconds(startTime) to be computed at the
start of request handling instead of at the end.
Describe the solution you'd like
N/A
Describe alternatives you've considered
N/A
Additional context
No response
Supporter
Beta Was this translation helpful? Give feedback.
All reactions