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

deferUnlambda: False positive for mutated variable #1401

Open
ajscholl opened this issue Feb 5, 2024 · 2 comments
Open

deferUnlambda: False positive for mutated variable #1401

ajscholl opened this issue Feb 5, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@ajscholl
Copy link

ajscholl commented Feb 5, 2024

func example() {
	foo := func() {
		println("should never print")
	}
	defer foo()
	defer func() { // deferUnlambda: can rewrite as `defer foo()` (gocritic)
		foo()
	}()
	foo = func() {
		println("should print")
	}
}

Following the suggestion changes the behavior of the program. Instead of calling whatever foo was set to at the end of the function, we now instead call whatever foo was set to at the time of the defer call.

@cristaloleg cristaloleg added the bug Something isn't working label Feb 5, 2024
@ehsundar
Copy link

Need to convert this rule to a StmtListVisitor to mitigate this issue. Do you agree? @cristaloleg

@cristaloleg
Copy link
Member

For now sounds ok. Feel free to try.

ehsundar added a commit to ehsundar/go-critic that referenced this issue Feb 25, 2024
- fix assigned closure function false-positive issue go-critic#1401
ehsundar added a commit to ehsundar/go-critic that referenced this issue Feb 25, 2024
- fix assigned closure function false-positive issue go-critic#1401
ehsundar added a commit to ehsundar/go-critic that referenced this issue Feb 25, 2024
- fix assigned closure function false-positive issue go-critic#1401
ehsundar added a commit to ehsundar/go-critic that referenced this issue Feb 25, 2024
- fix assigned closure function false-positive issue go-critic#1401
ehsundar added a commit to ehsundar/go-critic that referenced this issue Feb 25, 2024
- fix assigned closure function false-positive issue go-critic#1401
ehsundar added a commit to ehsundar/go-critic that referenced this issue Feb 28, 2024
- fix assigned closure function false-positive issue go-critic#1401
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants