Skip to content
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

Merged
merged 1 commit into from
Feb 20, 2021

Conversation

ldez
Copy link
Member

@ldez ldez commented Feb 17, 2021

@ldez ldez added bug Something isn't working linter: update version Update version of linter labels Feb 17, 2021
@ldez ldez force-pushed the fix/durationcheck branch 3 times, most recently from 8d32966 to 5645d4c Compare February 17, 2021 23:10
@ldez ldez changed the title fix: False positive when multiplying with int type struct field durationcheck: False positive when multiplying with int type struct field Feb 17, 2021
@ldez
Copy link
Member Author

ldez commented Feb 20, 2021

@bombsimon could you take a look at this PR like that I will be able to create a bug fix version (v1.37.1)

Copy link
Member

@bombsimon bombsimon left a 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)
Copy link
Member

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? 🤔

Copy link
Member Author

@ldez ldez Feb 20, 2021

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

@ldez ldez merged commit b39dbcd into golangci:master Feb 20, 2021
@ldez ldez deleted the fix/durationcheck branch February 20, 2021 11:43
ashanbrown pushed a commit to ashanbrown/golangci-lint that referenced this pull request Feb 20, 2021
@ldez ldez added this to the v1.37 milestone Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working linter: update version Update version of linter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants