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

False positive in tracking conversion from value to pointer receiver #284

Open
sonalmahajan15 opened this issue Sep 30, 2024 · 0 comments
Open
Labels
false positive Requires more analysis and support

Comments

@sonalmahajan15
Copy link
Contributor

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
}
@sonalmahajan15 sonalmahajan15 added the false positive Requires more analysis and support label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false positive Requires more analysis and support
Projects
None yet
Development

No branches or pull requests

1 participant