Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fixed erroneous PSUseDeclaredVarsMoreThanAssignments for some globals variables#2013

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
andyleejordan merged 4 commits intoPowerShell:mainfromJohn-Leitch:master
Feb 20, 2025

Conversation

@John-Leitch
Copy link
Contributor

@John-LeitchJohn-Leitch commentedJul 11, 2024
edited
Loading

PR Summary

This PR fixes the following longstanding issue:#1300 (Global variables are erroneously reported as "never used")

The issue exists becauseHelper.IsVariableGlobalOrEnvironment uses anAst to key intoVariableAnalysisDictionary, callingVariableAnalysis.IsGlobalOrEnvironment on the value returned to determine whether or not the variable is a global. However, in some cases, the key does not exist in the dictionary, resulting in the method returningfalse. Fortunately,VariableAnalysis.IsGlobalOrEnvironment depends on no instance members, instead relying solely on the properties ofVariableExpressionAst, which is passed in. As such,VariableAnalysis.IsGlobalOrEnvironment can be madestatic with no consequence, allowingHelper.IsVariableGlobalOrEnvironment to call the method without the dictionary operations.

Also of note, the current implementation is somewhat redundant, withUseDeclaredVarsMoreThanAssignments.AnalyzeScriptBlockAst checkingVariablePath.DriveName separately, which is why the issue does not affect environment variables despiteVariableAnalysis.IsGlobalOrEnvironment erroneously returningfalse in some cases.

PR Checklist

liamjpeters reacted with hooray emoji
@liamjpeters
Copy link
Contributor

Really clear explanation, thanks for getting to the root of the issue! 🙂 LGTM!

John-Leitch reacted with thumbs up emoji

Copy link
Collaborator

@bergmeisterbergmeister left a comment
edited
Loading

Choose a reason for hiding this comment

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

Looks good. Sorry for late review. Updated branch from main since CI is now on GitHub Actions. If it passed, happy to merge if@andyleejordan is ok as well?

John-Leitch reacted with thumbs up emoji
@andyleejordanandyleejordanenabled auto-merge (squash)February 18, 2025 19:00
@andyleejordan
Copy link
Member

Nice fix!

John-Leitch reacted with thumbs up emoji

@andyleejordanandyleejordan merged commit3a91195 intoPowerShell:mainFeb 20, 2025
4 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@andyleejordanandyleejordanandyleejordan approved these changes

@bergmeisterbergmeisterbergmeister approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@John-Leitch@liamjpeters@andyleejordan@bergmeister

[8]ページ先頭

©2009-2025 Movatter.jp