-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
False positive about result err is always nil #40
Comments
I'm getting something similar for a spy double that I'm using in a test: var ackFuncCalled bool
spyAckFunc := func(bool) error {
ackFuncCalled = true
return nil
}
|
@gonzaloserrano how are you using Thanks for the report @lsytj0413 by the way. I'll take a look when I find time. |
There are some structs collaborating the the ackFunc is passed around but in the end is called like |
In my case it appears that Examples: func blah() {
_ = map[int]func() ([]byte, error){
0: func() ([]byte, error) {
return []byte("0"), nil
},
1: func() ([]byte, error) {
return []byte{}, nil
},
}
} errs with:
But.... func blah() {
_ = []func() ([]byte, error){
func() ([]byte, error) {
return []byte("0"), nil
},
func() ([]byte, error) {
return []byte{}, nil
},
}
} And: func blah() {
_ = map[int]func() ([]byte, error){
0: func() ([]byte, error) {
return []byte{30}, nil
},
1: func() ([]byte, error) {
return []byte{}, nil
},
}
} Both work fine. Hope these examples help determining/fixing the issue. LMK if you need more info. |
False positive on a non-nullable return type when there is some other nullable type in the return tuple that is constructed via function that returns pointer but is never nil: func never_nil() *int {
a := 1
return &a
}
// Only fails if the type is a struct
type B struct{}
// False positive
func f() (*int, B) {
a := never_nil()
b := B{}
return a, b
}
// False positive
func f_reordered() (B, *int) {
a := never_nil()
b := B{}
return b, a
}
// False negative
func f_false_negative() (B, *int) {
b := B{}
return b, nil
}
// False negative
func f_false_negative_simplest() *int {
return nil
}
// Correct
func f_inlined() (B, *int) {
a := 1
p := &a
b := B{}
return b, p
}
// Correct
func f_no_a() B {
b := B{}
return b
}
// Correct
func f_no_b() *int {
a := never_nil()
return a
} The error only occurs on
If the type is a primitive or an interface the bug does not occur. |
Is there an elegant way to deal with this? |
mvdan/unparam#40 Signed-off-by: Lucas Fernando Cardoso Nunes <[email protected]>
mvdan/unparam#40 Signed-off-by: Lucas Fernando Cardoso Nunes <[email protected]>
* fix(providers): k8s, log message getting into stdout Signed-off-by: Lucas Fernando Cardoso Nunes <[email protected]> * fix: unparam always nil mvdan/unparam#40 Signed-off-by: Lucas Fernando Cardoso Nunes <[email protected]> * fix: linter 'File is not `gci`-ed with ...' Signed-off-by: Lucas Fernando Cardoso Nunes <[email protected]> * feat: add make lint command Signed-off-by: Lucas Fernando Cardoso Nunes <[email protected]> --------- Signed-off-by: Lucas Fernando Cardoso Nunes <[email protected]>
The following code:
returns the following unparam issue:
I have update unparam use:
The text was updated successfully, but these errors were encountered: