-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
durationcheck: False positive when multiplying with int type struct f…
…ield (#1744)
- Loading branch information
Showing
3 changed files
with
35 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,38 @@ | ||
//args: -Edurationcheck | ||
package testdata | ||
|
||
import "time" | ||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
func waitFor(someDuration time.Duration) { | ||
timeToWait := someDuration * time.Second // ERROR "Multiplication of durations: `someDuration \\* time.Second` " | ||
type durationCheckData struct { | ||
i int | ||
d time.Duration | ||
} | ||
|
||
func durationcheckCase01() { | ||
dcd := durationCheckData{i: 10} | ||
_ = time.Duration(dcd.i) * time.Second | ||
} | ||
|
||
func durationcheckCase02() { | ||
dcd := durationCheckData{d: 10 * time.Second} | ||
_ = dcd.d * time.Second // ERROR "Multiplication of durations: `dcd.d \\* time.Second`" | ||
} | ||
|
||
func durationcheckCase03() { | ||
seconds := 10 | ||
fmt.Print(time.Duration(seconds) * time.Second) | ||
} | ||
|
||
func durationcheckCase04(someDuration time.Duration) { | ||
timeToWait := someDuration * time.Second // ERROR "Multiplication of durations: `someDuration \\* time.Second`" | ||
time.Sleep(timeToWait) | ||
} | ||
|
||
func durationcheckCase05() { | ||
someDuration := 2 * time.Second | ||
timeToWait := someDuration * time.Second // ERROR "Multiplication of durations: `someDuration \\* time.Second`" | ||
time.Sleep(timeToWait) | ||
} |