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 of return in a defer function has no effect #1029

Closed
rpstw opened this issue Aug 21, 2024 · 2 comments · Fixed by #1030
Closed

False positive of return in a defer function has no effect #1029

rpstw opened this issue Aug 21, 2024 · 2 comments · Fixed by #1030

Comments

@rpstw
Copy link

rpstw commented Aug 21, 2024

Describe the bug
Unexpected return in a defer function has no effect

To Reproduce

  1. use the 1.3.9 version
  2. use this go code
package main

func verify(a any) func() {
	return func() {
		fn := a.(func() error)
		if err := fn(); err != nil {
			panic(err)
		}
	}

}

func main() {
	defer verify(func() error {
		return nil
	})()
}
  1. use this config
    As of my understanding, it disable the call-chain defer check but enable the return defer check, which is our case.
[rule.defer]
  arguments=[["return"]]

Expected behavior
No return in a defer function has no effect

Desktop (please complete the following information):

  • OS: macOS
  • Version of Go: 1.22

Additional context
This issue is similar to #863, which is also the one first on Google, but this issue is not exactly the same.

chavacava added a commit that referenced this issue Aug 21, 2024
@chavacava chavacava mentioned this issue Aug 21, 2024
@chavacava
Copy link
Collaborator

Hi @rpstw thank you for reporting the problem.
I've created a PR #1030 with a proposal of a fix. Please let me know if the PR solves the problem (I've added your code example to the rule's test cases)

@rpstw
Copy link
Author

rpstw commented Aug 21, 2024

Fixed. 🚀

@rpstw rpstw closed this as completed Aug 21, 2024
chavacava added a commit that referenced this issue Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants