NilAway reports a false positive when a value (m) calls a method (m.foo()) with a pointer receiver, not being able to understand the implicit conversion that takes place: (&m).foo().
type myInt int
func (m *myInt) foo() *myInt {
if m == nil {
return nil
}
return m
}
func test(m myInt) {
v := m.foo()
_ = *v // FP here
}
However, if we convert this into a regular parameter, then NilAway can reason about the flow correctly and does not report any false positive.
type myInt int
func foo(m *myInt) *myInt {
if m == nil {
return nil
}
return m
}
func test(m myInt) {
v := foo(&m)
_ = *v // no error -- correct behavior
}
NilAway reports a false positive when a value (
m
) calls a method (m.foo()
) with a pointer receiver, not being able to understand the implicit conversion that takes place:(&m).foo()
.However, if we convert this into a regular parameter, then NilAway can reason about the flow correctly and does not report any false positive.