Skip to content

Handle assignments to global variables from the init function#4

Open
lizard-boy wants to merge 5 commits intomainfrom
pr-253
Open

Handle assignments to global variables from the init function#4
lizard-boy wants to merge 5 commits intomainfrom
pr-253

Conversation

@lizard-boy
Copy link
Collaborator

Original PR: uber-go/nilaway#253

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR adds new detection logic for assignments to global variables from init functions, enhancing how NilAway initializes and processes global variables.

  • In /assertion/global/analyzer.go, getInitFuncDecls now collects init functions with a visited set to avoid infinite recursion; duplicate entries may occur across init functions.
  • In /assertion/global/globalvarinit.go, analyzeValueSpec and getGlobalConsumers now accept init declarations, and hasGlobalVarAssignInInitFunc is added to detect global assignments.
  • Consider caching repeated calls to hasGlobalVarAssignInInitFunc to improve efficiency and ensure proper logging using logger.error for failures.

💡 (2/5) Greptile learns from your feedback when you react with 👍/👎!

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

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.

3 participants