-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Panic case #40
Comments
Not bug. Your case should be written like below to avoid the warn from wastedassign.
|
@sanposhiho it's absolutely different code :) it doesn't work properly for not panic case: package main
import "fmt"
func main() {
fmt.Println(didPanic(func() {})) // Must be false.
fmt.Println(didPanic(func() { panic("boom!") })) // Must be true.
fmt.Println(didPanic(func() { panic(nil) })) // Must be true.
}
func didPanic(fn func()) (result bool) {
defer func() {
result = true
recover()
}()
fn()
return false
}
/*
true
true
true
*/ |
@Antonboom defer func() {
if r := recover(); r != nil {
result = true
}
}() |
@nickajacks1 hi! Thank you for your attention, but your code is not valid for Go < 1.21, because I can do Anyway the question is not "how to rewrite the code", but "how to improve the linter". |
I think I understand now. If fn panics, the assignment in the original code is technically used. I'm not really familiar with Go's AST, but this sounds complex to statically determine. Some thoughts:
So I'm not really sure what the best move here is. I've noticed other times where wastedassign seems to opt for false-positives over false-negatives: // wastedassign gives a "false positive" here (or maybe it's a bug, I haven't really looked deeper)
thing := 0
switch arg {
case 1:
thing = 3
case 2:
thing = 39
default:
thing = 100
} |
Hi!
Please look at this simple example:
The text was updated successfully, but these errors were encountered: