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

checkers: rewrite deferUnlambda checker as a StmtListVisitor #1406

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ehsundar
Copy link

@cristaloleg
Copy link
Member

There are failures in make ci-linter

@ehsundar ehsundar force-pushed the master branch 3 times, most recently from 95123ff to 1f541c7 Compare February 25, 2024 17:50
@ehsundar
Copy link
Author

Addressed the issues.
Sorry for repetitive pushes. My IDE is configured to add and end line to every file including the generated one. I would change the code gen to add an empty line at the end in future...

- fix assigned closure function false-positive issue go-critic#1401
@cristaloleg
Copy link
Member

Sorry for the delay, I will take a look tomorrow. Thanks.

Copy link
Member

@cristaloleg cristaloleg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

}()
foo = func() {
println("should print")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the implementation, I guess it wouldn't "see" the assignment anywhere except the same depth level.

// This assignment inside of the if statement will not be handled.
if cond {
	foo = func() {
		println("should print")
	}
}

The proper analysis is cumbersome at AST level. This is probably one of the cases where SSA would be beneficial.

Copy link
Author

@ehsundar ehsundar Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your advice. Since this is the first time I work with AST, I'll see if I could figure out a proper solution based on what you mentioned.

continue
}

if ident.Name == target.Name {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to check the "objects" for identity, so the shadowing doesn't break anything.
But for a single-level statement scanning name check is probably enough, depending on whether you want to make it recursive or not.

@ehsundar
Copy link
Author

ehsundar commented Mar 7, 2024

I've read a number of other checkers since last week and yet I couldn't find any similar situation to begin with. I also inspected the context using a debugger in which lays several utilities, however none of them helped me with the case. Could you possibly provide me with some reference, doc or code to help me find my way? Talking about accessing "objects" and utilizing SSA approach.

Of course there is always a way to implement something, but given that my little code is already messy and unreadable, I don't feel good about shooting in the dark.

@cristaloleg
Copy link
Member

I will make a review today, thank you for the update.

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 this pull request may close these issues.

None yet

3 participants