-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
durationcheck: False positive when multiplying with int type struct field #1744
Conversation
8d32966
to
5645d4c
Compare
5645d4c
to
d2157b8
Compare
d2157b8
to
0547fae
Compare
@bombsimon could you take a look at this PR like that I will be able to create a bug fix version (v1.37.1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Added a question but since it's related to upstream I'll just approve anyway.
|
||
func durationcheckCase03() { | ||
seconds := 10 | ||
fmt.Print(time.Duration(seconds) * time.Second) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't this yield an error? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because time.Duration
is a int64
(type Duration int64
) so in this case: seconds
(int
) is just converted to int64
(Duration
).
time.Duration(10)
means 10 nanoseconds.
time.Duration(seconds) * time.Second
=> int64(seconds) * time.Second
=> 10 * time.Second
Related to charithe/durationcheck#7