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 when a nil slice is returned from a function #298

Open
sonalmahajan15 opened this issue Feb 4, 2025 · 0 comments
Open

False positive when a nil slice is returned from a function #298

sonalmahajan15 opened this issue Feb 4, 2025 · 0 comments
Labels
false positive Requires more analysis and support

Comments

@sonalmahajan15
Copy link
Contributor

sonalmahajan15 commented Feb 4, 2025

Fix behavior when a nil slice is returned as in the case below.

type myIntSlice []int

func (r myIntSlice) Count() int {
	count := 0
	for _, e := range r {
		count = count + e
	}
	return count
}

func foo(input myIntSlice) myIntSlice {
	var result myIntSlice
	for _, t := range input {
		result = append(result, t)
	}
	return result
}

func test() {
	_ = foo(nil).Count()
}
@sonalmahajan15 sonalmahajan15 added the false positive Requires more analysis and support label Feb 4, 2025
@sonalmahajan15 sonalmahajan15 changed the title False positive when an nil slice is returned from a function False positive when a nil slice is returned from a function Feb 4, 2025
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